From 35fcd9077f4d60e67f11518cacf290857b139e5d Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 14 Jan 2019 13:49:50 -0800 Subject: [PATCH] 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. --- dev/bots/analyze.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 3a493c8827..1d3f4758e2 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -383,8 +383,8 @@ bool _matches(List a, List 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 _findDependencies(String srcPath, List errors, { bool checkForMeta = false }) { return Directory(srcPath).listSync(recursive: true).where((FileSystemEntity entity) { @@ -395,7 +395,7 @@ Set _findDependencies(String srcPath, List 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) {