From cc6c16dc88fb52c5fabc8041931df80f7af234a0 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 8 Jul 2021 13:22:11 -0400 Subject: [PATCH] [flutter_plugin_tools] Only check target packages in analyze Makes validating that there are no unexpected analysis_options.yaml files part of the per-package loop, rather than a pre-check, so that it only runs against the target packages. This makes it easier to run locally on specific packages, since it's not necessary to pass the allow list for every package when targetting just one package. --- script/tool/lib/src/analyze_command.dart | 17 +++++++++-------- script/tool/test/analyze_command_test.dart | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/script/tool/lib/src/analyze_command.dart b/script/tool/lib/src/analyze_command.dart index b8458da5228c..2c4fc1b8376e 100644 --- a/script/tool/lib/src/analyze_command.dart +++ b/script/tool/lib/src/analyze_command.dart @@ -11,7 +11,6 @@ import 'common/core.dart'; import 'common/package_looping_command.dart'; import 'common/process_runner.dart'; -const int _exitBadCustomAnalysisFile = 2; const int _exitPackagesGetFailed = 3; /// A command to run Dart analysis on packages. @@ -48,8 +47,8 @@ class AnalyzeCommand extends PackageLoopingCommand { final bool hasLongOutput = false; /// Checks that there are no unexpected analysis_options.yaml files. - void _validateAnalysisOptions() { - final List files = packagesDir.listSync(recursive: true); + bool _hasUnexpecetdAnalysisOptions(Directory package) { + final List files = package.listSync(recursive: true); for (final FileSystemEntity file in files) { if (file.basename != 'analysis_options.yaml' && file.basename != '.analysis_options') { @@ -60,7 +59,8 @@ class AnalyzeCommand extends PackageLoopingCommand { (String directory) => directory != null && directory.isNotEmpty && - p.isWithin(p.join(packagesDir.path, directory), file.path)); + p.isWithin( + packagesDir.childDirectory(directory).path, file.path)); if (allowed) { continue; } @@ -70,8 +70,9 @@ class AnalyzeCommand extends PackageLoopingCommand { printError( 'If this was deliberate, pass the package to the analyze command ' 'with the --$_customAnalysisFlag flag and try again.'); - throw ToolExit(_exitBadCustomAnalysisFile); + return true; } + return false; } /// Ensures that the dependent packages have been fetched for all packages @@ -100,9 +101,6 @@ class AnalyzeCommand extends PackageLoopingCommand { @override Future initializeRun() async { - print('Verifying analysis settings...'); - _validateAnalysisOptions(); - print('Fetching dependencies...'); if (!await _runPackagesGetOnTargetPackages()) { printError('Unable to get dependencies.'); @@ -116,6 +114,9 @@ class AnalyzeCommand extends PackageLoopingCommand { @override Future runForPackage(Directory package) async { + if (_hasUnexpecetdAnalysisOptions(package)) { + return PackageResult.fail(['Unexpected local analysis options']); + } final int exitCode = await processRunner.runAndStream( _dartBinaryPath, ['analyze', '--fatal-infos'], workingDir: package); diff --git a/script/tool/test/analyze_command_test.dart b/script/tool/test/analyze_command_test.dart index 768463f0a5a2..adeaabaaca52 100644 --- a/script/tool/test/analyze_command_test.dart +++ b/script/tool/test/analyze_command_test.dart @@ -126,6 +126,8 @@ void main() { containsAllInOrder([ contains( 'Found an extra analysis_options.yaml at /packages/foo/analysis_options.yaml'), + contains(' foo:\n' + ' Unexpected local analysis options'), ]), ); }); @@ -146,6 +148,8 @@ void main() { containsAllInOrder([ contains( 'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'), + contains(' foo:\n' + ' Unexpected local analysis options'), ]), ); });