Skip to content

Commit 4ef189a

Browse files
srawlinsCommit Queue
authored andcommitted
linter: Rename State to RuleState, and sub-classes
Change-Id: Id74c1a34e0a3154e1720d323bf4002aceb092dd4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429160 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 5d175fa commit 4ef189a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+153
-117
lines changed

pkg/analysis_server/test/shared/shared_code_actions_fixes_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ class _DeprecatedCamelCaseTypes extends LintRule {
881881
_DeprecatedCamelCaseTypes()
882882
: super(
883883
name: 'camel_case_types',
884-
state: State.deprecated(),
884+
state: RuleState.deprecated(),
885885
description: '',
886886
);
887887

pkg/analysis_server/test/src/services/completion/yaml/analysis_options_generator_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ class InternalRule extends LintRule {
313313
);
314314

315315
InternalRule()
316-
: super(name: 'internal_lint', state: State.internal(), description: '');
316+
: super(
317+
name: 'internal_lint',
318+
state: RuleState.internal(),
319+
description: '',
320+
);
317321

318322
@override
319323
DiagnosticCode get diagnosticCode => code;
@@ -323,7 +327,7 @@ class _RemovedLint extends LintRule {
323327
static const LintCode _code = LintCode('removed_lint', 'Removed rule.');
324328

325329
_RemovedLint()
326-
: super(name: 'removed_lint', state: State.removed(), description: '');
330+
: super(name: 'removed_lint', state: RuleState.removed(), description: '');
327331

328332
@override
329333
DiagnosticCode get diagnosticCode => _code;

pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DeprecatedRule extends LintRule {
2727
: super(
2828
name: 'deprecated_rule',
2929
description: '',
30-
state: State.deprecated(since: dart2_12),
30+
state: RuleState.deprecated(since: dart2_12),
3131
);
3232

3333
@override
@@ -42,7 +42,7 @@ class RemovedRule extends LintRule {
4242
);
4343

4444
RemovedRule()
45-
: super(name: 'removed_rule', description: '', state: State.removed());
45+
: super(name: 'removed_rule', description: '', state: RuleState.removed());
4646

4747
@override
4848
DiagnosticCode get diagnosticCode => code;

pkg/analyzer/lib/src/error/ignore_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ class IgnoreValidator {
207207
} else {
208208
var state = rule.state;
209209
var since = state.since.toString();
210-
if (state is DeprecatedState) {
210+
if (state is DeprecatedRuleState) {
211211
// `todo`(pq): implement
212-
} else if (state is RemovedState) {
212+
} else if (state is RemovedRuleState) {
213213
var replacedBy = state.replacedBy;
214214
if (replacedBy != null) {
215215
_errorReporter.atOffset(

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'package:meta/meta.dart';
2121

2222
export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
2323
export 'package:analyzer/src/lint/state.dart'
24-
show dart2_12, dart3, dart3_3, State;
24+
show dart2_12, dart3, dart3_3, RuleState;
2525

2626
/// Describes an [AbstractAnalysisRule] which reports diagnostics using exactly
2727
/// one [DiagnosticCode].
@@ -41,13 +41,14 @@ sealed class AbstractAnalysisRule {
4141
/// Lint name.
4242
final String name;
4343

44-
/// The state of a lint, and optionally since when the state began.
45-
final State state;
44+
/// The state of this analysis rule, optionally indicating the "version" that
45+
/// this state started applying to this rule.
46+
final RuleState state;
4647

4748
AbstractAnalysisRule({
4849
required this.name,
4950
required this.description,
50-
this.state = const State.stable(),
51+
this.state = const RuleState.stable(),
5152
});
5253

5354
/// Indicates whether this analysis rule can work with just the parsed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class LinterRuleOptionsValidator extends OptionsValidator {
3939
.rules
4040
.firstWhereOrNull((rule) => rule.name == value);
4141

42-
bool isDeprecatedInCurrentSdk(DeprecatedState state) =>
42+
bool isDeprecatedInCurrentSdk(DeprecatedRuleState state) =>
4343
currentSdkAllows(state.since);
4444

45-
bool isRemovedInCurrentSdk(State state) {
46-
if (state is! RemovedState) return false;
45+
bool isRemovedInCurrentSdk(RuleState state) {
46+
if (state is! RemovedRuleState) return false;
4747
return currentSdkAllows(state.since);
4848
}
4949

@@ -103,7 +103,7 @@ class LinterRuleOptionsValidator extends OptionsValidator {
103103
// includes).
104104
if (sourceIsOptionsForContextRoot) {
105105
var state = rule.state;
106-
if (state is DeprecatedState && isDeprecatedInCurrentSdk(state)) {
106+
if (state is DeprecatedRuleState && isDeprecatedInCurrentSdk(state)) {
107107
var replacedBy = state.replacedBy;
108108
if (replacedBy != null) {
109109
reporter.atSourceSpan(
@@ -120,7 +120,7 @@ class LinterRuleOptionsValidator extends OptionsValidator {
120120
}
121121
} else if (isRemovedInCurrentSdk(state)) {
122122
var since = state.since.toString();
123-
var replacedBy = (state as RemovedState).replacedBy;
123+
var replacedBy = (state as RemovedRuleState).replacedBy;
124124
if (replacedBy != null) {
125125
reporter.atSourceSpan(
126126
node.span,

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,91 @@ final Version dart3 = Version(3, 0, 0);
1313
/// A version describing Dart language version 3.3.0.
1414
final Version dart3_3 = Version(3, 3, 0);
1515

16-
/// A state that marks a lint as deprecated.
17-
final class DeprecatedState extends State {
18-
/// An optional lint name that replaces the rule with this state.
16+
@Deprecated("Prefer to use 'RuleState'")
17+
typedef State = RuleState;
18+
19+
/// A state that marks an analysis rule as deprecated.
20+
final class DeprecatedRuleState extends RuleState {
21+
/// The optional name of an analysis rule which replaces the rule with this
22+
/// state.
1923
final String? replacedBy;
2024

21-
/// Initialize a newly created deprecated state with given values.
22-
const DeprecatedState._({super.since, this.replacedBy});
25+
const DeprecatedRuleState._({super.since, this.replacedBy});
2326

2427
@override
2528
String get label => 'deprecated';
2629
}
2730

28-
/// A state that marks a lint as experimental.
29-
final class ExperimentalState extends State {
30-
/// Initialize a newly created experimental state with given values.
31-
const ExperimentalState._({super.since});
31+
/// A state that marks an analysis rule as experimental.
32+
final class ExperimentalRuleState extends RuleState {
33+
const ExperimentalRuleState._({super.since});
3234

3335
@override
3436
String get label => 'experimental';
3537
}
3638

37-
/// A state that marks a lint as for internal (Dart SDK) use only.
38-
final class InternalState extends State {
39-
/// Initialize a newly created internal state with given values.
40-
const InternalState._({super.since});
39+
/// A state that marks an analysis rule as for internal (Dart SDK) use only.
40+
final class InternalRuleState extends RuleState {
41+
const InternalRuleState._({super.since});
4142

4243
@override
4344
String get label => 'internal';
4445
}
4546

46-
/// A state that identifies a lint as having been removed.
47-
final class RemovedState extends State {
47+
/// A state that identifies an analysis rule as having been removed.
48+
final class RemovedRuleState extends RuleState {
4849
/// An optional lint name that replaces the rule with this state.
4950
final String? replacedBy;
5051

51-
/// Initialize a newly created removed state with given values.
52-
const RemovedState._({super.since, this.replacedBy});
52+
const RemovedRuleState._({super.since, this.replacedBy});
5353

5454
@override
5555
String get label => 'removed';
5656
}
5757

58-
/// A state that marks a lint as stable.
59-
final class StableState extends State {
60-
/// Initialize a newly created stable state with given values.
61-
const StableState._({super.since});
62-
63-
@override
64-
String get label => 'stable';
65-
}
66-
6758
/// Describes the state of a lint.
68-
sealed class State {
59+
sealed class RuleState {
6960
/// An Optional Dart language version that identifies the start of this state.
7061
final Version? since;
7162

7263
/// Initialize a newly created State object.
73-
const State({this.since});
64+
const RuleState({this.since});
7465

7566
/// Initialize a newly created deprecated state with given values.
76-
const factory State.deprecated({Version? since, String? replacedBy}) =
77-
DeprecatedState._;
67+
const factory RuleState.deprecated({Version? since, String? replacedBy}) =
68+
DeprecatedRuleState._;
7869

7970
/// Initialize a newly created experimental state with given values.
80-
const factory State.experimental({Version? since}) = ExperimentalState._;
71+
const factory RuleState.experimental({Version? since}) =
72+
ExperimentalRuleState._;
8173

8274
/// Initialize a newly created internal state with given values.
83-
const factory State.internal({Version? since}) = InternalState._;
75+
const factory RuleState.internal({Version? since}) = InternalRuleState._;
8476

8577
/// Initialize a newly created removed state with given values.
86-
const factory State.removed({Version? since, String? replacedBy}) =
87-
RemovedState._;
78+
const factory RuleState.removed({Version? since, String? replacedBy}) =
79+
RemovedRuleState._;
8880

8981
/// Initialize a newly created stable state with given values.
90-
const factory State.stable({Version? since}) = StableState._;
82+
const factory RuleState.stable({Version? since}) = StableRuleState._;
9183

9284
/// A short description, suitable for displaying in documentation or a
9385
/// diagnostic message.
9486
String get label;
9587
}
9688

97-
extension StateExtension on State {
98-
bool get isDeprecated => this is DeprecatedState;
99-
bool get isExperimental => this is ExperimentalState;
100-
bool get isInternal => this is InternalState;
101-
bool get isRemoved => this is RemovedState;
102-
bool get isStable => this is StableState;
89+
/// A state that marks an analysis rule as stable.
90+
final class StableRuleState extends RuleState {
91+
const StableRuleState._({super.since});
92+
93+
@override
94+
String get label => 'stable';
95+
}
96+
97+
extension StateExtension on RuleState {
98+
bool get isDeprecated => this is DeprecatedRuleState;
99+
bool get isExperimental => this is ExperimentalRuleState;
100+
bool get isInternal => this is InternalRuleState;
101+
bool get isRemoved => this is RemovedRuleState;
102+
bool get isStable => this is StableRuleState;
103103
}

pkg/analyzer/test/src/diagnostics/removed_lint_use_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RemovedLint extends LintRule {
2020
RemovedLint()
2121
: super(
2222
name: 'removed_lint',
23-
state: State.removed(since: dart3),
23+
state: RuleState.removed(since: dart3),
2424
description: '',
2525
);
2626

pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RemovedLint extends LintRule {
2020
RemovedLint()
2121
: super(
2222
name: 'removed_lint',
23-
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
23+
state: RuleState.removed(since: dart3, replacedBy: 'replacing_lint'),
2424
description: '',
2525
);
2626

@@ -78,7 +78,7 @@ class ReplacingLint extends LintRule {
7878
ReplacingLint()
7979
: super(
8080
name: 'replacing_lint',
81-
state: State.removed(since: dart3),
81+
state: RuleState.removed(since: dart3),
8282
description: '',
8383
);
8484

pkg/analyzer/test/src/options/options_rule_validator_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ main() {
2323
}
2424

2525
class DeprecatedLint extends TestLintRule {
26-
DeprecatedLint() : super(name: 'deprecated_lint', state: State.deprecated());
26+
DeprecatedLint()
27+
: super(name: 'deprecated_lint', state: RuleState.deprecated());
2728
}
2829

2930
class DeprecatedLintWithReplacement extends TestLintRule {
3031
DeprecatedLintWithReplacement()
3132
: super(
3233
name: 'deprecated_lint_with_replacement',
33-
state: State.deprecated(replacedBy: 'replacing_lint'),
34+
state: RuleState.deprecated(replacedBy: 'replacing_lint'),
3435
);
3536
}
3637

3738
class DeprecatedSince3Lint extends TestLintRule {
3839
DeprecatedSince3Lint()
3940
: super(
4041
name: 'deprecated_since_3_lint',
41-
state: State.deprecated(since: dart3),
42+
state: RuleState.deprecated(since: dart3),
4243
);
4344
}
4445

@@ -301,15 +302,15 @@ class RemovedIn2_12Lint extends TestLintRule {
301302
RemovedIn2_12Lint()
302303
: super(
303304
name: 'removed_in_2_12_lint',
304-
state: State.removed(since: dart2_12),
305+
state: RuleState.removed(since: dart2_12),
305306
);
306307
}
307308

308309
class ReplacedLint extends TestLintRule {
309310
ReplacedLint()
310311
: super(
311312
name: 'replaced_lint',
312-
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
313+
state: RuleState.removed(since: dart3, replacedBy: 'replacing_lint'),
313314
);
314315
}
315316

@@ -332,7 +333,7 @@ class RulePos extends TestLintRule {
332333
}
333334

334335
class StableLint extends TestLintRule {
335-
StableLint() : super(name: 'stable_lint', state: State.stable());
336+
StableLint() : super(name: 'stable_lint', state: RuleState.stable());
336337
}
337338

338339
abstract class TestLintRule extends LintRule {

0 commit comments

Comments
 (0)