-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Narrow regexp for import search in bot's analyze script. #26539
Conversation
final RegExp _importPattern = RegExp(r"import 'package:flutter/([^.]+)\.dart'"); | ||
final RegExp _importMetaPattern = RegExp(r"import 'package:meta/meta.dart'"); | ||
final RegExp _importPattern = RegExp(r'''^\s*import (['"])package:flutter/([^.]+)\.dart\1'''); | ||
final RegExp _importMetaPattern = RegExp(r'''^\s*import (['"])package:meta/meta.dart\1'''); |
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 thought we expected imports to use single quotes?
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 think checking for both makes this more resilient to lint failures.
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 do, but if this check doesn't look for double quotes, then it might miss a problem in imports. There is another analyzer lint that checks for double quotes here, so it will still fail the analysis.
I wanted those to be independent checks: imagine if you put double quotes on a problematic import: the analysis would fail the first time on the double quote check, but give no other errors. The second time you ran it, it would give the "import problem" error. The way this RegExp is, you'd now get both errors on the first run.
final RegExp _importPattern = RegExp(r"import 'package:flutter/([^.]+)\.dart'"); | ||
final RegExp _importMetaPattern = RegExp(r"import 'package:meta/meta.dart'"); | ||
final RegExp _importPattern = RegExp(r'''^\s*import (['"])package:flutter/([^.]+)\.dart\1'''); | ||
final RegExp _importMetaPattern = RegExp(r'''^\s*import (['"])package:meta/meta.dart\1'''); |
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.
How do these ignore 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.
The "^" anchors the search at the start of the line.
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.
mind = blown
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.
LGTM
This was causing analysis to fail when there was an import statement in a comment, such as when snippets add imports to their examples. I narrowed the RegExp to match only those lines which aren't commented out, but it really should probably be using the analysis server to catch all cases (e.g. if someone put the doc comment into /** */ comments, it could still match). Since this is a Flutter-specific script, it's probably not worth doing that.
This was causing analysis to fail when there was an import statement in a comment, such as when snippets add imports to their examples.
I narrowed the RegExp to match only those lines which aren't commented out, but it really should probably be using the analysis server to catch all cases (e.g. if someone put the doc comment into /** */ comments, it could still match). Since this is a Flutter-specific script, it's probably not worth doing that.