mirror of
https://github.com/flutter/packages.git
synced 2025-06-27 13:19:06 +08:00
[flutter_plugin_tools] Only check target packages in analyze (#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.
This commit is contained in:
@ -11,7 +11,6 @@ import 'common/core.dart';
|
|||||||
import 'common/package_looping_command.dart';
|
import 'common/package_looping_command.dart';
|
||||||
import 'common/process_runner.dart';
|
import 'common/process_runner.dart';
|
||||||
|
|
||||||
const int _exitBadCustomAnalysisFile = 2;
|
|
||||||
const int _exitPackagesGetFailed = 3;
|
const int _exitPackagesGetFailed = 3;
|
||||||
|
|
||||||
/// A command to run Dart analysis on packages.
|
/// A command to run Dart analysis on packages.
|
||||||
@ -48,8 +47,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
final bool hasLongOutput = false;
|
final bool hasLongOutput = false;
|
||||||
|
|
||||||
/// Checks that there are no unexpected analysis_options.yaml files.
|
/// Checks that there are no unexpected analysis_options.yaml files.
|
||||||
void _validateAnalysisOptions() {
|
bool _hasUnexpecetdAnalysisOptions(Directory package) {
|
||||||
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
|
final List<FileSystemEntity> files = package.listSync(recursive: true);
|
||||||
for (final FileSystemEntity file in files) {
|
for (final FileSystemEntity file in files) {
|
||||||
if (file.basename != 'analysis_options.yaml' &&
|
if (file.basename != 'analysis_options.yaml' &&
|
||||||
file.basename != '.analysis_options') {
|
file.basename != '.analysis_options') {
|
||||||
@ -60,7 +59,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
(String directory) =>
|
(String directory) =>
|
||||||
directory != null &&
|
directory != null &&
|
||||||
directory.isNotEmpty &&
|
directory.isNotEmpty &&
|
||||||
p.isWithin(p.join(packagesDir.path, directory), file.path));
|
p.isWithin(
|
||||||
|
packagesDir.childDirectory(directory).path, file.path));
|
||||||
if (allowed) {
|
if (allowed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -70,8 +70,9 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
printError(
|
printError(
|
||||||
'If this was deliberate, pass the package to the analyze command '
|
'If this was deliberate, pass the package to the analyze command '
|
||||||
'with the --$_customAnalysisFlag flag and try again.');
|
'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
|
/// Ensures that the dependent packages have been fetched for all packages
|
||||||
@ -100,9 +101,6 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> initializeRun() async {
|
Future<void> initializeRun() async {
|
||||||
print('Verifying analysis settings...');
|
|
||||||
_validateAnalysisOptions();
|
|
||||||
|
|
||||||
print('Fetching dependencies...');
|
print('Fetching dependencies...');
|
||||||
if (!await _runPackagesGetOnTargetPackages()) {
|
if (!await _runPackagesGetOnTargetPackages()) {
|
||||||
printError('Unable to get dependencies.');
|
printError('Unable to get dependencies.');
|
||||||
@ -116,6 +114,9 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<PackageResult> runForPackage(Directory package) async {
|
Future<PackageResult> runForPackage(Directory package) async {
|
||||||
|
if (_hasUnexpecetdAnalysisOptions(package)) {
|
||||||
|
return PackageResult.fail(<String>['Unexpected local analysis options']);
|
||||||
|
}
|
||||||
final int exitCode = await processRunner.runAndStream(
|
final int exitCode = await processRunner.runAndStream(
|
||||||
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
|
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
|
||||||
workingDir: package);
|
workingDir: package);
|
||||||
|
@ -126,6 +126,8 @@ void main() {
|
|||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains(
|
contains(
|
||||||
'Found an extra analysis_options.yaml at /packages/foo/analysis_options.yaml'),
|
'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(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains(
|
contains(
|
||||||
'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'),
|
'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'),
|
||||||
|
contains(' foo:\n'
|
||||||
|
' Unexpected local analysis options'),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user