From 55520b842cffd482baf0f813c5bdc641ced44b6d Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Fri, 5 Jul 2024 13:31:20 -0700 Subject: [PATCH] de-duplicate code in analyze.dart (#151279) This is just a de-duplication PR that should be a no-op. --- dev/bots/analyze.dart | 13 ++++++++--- dev/bots/custom_rules/analyze.dart | 35 ------------------------------ 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index d284aaff88..3184f987fc 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -184,8 +184,8 @@ Future run(List 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: ['packages/flutter/lib'], - excludePaths: ['packages/flutter/lib/fix_data'], + includePaths: const ['packages/flutter/lib'], + excludePaths: const ['packages/flutter/lib/fix_data'], ); final List testRules = [noStopwatches]; final String testRuleNames = testRules.map((AnalyzeRule rule) => '\n * $rule').join(); @@ -196,7 +196,14 @@ Future run(List arguments) async { final List toolRules = [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 [ + '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.'); } diff --git a/dev/bots/custom_rules/analyze.dart b/dev/bots/custom_rules/analyze.dart index 0267d653df..2968f5d732 100644 --- a/dev/bots/custom_rules/analyze.dart +++ b/dev/bots/custom_rules/analyze.dart @@ -64,41 +64,6 @@ Future analyzeWithRules(String flutterRootDirectory, List rul } } -Future analyzeToolWithRules(String flutterRootDirectory, List rules) async { - final String libPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/lib'); - if (!Directory(libPath).existsSync()) { - foundError(['Analyzer error: the specified $libPath does not exist.']); - } - final String testPath = path.canonicalize('$flutterRootDirectory/packages/flutter_tools/test'); - final AnalysisContextCollection collection = AnalysisContextCollection( - includedPaths: [libPath, testPath], - ); - - final List analyzerErrors = []; - for (final AnalysisContext context in collection.contexts) { - final Iterable 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]. ///