-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 //ignore comments to suppress static errors #44237
Comments
CC @Hixie @jonahwilliams who ran into this in flutter/flutter#70506 and flutter/flutter#52899 |
This would fix #42977 |
I wrote #27218 (comment) and #42977 (comment) in support of allowing errors to be ignored. I would also make security lints ignorable, FWIW. There's always going to be cases where a lint is wrong. For example, suppose someone wants to write a security tutorial, and wants to analyze their code. They might want to have code that shows the vulnerability, and so they're going to need to ignore the lint. |
FWIW: I'm very much in favor of a revert. There are other ways we can enforce a policy of unignorability internally and this has clearly turned out to be too big a hammer... |
There needs to be a way to keep security lints un-ignoreable in google3, but I'm neutral on the other cases presented. |
This isn't true in practice. For example, people may be analyzing code that has known missing dependencies, e.g. the issue that led me to investigate this earlier today was that the analyzer was complaining about a missing import because the |
If the program you are analyzing isn't the program you are compiling, or the analyzer and compiler are not using the same language, then obviously any connection between the results is tenuous at best. Those are the assumptions that makes it possible to have an analyzer separate from the compiler. |
I mean, I get that in theory. In practice, there may not be an analyzer that matches the language/compiler in use. Having to abandon analysis entirely, or having to wrap the analyzer in code that post-processes the messages (something Flutter used to do), seems like a high cost compared to just being able to use an existing feature to silence analyzer output on a per-line basis. This may be a philosophy vs pragmatism discussion. Pragmatic software tends to get more users than philosophically correct software, so I personally think pragmatism should always win, but I understand the attraction of making a philosophically-correct product as well. |
For what it's worth, dart:ui was one of the reasons we pushed forward with this solution. Allowing errors to be easily ignored was an easy tool for users to use - it facilitated technical debt building up in the ecosystem. It was too easy to just ignore an error and push forward with a temporary solution, and then for that solution to become permanent. I see having two different public APIs for |
If we want to allow a: # analysis_options.yaml
analyzer:
allow_ignoring_errors: true ... for a select few projects, I have no strong opinion there, but I agree with @devoncarew otherwise. |
I'm 100% behind removing technical debt. Unfortunately, making //ignore not work on errors didn't help at all here because we promptly added an exception for that very code. That's how I ran into this -- I was trying to move where the //ignore was from a package into autogenerated code (which seems like an improvement, if maybe only a minor one), and was unable to because while the package was exempt and could //ignore the problematic code, the autogenerated code was not and could not.
FWIW this wouldn't really help in the case I reference above, since the //ignore in question is present for every Flutter app (or at least, every Flutter app compiled for web), so we'd have to enable it in our global analysis options, which seems to defeat the point of making it opt-in. |
FYI |
You are not only blocking ignore for errors, or compile issues, but also for security warnings, of totally normal codes (like unsafe_html)! In Dart 2.12.0 is not possible to make a simple set of a 'src' of an image! There's no alternative to do that without warnings. |
@bwilkerson has a great suggestion at #45230 (comment), something like an analysis option which says which codes are un-ignorable: analyzer:
cannot_ignore:
- unsafe_html This supports the original requirement of having _un_ignorable security codes internally at Google. This would change all compile-time errors to be totally ignorable (desired by Flutter and others). In theory, you could add compile_time errors to |
If that's a use case we want to support, then I'd propose that we have a way to specify "groups" of diagnostics (perhaps 'compile_time_errors' or even 'security-errors') as being un-ignorable. It isn't reasonable to expect any user to be able to maintain a list of compile time errors given that we typically add several with each new language feature. |
I love it. It feels very pragmatic, helpful, and can be discoverable when we get more auto-complete / analysis working in |
In closing #27218 (I think for Dart 2.9) we changed the behavior of
// ignore:
comments such that they could no longer suppress "errors" or "warnings" (defined by the language specification); they could only ignore "hints" (likeunused_import
) or "lints."The initial idea was that nothing good can come from
// ignore
-ing a compile-time error, and a user may be confused about what// ignore
does if not suppress the error at runtime as well.The change was ultimately made so that security-motivated lint rules could be written and could not be ignored. The
SecurityLintCode
class makes use of un-ignorability. Lint rules like unsafe_html use this. This feature means that developers cannot ignore a security-motivated lint rule inline.The big problem which has arisen since closing #27218 is that the analyzer is not infallible. If the analyzer reports a false positive error diagnostic, the developer can do nothing inline to suppress that erroneous diagnostic. They can bulk ignore the diagnostic code in an
analysis_options.yaml
file, but not file-by-file. This problem is big because of CI systems. Generally a CI bot/queue/configuration is red or green. If a code repository has one false positive static analysis diagnostic, then the "analyze" bot/queue/configuration is just red.I think the analyzer team should revisit un-ignorable errors, and likely reduce the concept to just un-ignorable security-motivated lints.
The text was updated successfully, but these errors were encountered: