Skip to content

Commit a3b1b4f

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Deprecate AbstractAnalysisRule.lintCodes
Work towards #50986 Change-Id: I4c86dbf806964c98f4a1c5854eb53c6c8cfe002b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428624 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 49e7d4a commit a3b1b4f

27 files changed

+75
-54
lines changed

pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ String? verifyErrorFixStatus() {
5252
registerLintRules();
5353
registerBuiltInFixGenerators();
5454
var lintRuleCodes = {
55-
for (var rule in Registry.ruleRegistry.rules) ...rule.lintCodes,
55+
for (var rule in Registry.ruleRegistry.rules) ...rule.diagnosticCodes,
5656
};
5757
var lintRuleNames = {for (var lintCode in lintRuleCodes) lintCode.uniqueName};
5858

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class PluginServer {
364364
// `benchhmark.dart` script does.
365365
rule.registerNodeProcessors(nodeRegistry, context);
366366
}
367-
for (var code in rules.expand((r) => r.lintCodes)) {
367+
for (var code in rules.expand((r) => r.diagnosticCodes)) {
368368
var existingPlugin = pluginCodeMapping[code.name];
369369
if (existingPlugin == null) {
370370
pluginCodeMapping[code.name] = configuration.name;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ sealed class AbstractAnalysisRule {
5555
bool get canUseParsedResult => false;
5656

5757
/// The diagnostic codes associated with this analysis rule.
58-
List<DiagnosticCode> get diagnosticCodes => lintCodes;
58+
List<DiagnosticCode> get diagnosticCodes;
5959

6060
/// A list of incompatible rule ids.
6161
List<String> get incompatibleRules => const [];
6262

6363
/// The lint codes associated with this analysis rule.
64-
// TODO(srawlins): Deprecate this in favor of `diagnosticCodes`.
65-
List<LintCode> get lintCodes;
64+
@Deprecated("Use 'diagnosticCodes' instead.")
65+
List<DiagnosticCode> get lintCodes => diagnosticCodes;
6666

6767
/// Returns a visitor that visits a [Pubspec] to perform analysis.
6868
///
@@ -164,13 +164,13 @@ abstract class AnalysisRule extends AbstractAnalysisRule {
164164
/// The code to report for a violation.
165165
DiagnosticCode get diagnosticCode => lintCode;
166166

167+
@override
168+
List<DiagnosticCode> get diagnosticCodes => [lintCode];
169+
167170
/// The code to report for a violation.
168171
// TODO(srawlins): Deprecate this in favor of `diagnosticCode`.
169172
LintCode get lintCode;
170173

171-
@override
172-
List<LintCode> get lintCodes => [lintCode];
173-
174174
/// Reports a diagnostic at [node] with message [arguments] and
175175
/// [contextMessages].
176176
void reportAtNode(

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,32 @@ class Registry with IterableMixin<AbstractAnalysisRule> {
6868
/// Adds the given lint [rule] to this registry.
6969
void registerLintRule(AbstractAnalysisRule rule) {
7070
_lintRules[rule.name] = rule;
71-
for (var lintCode in rule.lintCodes) {
72-
_codeMap[lintCode.uniqueName] = lintCode;
71+
for (var code in rule.diagnosticCodes) {
72+
_codeMap[code.uniqueName] = code as LintCode;
7373
}
7474
}
7575

7676
/// Adds the given warning [rule] to this registry.
7777
void registerWarningRule(AbstractAnalysisRule rule) {
7878
_warningRules[rule.name] = rule;
79-
for (var lintCode in rule.lintCodes) {
80-
_codeMap[lintCode.uniqueName] = lintCode;
79+
for (var code in rule.diagnosticCodes) {
80+
_codeMap[code.uniqueName] = code as LintCode;
8181
}
8282
}
8383

8484
/// Removes the given lint [rule] from this registry.
8585
void unregisterLintRule(AbstractAnalysisRule rule) {
8686
_lintRules.remove(rule.name);
87-
for (var lintCode in rule.lintCodes) {
88-
_codeMap.remove(lintCode.uniqueName);
87+
for (var code in rule.diagnosticCodes) {
88+
_codeMap.remove(code.uniqueName);
8989
}
9090
}
9191

9292
/// Removes the given warning [rule] from this registry.
9393
void unregisterWarningRule(AbstractAnalysisRule rule) {
9494
_warningRules.remove(rule.name);
95-
for (var lintCode in rule.lintCodes) {
96-
_codeMap.remove(lintCode.uniqueName);
95+
for (var code in rule.diagnosticCodes) {
96+
_codeMap.remove(code.uniqueName);
9797
}
9898
}
9999
}

pkg/analyzer/test/src/lint/lint_rule_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class TestRule extends MultiAnalysisRule {
133133
TestRule() : super(name: 'test_rule', description: '');
134134

135135
@override
136-
List<LintCode> get lintCodes => [code, customCode];
136+
List<DiagnosticCode> get diagnosticCodes => [code, customCode];
137137
}
138138

139139
class _MockSource implements Source {

pkg/linter/lib/src/rules/always_declare_return_types.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/ast/visitor.dart';
8+
import 'package:analyzer/error/error.dart';
89

910
import '../analyzer.dart';
1011
import '../extensions.dart';
@@ -16,7 +17,7 @@ class AlwaysDeclareReturnTypes extends MultiAnalysisRule {
1617
: super(name: LintNames.always_declare_return_types, description: _desc);
1718

1819
@override
19-
List<LintCode> get lintCodes => [
20+
List<DiagnosticCode> get diagnosticCodes => [
2021
LinterLintCode.always_declare_return_types_of_functions,
2122
LinterLintCode.always_declare_return_types_of_methods,
2223
];

pkg/linter/lib/src/rules/always_specify_types.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class AlwaysSpecifyTypes extends MultiAnalysisRule {
1818
AlwaysSpecifyTypes()
1919
: super(name: LintNames.always_specify_types, description: _desc);
2020

21+
@override
22+
List<DiagnosticCode> get diagnosticCodes => [
23+
LinterLintCode.always_specify_types_add_type,
24+
LinterLintCode.always_specify_types_replace_keyword,
25+
LinterLintCode.always_specify_types_specify_type,
26+
LinterLintCode.always_specify_types_split_to_types,
27+
];
28+
2129
@override
2230
List<String> get incompatibleRules => const [
2331
LintNames.avoid_types_on_closure_parameters,
@@ -26,14 +34,6 @@ class AlwaysSpecifyTypes extends MultiAnalysisRule {
2634
LintNames.omit_obvious_property_types,
2735
];
2836

29-
@override
30-
List<LintCode> get lintCodes => [
31-
LinterLintCode.always_specify_types_add_type,
32-
LinterLintCode.always_specify_types_replace_keyword,
33-
LinterLintCode.always_specify_types_specify_type,
34-
LinterLintCode.always_specify_types_split_to_types,
35-
];
36-
3737
@override
3838
void registerNodeProcessors(
3939
NodeLintRegistry registry,

pkg/linter/lib/src/rules/analyzer_public_api.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
77
import 'package:analyzer/dart/constant/value.dart';
88
import 'package:analyzer/dart/element/element.dart';
99
import 'package:analyzer/dart/element/type.dart';
10+
import 'package:analyzer/error/error.dart';
1011

1112
import '../analyzer.dart';
1213

@@ -89,7 +90,7 @@ class AnalyzerPublicApi extends MultiAnalysisRule {
8990
: super(name: ruleName, description: _desc, state: const State.internal());
9091

9192
@override
92-
List<LintCode> get lintCodes => [
93+
List<DiagnosticCode> get diagnosticCodes => [
9394
badPartDirective,
9495
badType,
9596
exportsNonPublicName,

pkg/linter/lib/src/rules/avoid_catching_errors.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7+
import 'package:analyzer/error/error.dart';
78

89
import '../analyzer.dart';
910
import '../extensions.dart';
@@ -15,7 +16,7 @@ class AvoidCatchingErrors extends MultiAnalysisRule {
1516
: super(name: LintNames.avoid_catching_errors, description: _desc);
1617

1718
@override
18-
List<LintCode> get lintCodes => [
19+
List<DiagnosticCode> get diagnosticCodes => [
1920
LinterLintCode.avoid_catching_errors_class,
2021
LinterLintCode.avoid_catching_errors_subclass,
2122
];

pkg/linter/lib/src/rules/avoid_returning_null_for_void.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
77
import 'package:analyzer/dart/element/type.dart';
8+
import 'package:analyzer/error/error.dart';
89

910
import '../analyzer.dart';
1011

@@ -15,7 +16,7 @@ class AvoidReturningNullForVoid extends MultiAnalysisRule {
1516
: super(name: LintNames.avoid_returning_null_for_void, description: _desc);
1617

1718
@override
18-
List<LintCode> get lintCodes => [
19+
List<DiagnosticCode> get diagnosticCodes => [
1920
LinterLintCode.avoid_returning_null_for_void_from_function,
2021
LinterLintCode.avoid_returning_null_for_void_from_method,
2122
];

0 commit comments

Comments
 (0)