From 0290622bc6406af82861594debb6ae808d3ba1ee Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 3 Dec 2015 19:52:23 -0800 Subject: [PATCH] Analyzer improvements - strengthen analyzer against error messages that point past the bottom of the file. - ignore any errors in intl's auto-generated files. --- packages/flutter_tools/lib/src/commands/analyze.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index 23c3ad2e93c..14e5d3fd1cd 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -256,9 +256,9 @@ class AnalyzeCommand extends FlutterCommand { ]; RegExp generalPattern = new RegExp(r'^\[(error|warning|hint|lint)\] (.+) \(([^(),]+), line ([0-9]+), col ([0-9]+)\)$'); - RegExp ignorePattern = new RegExp(r'// analyzer says "([^"]+)"'); + RegExp allowedIdentifiersPattern = new RegExp(r'_?([A-Z]|_+)\b'); RegExp constructorTearOffsPattern = new RegExp('.+#.+// analyzer doesn\'t like constructor tear-offs'); - RegExp allowedIdentifiers = new RegExp(r'_?([A-Z]|_+)\b'); + RegExp ignorePattern = new RegExp(r'// analyzer says "([^"]+)"'); List errorLines = output.toString().split('\n'); for (String errorLine in errorLines) { @@ -272,12 +272,16 @@ class AnalyzeCommand extends FlutterCommand { int colNumber = int.parse(groups[5]); File source = new File(filename); List sourceLines = source.readAsLinesSync(); - String sourceLine = sourceLines[lineNumber-1]; + String sourceLine = (lineNumber < sourceLines.length) ? sourceLines[lineNumber-1] : ''; bool shouldIgnore = false; if (filename.endsWith('.mojom.dart')) { + // autogenerated code - TODO(ianh): Fix the Dart mojom compiler + shouldIgnore = true; + } else if ((sourceLines[0] == '/**') && (' * DO NOT EDIT. This is code generated'.matchAsPrefix(sourceLines[1]) != null)) { + // autogenerated code - TODO(ianh): Fix the intl package resource generator shouldIgnore = true; } else if (level == 'lint' && errorMessage == 'Name non-constant identifiers using lowerCamelCase.') { - if (allowedIdentifiers.matchAsPrefix(sourceLine, colNumber-1) != null) + if (allowedIdentifiersPattern.matchAsPrefix(sourceLine, colNumber-1) != null) shouldIgnore = true; } else if (constructorTearOffsPattern.allMatches(sourceLine).isNotEmpty) { shouldIgnore = true;