Skip to content

Commit 63bfd1f

Browse files
stuartmorgan-gfotiDim
authored andcommitted
[flutter_plugin_tools] Only check target packages in analyze (flutter#4146)
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.
1 parent d24cc15 commit 63bfd1f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

script/tool/lib/src/analyze_command.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'common/core.dart';
1111
import 'common/package_looping_command.dart';
1212
import 'common/process_runner.dart';
1313

14-
const int _exitBadCustomAnalysisFile = 2;
1514
const int _exitPackagesGetFailed = 3;
1615

1716
/// A command to run Dart analysis on packages.
@@ -48,8 +47,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
4847
final bool hasLongOutput = false;
4948

5049
/// Checks that there are no unexpected analysis_options.yaml files.
51-
void _validateAnalysisOptions() {
52-
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
50+
bool _hasUnexpecetdAnalysisOptions(Directory package) {
51+
final List<FileSystemEntity> files = package.listSync(recursive: true);
5352
for (final FileSystemEntity file in files) {
5453
if (file.basename != 'analysis_options.yaml' &&
5554
file.basename != '.analysis_options') {
@@ -60,7 +59,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
6059
(String directory) =>
6160
directory != null &&
6261
directory.isNotEmpty &&
63-
p.isWithin(p.join(packagesDir.path, directory), file.path));
62+
p.isWithin(
63+
packagesDir.childDirectory(directory).path, file.path));
6464
if (allowed) {
6565
continue;
6666
}
@@ -70,8 +70,9 @@ class AnalyzeCommand extends PackageLoopingCommand {
7070
printError(
7171
'If this was deliberate, pass the package to the analyze command '
7272
'with the --$_customAnalysisFlag flag and try again.');
73-
throw ToolExit(_exitBadCustomAnalysisFile);
73+
return true;
7474
}
75+
return false;
7576
}
7677

7778
/// Ensures that the dependent packages have been fetched for all packages
@@ -100,9 +101,6 @@ class AnalyzeCommand extends PackageLoopingCommand {
100101

101102
@override
102103
Future<void> initializeRun() async {
103-
print('Verifying analysis settings...');
104-
_validateAnalysisOptions();
105-
106104
print('Fetching dependencies...');
107105
if (!await _runPackagesGetOnTargetPackages()) {
108106
printError('Unable to get dependencies.');
@@ -116,6 +114,9 @@ class AnalyzeCommand extends PackageLoopingCommand {
116114

117115
@override
118116
Future<PackageResult> runForPackage(Directory package) async {
117+
if (_hasUnexpecetdAnalysisOptions(package)) {
118+
return PackageResult.fail(<String>['Unexpected local analysis options']);
119+
}
119120
final int exitCode = await processRunner.runAndStream(
120121
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
121122
workingDir: package);

script/tool/test/analyze_command_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ void main() {
126126
containsAllInOrder(<Matcher>[
127127
contains(
128128
'Found an extra analysis_options.yaml at /packages/foo/analysis_options.yaml'),
129+
contains(' foo:\n'
130+
' Unexpected local analysis options'),
129131
]),
130132
);
131133
});
@@ -146,6 +148,8 @@ void main() {
146148
containsAllInOrder(<Matcher>[
147149
contains(
148150
'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'),
151+
contains(' foo:\n'
152+
' Unexpected local analysis options'),
149153
]),
150154
);
151155
});

0 commit comments

Comments
 (0)