-
Notifications
You must be signed in to change notification settings - Fork 170
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
Implement null_safety rule #2773
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.
Thanks!
You should be able to handle the pubspec case by overriding PubspecVisitor getPubspecVisitor()
in your subclass of LintRule
. I haven't verified that it will give you access to everything you need, but we can extend it if necessary.
lib/src/rules/null_safety.dart
Outdated
class NullSafety extends LintRule implements NodeLintRule { | ||
NullSafety() | ||
: super( | ||
name: 'null_safety', |
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.
Although it isn't strictly a requirement, consider naming this with a verb phrase, something like enable_null_safety
. We generally try to name lints so that they describe either what should be done or what shouldn't be done.
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.
I see, it is now enable_null_safety
. Another suggestion is ensure_sound_null_safety
.
abd2b6d
to
eb560a5
Compare
@pq Do we want to merge this now (well, after the conflict is resolved) and risk it being a breaking change to have additional checks, or would it be better to merge this after the next roll into the SDK so that it can't be used yet? A third option would be to mark it as experimental until the pubspec checking has been added. (FYI, Flutter is interested in this lint.) |
3d4f0a3
to
2d3e58e
Compare
@override | ||
void registerNodeProcessors( | ||
NodeLintRegistry registry, LinterContext context) { | ||
var visitor = _Visitor(this, context); |
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.
I don't know how expensive the comment parsing below is but I wonder if it's worth bailing if non-nullability is enabled?
if (context.isEnabled(Feature.non_nullable)) {
return;
}
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.
The comments have already been parsed and are in the AST so it's fairly inexpensive to iterate over them, but it wouldn't hurt to check.
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.
👍
More specifically I mean the cost of the regexps.
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.
Thanks for hinting.
if (context.isEnabled(Feature.non_nullable)) {
return;
}
doesn't work, giving all cases are ok (2 should fail).
On the other hand, there was also a suggestion to do something like:
if (line.replaceAll(' ', '').startsWith('//@dart=')) {
// parse the version
}
if there is a concern about regExp
.
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.
It might not be too bad, given that we only need to look at the comments before the first non-comment token in the file (modulo the corner case below). The performance is then dependent on the length of the file header and library documentation comments.
1fd6b6a
to
1768bf5
Compare
1768bf5
to
6c29df7
Compare
I think it would be super good to land this. Would you mind fixing the merge conflict, @asashour ? |
@bwilkerson @pq this is the rule that bans |
# Conflicts: # CHANGELOG.md
@override | ||
void registerNodeProcessors( | ||
NodeLintRegistry registry, LinterContext context) { | ||
var visitor = _Visitor(this, context); |
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.
It might not be too bad, given that we only need to look at the comments before the first non-comment token in the file (modulo the corner case below). The performance is then dependent on the length of the file header and library documentation comments.
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.
👍
I'd like to hold off on landing this until after the currently in progress roll is finished. (See: https://dart-review.googlesource.com/c/sdk/+/264961) Thanks for your patience! |
* Implement enable_null_safety rule * year * Update tests * Use `reflective_test_loader` * `all.dart`
Implements the first requirement of #2702
I am not sure how best to process
pubspec.yaml
Should the name be
sound_null_safety
,unsound_null_safety
, ...?