From c4d1b31b746955a28c05c959873a9e9eeebc042d Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 19 Oct 2018 08:01:05 -0700 Subject: [PATCH] don't disable TODO issues in IDEs (#23274) * don't disable TODO issues in IDEs * minor change to start cirrus --- dev/bots/analyze-sample-code.dart | 2 +- .../flutter/lib/analysis_options_user.yaml | 2 -- .../lib/src/commands/analyze_once.dart | 7 +++--- .../test/commands/analyze_once_test.dart | 24 ++++++++++++++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/dev/bots/analyze-sample-code.dart b/dev/bots/analyze-sample-code.dart index 9e0458282c..c3e8c49a57 100644 --- a/dev/bots/analyze-sample-code.dart +++ b/dev/bots/analyze-sample-code.dart @@ -231,7 +231,7 @@ linter: errors.add(null); errors.addAll(await process.stdout.transform(utf8.decoder).transform(const LineSplitter()).toList()); // top is stderr - if (errors.isNotEmpty && (errors.first.contains(' issues found. (ran in ') || errors.first.contains(' issue found. (ran in '))) { + if (errors.isNotEmpty && (errors.first.contains(' issues found (ran in ') || errors.first.contains(' issue found (ran in '))) { errors.removeAt(0); // the "23 issues found" message goes onto stderr, which is concatenated first if (errors.isNotEmpty && errors.last.isEmpty) errors.removeLast(); // if there's an "issues found" message, we put a blank line on stdout before it diff --git a/packages/flutter/lib/analysis_options_user.yaml b/packages/flutter/lib/analysis_options_user.yaml index e558021bc9..01c274a8b1 100644 --- a/packages/flutter/lib/analysis_options_user.yaml +++ b/packages/flutter/lib/analysis_options_user.yaml @@ -24,8 +24,6 @@ analyzer: errors: # treat missing required parameters as a warning (not a hint) missing_required_param: warning - # allow having TODOs in the code - todo: ignore linter: rules: diff --git a/packages/flutter_tools/lib/src/commands/analyze_once.dart b/packages/flutter_tools/lib/src/commands/analyze_once.dart index faadddcbaf..942db176bf 100644 --- a/packages/flutter_tools/lib/src/commands/analyze_once.dart +++ b/packages/flutter_tools/lib/src/commands/analyze_once.dart @@ -87,7 +87,8 @@ class AnalyzeOnce extends AnalyzeBase { } }); server.onErrors.listen((FileAnalysisErrors fileErrors) { - errors.addAll(fileErrors.errors); + // Record the issues found (but filter out to do comments). + errors.addAll(fileErrors.errors.where((AnalysisError error) => error.type != 'TODO')); }); await server.start(); @@ -148,9 +149,9 @@ class AnalyzeOnce extends AnalyzeBase { final int errorCount = errors.length; printStatus(''); if (undocumentedMembers > 0) { - throwToolExit('$errorCount ${pluralize('issue', errorCount)} found. (ran in ${seconds}s; $dartdocMessage)'); + throwToolExit('$errorCount ${pluralize('issue', errorCount)} found (ran in ${seconds}s; $dartdocMessage).'); } else { - throwToolExit('$errorCount ${pluralize('issue', errorCount)} found. (ran in ${seconds}s)'); + throwToolExit('$errorCount ${pluralize('issue', errorCount)} found (ran in ${seconds}s).'); } } diff --git a/packages/flutter_tools/test/commands/analyze_once_test.dart b/packages/flutter_tools/test/commands/analyze_once_test.dart index 1166a6effb..4c87e50d35 100644 --- a/packages/flutter_tools/test/commands/analyze_once_test.dart +++ b/packages/flutter_tools/test/commands/analyze_once_test.dart @@ -96,7 +96,7 @@ void main() { 'warning $analyzerSeparator The parameter \'onPressed\' is required', 'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used', ], - exitMessageContains: '2 issues found.', + exitMessageContains: '2 issues found', toolExit: true, ); }, timeout: allowForSlowAnalyzeTests); @@ -123,7 +123,7 @@ void main() { 'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used', 'info $analyzerSeparator Only throw instances of classes extending either Exception or Error', ], - exitMessageContains: '3 issues found.', + exitMessageContains: '3 issues found', toolExit: true, ); }, timeout: allowForSlowAnalyzeTests); @@ -154,7 +154,7 @@ void bar() { statusTextContains: [ 'Analyzing', ], - exitMessageContains: '1 issue found.', + exitMessageContains: '1 issue found', toolExit: true, ); } finally { @@ -178,6 +178,24 @@ StringBuffer bar = StringBuffer('baz'); tryToDelete(tempDir); } }); + + testUsingContext('returns no issues for todo comments', () async { + const String contents = ''' +// TODO(foobar): +StringBuffer bar = StringBuffer('baz'); +'''; + final Directory tempDir = fs.systemTempDirectory.createTempSync('flutter_analyze_once_test_4.'); + tempDir.childFile('main.dart').writeAsStringSync(contents); + try { + await runCommand( + command: AnalyzeCommand(workingDirectory: fs.directory(tempDir)), + arguments: ['analyze'], + statusTextContains: ['No issues found!'], + ); + } finally { + tryToDelete(tempDir); + } + }); }); }