Repository navigation
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.
I thought we expected imports to use single quotes?
There was a problem hiding this comment.
I think checking for both makes this more resilient to lint failures.
There was a problem hiding this comment.
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.
How do these ignore comments?
There was a problem hiding this comment.
The "^" anchors the search at the start of the line.
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.