forked from firka/flutter
de-duplicate code in analyze.dart (#151279)
This is just a de-duplication PR that should be a no-op.
This commit is contained in:
committed by
GitHub
parent
1ebdbeef6c
commit
55520b842c
@@ -184,8 +184,8 @@ Future<void> run(List<String> arguments) async {
|
||||
final String ruleNames = rules.map((AnalyzeRule rule) => '\n * $rule').join();
|
||||
printProgress('Analyzing code in the framework with the following rules:$ruleNames');
|
||||
await analyzeWithRules(flutterRoot, rules,
|
||||
includePaths: <String>['packages/flutter/lib'],
|
||||
excludePaths: <String>['packages/flutter/lib/fix_data'],
|
||||
includePaths: const <String>['packages/flutter/lib'],
|
||||
excludePaths: const <String>['packages/flutter/lib/fix_data'],
|
||||
);
|
||||
final List<AnalyzeRule> testRules = <AnalyzeRule>[noStopwatches];
|
||||
final String testRuleNames = testRules.map((AnalyzeRule rule) => '\n * $rule').join();
|
||||
@@ -196,7 +196,14 @@ Future<void> run(List<String> arguments) async {
|
||||
final List<AnalyzeRule> toolRules = <AnalyzeRule>[AvoidFutureCatchError()];
|
||||
final String toolRuleNames = toolRules.map((AnalyzeRule rule) => '\n * $rule').join();
|
||||
printProgress('Analyzing code in the tool with the following rules:$toolRuleNames');
|
||||
await analyzeToolWithRules(flutterRoot, toolRules);
|
||||
await analyzeWithRules(
|
||||
flutterRoot,
|
||||
toolRules,
|
||||
includePaths: const <String>[
|
||||
'packages/flutter_tools/lib',
|
||||
'packages/flutter_tools/test',
|
||||
],
|
||||
);
|
||||
} else {
|
||||
printProgress('Skipped performing further analysis in the framework because "flutter analyze" finished with a non-zero exit code.');
|
||||
}
|
||||
|
||||
@@ -64,41 +64,6 @@ Future<void> analyzeWithRules(String flutterRootDirectory, List<AnalyzeRule> rul
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> analyzeToolWithRules(String flutterRootDirectory, List<AnalyzeRule> rules) async {
|
||||
final String libPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/lib');
|
||||
if (!Directory(libPath).existsSync()) {
|
||||
foundError(<String>['Analyzer error: the specified $libPath does not exist.']);
|
||||
}
|
||||
final String testPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/test');
|
||||
final AnalysisContextCollection collection = AnalysisContextCollection(
|
||||
includedPaths: <String>[libPath, testPath],
|
||||
);
|
||||
|
||||
final List<String> analyzerErrors = <String>[];
|
||||
for (final AnalysisContext context in collection.contexts) {
|
||||
final Iterable<String> analyzedFilePaths = context.contextRoot.analyzedFiles();
|
||||
final AnalysisSession session = context.currentSession;
|
||||
|
||||
for (final String filePath in analyzedFilePaths) {
|
||||
final SomeResolvedUnitResult unit = await session.getResolvedUnit(filePath);
|
||||
if (unit is ResolvedUnitResult) {
|
||||
for (final AnalyzeRule rule in rules) {
|
||||
rule.applyTo(unit);
|
||||
}
|
||||
} else {
|
||||
analyzerErrors.add('Analyzer error: file $unit could not be resolved. Expected "ResolvedUnitResult", got ${unit.runtimeType}.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (analyzerErrors.isNotEmpty) {
|
||||
foundError(analyzerErrors);
|
||||
}
|
||||
for (final AnalyzeRule verifier in rules) {
|
||||
verifier.reportViolations(flutterRootDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/// An interface that defines a set of best practices, and collects information
|
||||
/// about code that violates the best practices in a [ResolvedUnitResult].
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user