-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting analyzer that checks existence/format of a file/license header #1516
Comments
Hi @siegfriedpammer, I think this would be very useful analyzer. Thank you for the initiative. Regarding the idea of regex, Do we really need it when defining a file header? If you have multiple headers in your solution you can configure it with multiple editorconfig files. What would be really useful in my opinion would be to provide functionality to replace old header with a new one. That would require to define option with "old" file header. I see that you provided a list of options which is great. Could you provide a list of real editorconfig options with keys and values. It would be better to agree on the options before the implementation starts. Thanks. References:
|
Thank you for the quick response!
For me the primary use case for a regex is not defining multiple file headers, but rather to allow file headers to have some dynamic elements such as copyright year or different author names for example (taken from the ILSpy project):
which would be generalized as:
This is the flexibility that is missing from https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0073 and the reason for this proposal.
I agree...
Will do so, but it might take some time since I am not very familiar with the editorconfig conventions yet. Thank you very much for providing some references! |
Finally, I managed to find the time to dive into the Roslynator "infrastructure" to understand how the CodeGenerator works and which XML files I need to edit to get the scaffolding for a new Analyzer/CodeFix and tests. So here is my first attempt at putting together a list of options in .editorconfig style (omitting the
I have omitted the detailed descriptoinfile_header_patternThis option features four modes:
file_header_comment_styleI think the options are mostly self-explanatory. The
vs.
file_header_allowed_triviaIdeally, this should be a flags enum option, but I don't know if that's supported by editorconfig. I have come up with the following combinations, not sure, if there are other useful ones:
One edge case I found: it's impossible to disable the analyzer via Looking forward to your feedback and comments! |
I could implement this in my own package, but it might be useful for other people, so I am creating an issue here.
While dotnet format has a rule for file headers, it is not really configurable, it only can check for static text. Things like copyright year numbers or different author names, which could easily be covered by a simple regex, cannot be configured.
Options:
I would be willing to implement this.
The text was updated successfully, but these errors were encountered: