-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Allow disabling analyzers for line/file/etc. #47
Comments
I'm willing to help implement this in FSharp.Analyzers.SDK. Here are some design notes. Let me know what you think. MechanismI suggest comments. Roslyn uses I have also seen attributes being used for this, but those are only valid on select syntax elements and are therefore too limited. KeywordThe comments should be prefixed with a keyword. We could use Disabling rules using analyzer namesUsers should be able to disable rules using the analyzer name (or the message Type, whatever that's used for) or similar: // az disable Flinter:FunctionParameterNaming (The examples in this comment follows the analyzer name namespacing mentioned in #8 (comment)). Disabling rules using codes?I'm not sure whether users should be able to disable rules using its Scopes/featuresDisabling and enabling rules for the rest of the file// az disable Flinter:FunctionParameterNaming
// az enable Flinter:FunctionParameterNaming Disabling the next occurrence of a rule in a file// az disable once Flinter:FunctionParameterNaming Disabling a rule for the scope that starts on the next lineA scope is either a module, function, class, or method, depending on what comes after it. (A scope could also be a namespace, but I have never seen multiple namespaces in an F# source file, so disabling for the entire file has the same effect. Also, disabling and then enabling is a very simple workaround.) // az disable scope Flinter:FunctionParameterNaming Ignore everything after the analyzer nameThis enables users to give reasons: // az disable scope Flinter:CyclomaticComplexity because the many top-level match cases don't add actual complexity Note that this prevents disabling multiple rules in a single comment. I think that is a good trade-off. (We could alternatively support it by separating rules with commas and no spaces.) It also requires analyzer names to not contain spaces (or whatever we choose to split on, e.g., any word break Setting config valuesThis is a separate feature, but I wanted to mention it since the syntax can be similar: // az set scope Flinter:FunctionParameterNaming.style "PascalCase" because our boss said so
// az set Flinter:CyclomaticComplexity.limit 20 because the many top-level match cases don't add actual complexity
// az restore Flinter:CyclomaticComplexity.limit The first line sets for the following scope. The second line sets for the rest of the file. The third line restores the default (configured) value. This would interpret the value as a JSON token and merge it into the config that the analyzer gets for the relevant range. This of course requires analyzers to provide a (Strictly speaking it requires Note that this would not work with ImplementationThe SDK can scan each file for relevant comments and keep a list of where rules are enabled/disabled. The analyzers can be none the wiser and do their work. When the SDK gets the messages from the analyzers, it just filters them according to the In the future, we can consider giving analyzers access to disabled ranges, so that they can disable expensive analysis if a rule is disabled for a certain range. But I don't think that is likely to ever become a problem, so we shouldn't add it from the start. |
Yeah this is definitely a missing feature. Just off the top of my head, if we wanted to use comments to disable sections easily, we may have to use Fantomas’s parser as it’s handling of trivia has become quite. Ice. |
Isn't it simpler to just |
Comment handling via the AST would be hard, because AST nodes are individually responsible for grabbing comments of all kinds. File.ReadAllLines would be a lot of bookkeeping, but might be the only way forward for the interim. |
I agree about it being the way forward. I don't think it'll be too bad in terms of bookeeping. |
In any case, do you agree with my design? Are you open for a PR with those features? Note that since it depends on analyzer names, I think it would make sense if we require analyzer names (and remove |
Sorry if I'm missing something obvious, but I can't find a way to disable an analyzer using e.g. a code comment.
I'm after something like what FSharpLint allows, like:
// fsharplint:disable TypePrefixing Hints
// fsharplint:disable-next-line TypePrefixing
Again, I'm coming at this from a linter perspective. This seems to me to be a crucial feature.
The text was updated successfully, but these errors were encountered: