Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.5k stars 61 forks source link

Validate attributes with analyzers #5

Closed Tyrrrz closed 4 years ago

Tyrrrz commented 5 years ago

Add analyzers as part of a nuget package to validate attribute usage at the time the code is written.

thorhj commented 5 years ago

@Tyrrrz what kinds of validation do you have in mind exactly? It might be sufficient to include a .targets file to perform the validation at build time instead?

Tyrrrz commented 5 years ago

Hi @thorhj The validations that I think will be useful are:

These are just off top of my head

thorhj commented 5 years ago

Is it possible/sensible to add an analyzer to the consumer project when adding this NuGet package? I am not experienced with analyzers, but the above validations could easily be checked by a .targets files, albeit at build time.

Tyrrrz commented 5 years ago

I haven't made an analyzer myself yet :) From my experience using open API analyzers for ASP.NET Core, it's just a NuGet package you add to the consumer project. Analyzers can both point out issues as well as quick fixes.

I'm not sure how to make validations like that with .targets files, do you have an example?

thorhj commented 5 years ago

I must have misremembered, it does not seem to be easily doable as an MSBuild task. Microsoft.NET.Sdk.Functions has a task that (among other things) check validate uniqueness of Function names, but that is done by a separate console application.

Tyrrrz commented 5 years ago

Yeah, so it seems it has to be done through the analyzer API.

Generally, I would like all validation that happens in CommandSchemaResolver to happen at build time. That would make the feedback loop shorter and improve user experience.

https://github.com/Tyrrrz/CliFx/blob/25cbfdb4b85a6cf5b79926a20e4523de73daf825/CliFx/Services/CommandSchemaResolver.cs#L15-L122

Tyrrrz commented 4 years ago

It's happening:

https://twitter.com/Tyrrrz/status/1254035827337953280