Narrow regexp for import search in bot's analyze script. (#26539)

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 commit is contained in:
Greg Spencer 2019-01-14 13:49:50 -08:00 committed by GitHub
parent 567db6f0d4
commit 35fcd9077f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,8 +383,8 @@ bool _matches<T>(List<T> a, List<T> b) {
return true;
}
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''');
Set<String> _findDependencies(String srcPath, List<String> errors, { bool checkForMeta = false }) {
return Directory(srcPath).listSync(recursive: true).where((FileSystemEntity entity) {
@ -395,7 +395,7 @@ Set<String> _findDependencies(String srcPath, List<String> errors, { bool checkF
for (String line in file.readAsLinesSync()) {
Match match = _importPattern.firstMatch(line);
if (match != null)
result.add(match.group(1));
result.add(match.group(2));
if (checkForMeta) {
match = _importMetaPattern.firstMatch(line);
if (match != null) {