Skip to content

Commit 55520b8

Browse files
de-duplicate code in analyze.dart (#151279)
This is just a de-duplication PR that should be a no-op.
1 parent 1ebdbee commit 55520b8

File tree

2 files changed

+10
-38
lines changed

2 files changed

+10
-38
lines changed

dev/bots/analyze.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ Future<void> run(List<String> arguments) async {
184184
final String ruleNames = rules.map((AnalyzeRule rule) => '\n * $rule').join();
185185
printProgress('Analyzing code in the framework with the following rules:$ruleNames');
186186
await analyzeWithRules(flutterRoot, rules,
187-
includePaths: <String>['packages/flutter/lib'],
188-
excludePaths: <String>['packages/flutter/lib/fix_data'],
187+
includePaths: const <String>['packages/flutter/lib'],
188+
excludePaths: const <String>['packages/flutter/lib/fix_data'],
189189
);
190190
final List<AnalyzeRule> testRules = <AnalyzeRule>[noStopwatches];
191191
final String testRuleNames = testRules.map((AnalyzeRule rule) => '\n * $rule').join();
@@ -196,7 +196,14 @@ Future<void> run(List<String> arguments) async {
196196
final List<AnalyzeRule> toolRules = <AnalyzeRule>[AvoidFutureCatchError()];
197197
final String toolRuleNames = toolRules.map((AnalyzeRule rule) => '\n * $rule').join();
198198
printProgress('Analyzing code in the tool with the following rules:$toolRuleNames');
199-
await analyzeToolWithRules(flutterRoot, toolRules);
199+
await analyzeWithRules(
200+
flutterRoot,
201+
toolRules,
202+
includePaths: const <String>[
203+
'packages/flutter_tools/lib',
204+
'packages/flutter_tools/test',
205+
],
206+
);
200207
} else {
201208
printProgress('Skipped performing further analysis in the framework because "flutter analyze" finished with a non-zero exit code.');
202209
}

dev/bots/custom_rules/analyze.dart

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,6 @@ Future<void> analyzeWithRules(String flutterRootDirectory, List<AnalyzeRule> rul
6464
}
6565
}
6666

67-
Future<void> analyzeToolWithRules(String flutterRootDirectory, List<AnalyzeRule> rules) async {
68-
final String libPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/lib');
69-
if (!Directory(libPath).existsSync()) {
70-
foundError(<String>['Analyzer error: the specified $libPath does not exist.']);
71-
}
72-
final String testPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/test');
73-
final AnalysisContextCollection collection = AnalysisContextCollection(
74-
includedPaths: <String>[libPath, testPath],
75-
);
76-
77-
final List<String> analyzerErrors = <String>[];
78-
for (final AnalysisContext context in collection.contexts) {
79-
final Iterable<String> analyzedFilePaths = context.contextRoot.analyzedFiles();
80-
final AnalysisSession session = context.currentSession;
81-
82-
for (final String filePath in analyzedFilePaths) {
83-
final SomeResolvedUnitResult unit = await session.getResolvedUnit(filePath);
84-
if (unit is ResolvedUnitResult) {
85-
for (final AnalyzeRule rule in rules) {
86-
rule.applyTo(unit);
87-
}
88-
} else {
89-
analyzerErrors.add('Analyzer error: file $unit could not be resolved. Expected "ResolvedUnitResult", got ${unit.runtimeType}.');
90-
}
91-
}
92-
}
93-
94-
if (analyzerErrors.isNotEmpty) {
95-
foundError(analyzerErrors);
96-
}
97-
for (final AnalyzeRule verifier in rules) {
98-
verifier.reportViolations(flutterRootDirectory);
99-
}
100-
}
101-
10267
/// An interface that defines a set of best practices, and collects information
10368
/// about code that violates the best practices in a [ResolvedUnitResult].
10469
///

0 commit comments

Comments
 (0)