Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[flutter_plugin_tools] Only check target packages in analyze #4146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<FileSystemEntity> files = packagesDir.listSync(recursive: true);
bool _hasUnexpecetdAnalysisOptions(Directory package) {
final List<FileSystemEntity> files = package.listSync(recursive: true);
for (final FileSystemEntity file in files) {
if (file.basename != 'analysis_options.yaml' &&
file.basename != '.analysis_options') {
Expand All @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -100,9 +101,6 @@ class AnalyzeCommand extends PackageLoopingCommand {

@override
Future<void> initializeRun() async {
print('Verifying analysis settings...');
_validateAnalysisOptions();

print('Fetching dependencies...');
if (!await _runPackagesGetOnTargetPackages()) {
printError('Unable to get dependencies.');
Expand All @@ -116,6 +114,9 @@ class AnalyzeCommand extends PackageLoopingCommand {

@override
Future<PackageResult> runForPackage(Directory package) async {
if (_hasUnexpecetdAnalysisOptions(package)) {
return PackageResult.fail(<String>['Unexpected local analysis options']);
}
final int exitCode = await processRunner.runAndStream(
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
workingDir: package);
Expand Down
4 changes: 4 additions & 0 deletions script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void main() {
containsAllInOrder(<Matcher>[
contains(
'Found an extra analysis_options.yaml at /packages/foo/analysis_options.yaml'),
contains(' foo:\n'
' Unexpected local analysis options'),
]),
);
});
Expand All @@ -146,6 +148,8 @@ void main() {
containsAllInOrder(<Matcher>[
contains(
'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'),
contains(' foo:\n'
' Unexpected local analysis options'),
]),
);
});
Expand Down