-
Notifications
You must be signed in to change notification settings - Fork 80
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 skipping checks with @("nolint(...)") and @nolint("...") #936
Allow skipping checks with @("nolint(...)") and @nolint("...") #936
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add a check to the ModuleDeclaration
that checks for the UDAs and then just returns or continues with recursion? Also people might use whitespace within NOLINT()
and maybe we just want to lowercase it instead of uppercasing, since non-string UDA equivalents would be all lower-case or camel-case
src/dscanner/analysis/base.d
Outdated
_messages.insert(Message(diagnostic, supplemental, key, getName(), autofixes)); | ||
} | ||
|
||
void reenableErrorMessage() | ||
in(this.errorMsgDisabled > 0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have mixed spaces and tabs everywhere in this file, try to stay consistent with the existing style (only tabs in this case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you use any formatter ? I can't find any config, this would be easier to maintain style conventions.
de01cf9
to
31b0c4a
Compare
No problem, I'll draft a second version with regex (case insensitive and ignoring spaces) EDIT: Done Here --> 39757e1 and 06b5ff5 I was thinking about some forms that could be accepted :
|
Not sure to understand well. Do you mean something like that ?
|
31b0c4a
to
2478479
Compare
re module declaration: yes like that also I think all your suggestions for UDA match format are nice and would be useful |
e294481
to
f2497f1
Compare
Soo I think this is a first mergeable version. I think I'll keep other improvements for futures PRs, especially :
Just a question : what do you expect when a malformed UDA is given ? For example |
we could probably add a dscanner checker to check for misconfigured dscanner UDAs later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to make the nolint check check for error message IDs (in most linters this is the enum KEY
member)
If you want to keep the optimization that it doesn't traverse into code, in the base analyzer class you probably want to add a abstract string[] getAvailableErrorKeys();
to be able to check all of them where you currently only check for the check name, however there would need to be another check in the actual addErrorMessage
code that will check before emitting the warning for real.
2cfc347
to
7456fa0
Compare
now accepts spaces et non-uppercase versions of NOLINT (NoLint, nolint, ..)
create dedicated struct to handle @NOLINT UDAs
7456fa0
to
f756a84
Compare
I totally missed that one analyzer could handle multiple checks. I made some refacto to handle this.
I also completely misunderstood that, this is fixed :) Hope I didn't miss anything else |
57b0119
to
0a50cae
Compare
a830b3f
to
959e469
Compare
make new code `@safe` to avoid accidental mistakes
among groups like dscanner.abc would disable all of dscanner.abc.*
Great to see this feature in and thanks so much for working on this! But I can't seem to silence this error for example: // test.d
@("nolint(dscanner.exception_check)")
void main() {
try {
} catch (Error) {
}
}
Using Also it would be nice to have this feature documented in And does #935 need closing? |
To silence an error, one has to use its ID (and not its name !), which is in this case
The 'nolint' feature is pretty experimental, it has not been widely tested and would require some more polish (see previous messages of this PR + PR #941. I personally think that one should also work on adding coherence between names and IDs. So there is still some work to do). I think this is the reason for the lack of documentation. |
Related #935
Here is the basic idea I had in mind to locally disable checks : one can attach a user defined attribute to any declaration (function declaration, variable declaration, ..). If this happens, the given check is disabled for the given declaration.
Example :
One could have done that with comment (like clang-tidy does) but I think UDAs are great since they are directly included in AST. They have a limitation though : according to libdparse D grammar, attributes can only be paired with 'declaration2'. So this would be a little hard to disable checks at other levels than declaration. For example, delete_check is applied on a deleteExpression.
Looking forward your reviews, I will try yo extend this proof of concept to all warnings in next few days if you're are okay with this direction.