Skip to content

Commit abd4e77

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
Introduce two subclasses of 'LintRule' for handling multiple lint codes
Before this change, we had an enforcement that either 'get lintCode' or 'get lintCodes' is implemented, but it was a runtime enforcement. And it was a little roundabout. The new system is simpler and more typical: * `AbstractLintRule` is the parent type, and it's sealed. It provides `get lintCodes` as an interface. Code outside of the lint rules requires this getter, in registering codes, etc. * `LintRule` is the new subclass which is the "90% case." It declares a `get lintRule`, and offers simpler reporting methods for reporting a single code everywhere. * `MultiLintRule` is the new subclass which represents that last "10% case." It only declares the reporting methods which all require a LintCode parameter, since there is no concept of a "default lint code among all my lint codes." Work towards #50986 Change-Id: I63cbbfc1d936bb4428aa0b8f5fb0638c9b61b3dc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426284 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 3ef77d1 commit abd4e77

39 files changed

+612
-395
lines changed

pkg/analysis_server_plugin/lib/src/registry.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import 'package:analyzer/src/lint/linter.dart';
1212
import 'package:analyzer/src/lint/registry.dart';
1313

1414
final class PluginRegistryImpl implements PluginRegistry {
15-
/// Returns currently registered lint rules.
16-
Iterable<AnalysisRule> get registeredRules => Registry.ruleRegistry;
15+
/// Returns currently registered rules.
16+
Iterable<AbstractAnalysisRule> get registeredRules => Registry.ruleRegistry;
1717

1818
@override
1919
void registerAssist(ProducerGenerator generator) {
@@ -62,5 +62,5 @@ final class PluginRegistryImpl implements PluginRegistry {
6262
Registry.ruleRegistry.registerWarningRule(rule);
6363
}
6464

65-
AnalysisRule? ruleNamed(String name) => Registry.ruleRegistry[name];
65+
AbstractAnalysisRule? ruleNamed(String name) => Registry.ruleRegistry[name];
6666
}

pkg/analyzer/api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package:analyzer/dart/analysis/analysis_options.dart:
2525
excludePatterns (getter: List<String>)
2626
formatterOptions (getter: FormatterOptions)
2727
lint (getter: bool)
28-
lintRules (getter: List<LintRule>)
28+
lintRules (getter: List<AbstractAnalysisRule>)
2929
pluginConfigurations (getter: List<PluginConfiguration>)
3030
strictCasts (getter: bool)
3131
strictInference (getter: bool)
@@ -4817,7 +4817,7 @@ package:analyzer/src/generated/timestamped_data.dart:
48174817
package:analyzer/src/lint/config.dart:
48184818
RuleConfig (non-public)
48194819
package:analyzer/src/lint/linter.dart:
4820-
LintRule (non-public)
4820+
AbstractAnalysisRule (non-public)
48214821
package:analyzer/src/workspace/workspace.dart:
48224822
Workspace (non-public)
48234823
package:analyzer/utilities/extensions/ast.dart:

pkg/analyzer/lib/dart/analysis/analysis_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class AnalysisOptions {
4545
/// A list of the lint rules that are to be run in an analysis context if
4646
/// [lint] is `true`.
4747
// ignore: analyzer_public_api_bad_type
48-
List<LintRule> get lintRules;
48+
List<AbstractAnalysisRule> get lintRules;
4949

5050
/// The plugin configurations for each plugin which is configured in analysis
5151
/// options.

pkg/analyzer/lib/src/dart/analysis/analysis_options.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class AnalysisOptionsBuilder {
4343

4444
bool lint = false;
4545

46-
List<LintRule> lintRules = [];
46+
List<AbstractAnalysisRule> lintRules = [];
4747

4848
bool propagateLinterExceptions = false;
4949

@@ -378,7 +378,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
378378
bool warning = true;
379379

380380
@override
381-
List<LintRule> lintRules = [];
381+
List<AbstractAnalysisRule> lintRules = [];
382382

383383
/// Whether linter exceptions should be propagated to the caller (by
384384
/// rethrowing them).

pkg/analyzer/lib/src/lint/analysis_rule_timers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class AnalysisRuleTimers {
1414

1515
/// Get a timer associated with the given analysis rule (or create one if none
1616
/// exists).
17-
Stopwatch getTimer(AnalysisRule linter) =>
17+
Stopwatch getTimer(AbstractAnalysisRule linter) =>
1818
timers.putIfAbsent(linter.name, () => Stopwatch());
1919
}

0 commit comments

Comments
 (0)