Skip to content

Commit 6c6b104

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
linter: Allow each LintRule multiple categories
Spelled out at https://github.com/dart-lang/linter/issues/1020 Fixes https://github.com/dart-lang/linter/issues/1020 This CL does not change the categories/groups that any rule has. We can add/change categories in later CLs. Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: Ief2856a6c472492bbad19fc95df172ef8d19fe7b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369861 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Sam Rawlins <[email protected]>
1 parent 63d6e6f commit 6c6b104

File tree

252 files changed

+274
-297
lines changed

Some content is hidden

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

252 files changed

+274
-297
lines changed

pkg/analysis_server/test/lsp/code_actions_fixes_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DeprecatedCamelCaseTypes extends LintRule {
2727
DeprecatedCamelCaseTypes()
2828
: super(
2929
name: 'camel_case_types',
30-
group: Group.style,
30+
categories: {Category.style},
3131
state: State.deprecated(),
3232
description: '',
3333
details: '',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class InternalLint extends LintRule {
259259
InternalLint()
260260
: super(
261261
name: 'internal_lint',
262-
group: Group.style,
262+
categories: {Category.style},
263263
state: State.internal(),
264264
description: '',
265265
details: '',

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
@@ -21,7 +21,7 @@ class DeprecatedRule extends LintRule {
2121
name: 'deprecated_rule',
2222
description: '',
2323
details: '...',
24-
group: Group.errors,
24+
categories: {Category.errors},
2525
state: State.deprecated(since: dart2_12),
2626
);
2727
}
@@ -32,7 +32,7 @@ class RemovedRule extends LintRule {
3232
name: 'removed_rule',
3333
description: '',
3434
details: '...',
35-
group: Group.errors,
35+
categories: {Category.errors},
3636
state: State.removed());
3737
}
3838

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,18 @@ export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
3535
export 'package:analyzer/src/lint/state.dart'
3636
show dart2_12, dart3, dart3_3, State;
3737

38-
abstract class Group {
39-
/// A group representing possible coding errors.
38+
final class Category {
39+
/// A category representing possible coding errors.
4040
static const String errors = 'errors';
4141

42-
/// A group representing Pub-related rules.
42+
/// A category representing Pub-related rules.
4343
static const String pub = 'pub';
4444

45-
/// A group representing matters of style, largely derived from Effective
45+
/// A category representing matters of style, largely derived from Effective
4646
/// Dart.
4747
static const String style = 'style';
4848
}
4949

50-
@visibleForTesting
51-
class Hyperlink {
52-
final String _label;
53-
final String _href;
54-
final bool _bold;
55-
56-
const Hyperlink(this._label, this._href, {bool bold = false}) : _bold = bold;
57-
58-
String get html => '<a href="$_href">${_emph(_label)}</a>';
59-
60-
String _emph(String msg) => _bold ? '<strong>$msg</strong>' : msg;
61-
}
62-
6350
/// The result of attempting to evaluate an expression.
6451
class LinterConstantEvaluationResult {
6552
/// The value of the expression, or `null` if has [errors].
@@ -213,8 +200,8 @@ abstract class LintRule {
213200
/// Short description suitable for display in console output.
214201
final String description;
215202

216-
/// Lint group (for example, 'style').
217-
final String group;
203+
/// Lint groups (for example, 'style', 'errors', 'pub').
204+
final Set<String> categories;
218205

219206
/// Lint name.
220207
final String name;
@@ -233,7 +220,7 @@ abstract class LintRule {
233220

234221
LintRule({
235222
required this.name,
236-
required this.group,
223+
required this.categories,
237224
required this.description,
238225
required this.details,
239226
State? state,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RemovedLint extends LintRule {
1919
RemovedLint()
2020
: super(
2121
name: 'removed_lint',
22-
group: Group.style,
22+
categories: {Category.style},
2323
state: State.removed(since: dart3),
2424
description: '',
2525
details: '',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RemovedLint extends LintRule {
1919
RemovedLint()
2020
: super(
2121
name: 'removed_lint',
22-
group: Group.style,
22+
categories: {Category.style},
2323
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
2424
description: '',
2525
details: '',
@@ -65,7 +65,7 @@ class ReplacingLint extends LintRule {
6565
ReplacingLint()
6666
: super(
6767
name: 'replacing_lint',
68-
group: Group.style,
68+
categories: {Category.style},
6969
state: State.removed(since: dart3),
7070
description: '',
7171
details: '',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _AvoidIntRule extends LintRule {
7777
name: 'avoid_int',
7878
description: '',
7979
details: '',
80-
group: Group.errors,
80+
categories: {Category.errors},
8181
);
8282

8383
@override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class TestRule extends LintRule {
139139
name: 'test_rule',
140140
description: '',
141141
details: '... tl;dr ...',
142-
group: Group.errors,
142+
categories: {Category.errors},
143143
);
144144
}
145145

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,14 @@ class TestRule extends LintRule {
375375
name: 'fantastic_test_rule',
376376
description: '',
377377
details: '',
378-
group: Group.style,
378+
categories: {Category.style},
379379
);
380380

381381
TestRule.withName(String name)
382382
: super(
383383
name: name,
384384
description: '',
385385
details: '',
386-
group: Group.style,
386+
categories: {Category.style},
387387
);
388388
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DeprecatedLint extends LintRule {
2727
DeprecatedLint()
2828
: super(
2929
name: 'deprecated_lint',
30-
group: Group.style,
30+
categories: {Category.style},
3131
state: State.deprecated(),
3232
description: '',
3333
details: '',
@@ -38,7 +38,7 @@ class DeprecatedLintWithReplacement extends LintRule {
3838
DeprecatedLintWithReplacement()
3939
: super(
4040
name: 'deprecated_lint_with_replacement',
41-
group: Group.style,
41+
categories: {Category.style},
4242
state: State.deprecated(replacedBy: 'replacing_lint'),
4343
description: '',
4444
details: '',
@@ -49,7 +49,7 @@ class DeprecatedSince3Lint extends LintRule {
4949
DeprecatedSince3Lint()
5050
: super(
5151
name: 'deprecated_since_3_lint',
52-
group: Group.style,
52+
categories: {Category.style},
5353
state: State.deprecated(since: dart3),
5454
description: '',
5555
details: '',
@@ -293,7 +293,7 @@ class RemovedIn2_12Lint extends LintRule {
293293
RemovedIn2_12Lint()
294294
: super(
295295
name: 'removed_in_2_12_lint',
296-
group: Group.style,
296+
categories: {Category.style},
297297
state: State.removed(since: dart2_12),
298298
description: '',
299299
details: '',
@@ -304,7 +304,7 @@ class ReplacedLint extends LintRule {
304304
ReplacedLint()
305305
: super(
306306
name: 'replaced_lint',
307-
group: Group.style,
307+
categories: {Category.style},
308308
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
309309
description: '',
310310
details: '',
@@ -315,7 +315,7 @@ class ReplacingLint extends LintRule {
315315
ReplacingLint()
316316
: super(
317317
name: 'replacing_lint',
318-
group: Group.style,
318+
categories: {Category.style},
319319
description: '',
320320
details: '',
321321
);
@@ -325,7 +325,7 @@ class RuleNeg extends LintRule {
325325
RuleNeg()
326326
: super(
327327
name: 'rule_neg',
328-
group: Group.style,
328+
categories: {Category.style},
329329
description: '',
330330
details: '',
331331
);
@@ -338,7 +338,7 @@ class RulePos extends LintRule {
338338
RulePos()
339339
: super(
340340
name: 'rule_pos',
341-
group: Group.style,
341+
categories: {Category.style},
342342
description: '',
343343
details: '',
344344
);
@@ -351,7 +351,7 @@ class StableLint extends LintRule {
351351
StableLint()
352352
: super(
353353
name: 'stable_lint',
354-
group: Group.style,
354+
categories: {Category.style},
355355
state: State.stable(),
356356
description: '',
357357
details: '',

pkg/analyzer/test/src/task/options_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,14 @@ class TestRule extends LintRule {
575575
name: 'fantastic_test_rule',
576576
description: '',
577577
details: '',
578-
group: Group.style,
578+
categories: {Category.style},
579579
);
580580

581581
TestRule.withName(String name)
582582
: super(
583583
name: name,
584584
description: '',
585585
details: '',
586-
group: Group.style,
586+
categories: {Category.style},
587587
);
588588
}

pkg/linter/lib/src/analyzer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export 'package:analyzer/src/lint/linter.dart'
2222
dart2_12,
2323
dart3,
2424
dart3_3,
25-
Group,
25+
Category,
2626
LintFilter,
2727
LintRule,
2828
LinterContext,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AlwaysDeclareReturnTypes extends LintRule {
5555
name: 'always_declare_return_types',
5656
description: _desc,
5757
details: _details,
58-
group: Group.style);
58+
categories: {Category.style});
5959

6060
@override
6161
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AlwaysPutControlBodyOnNewLine extends LintRule {
5959
name: 'always_put_control_body_on_new_line',
6060
description: _desc,
6161
details: _details,
62-
group: Group.style);
62+
categories: {Category.style});
6363

6464
@override
6565
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AlwaysPutRequiredNamedParametersFirst extends LintRule {
4747
name: 'always_put_required_named_parameters_first',
4848
description: _desc,
4949
details: _details,
50-
group: Group.style);
50+
categories: {Category.style});
5151

5252
@override
5353
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AlwaysRequireNonNullNamedParameters extends LintRule {
4848
description: _desc,
4949
details: _details,
5050
state: State.removed(since: dart3_3),
51-
group: Group.style);
51+
categories: {Category.style});
5252

5353
@override
5454
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class AlwaysSpecifyTypes extends LintRule {
7070
name: 'always_specify_types',
7171
description: _desc,
7272
details: _details,
73-
group: Group.style);
73+
categories: {Category.style});
7474

7575
@override
7676
List<String> get incompatibleRules =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AlwaysUsePackageImports extends LintRule {
5555
name: 'always_use_package_imports',
5656
description: _desc,
5757
details: _details,
58-
group: Group.errors);
58+
categories: {Category.errors});
5959

6060
@override
6161
List<String> get incompatibleRules => const ['prefer_relative_imports'];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AnnotateOverrides extends LintRule {
5858
name: 'annotate_overrides',
5959
description: _desc,
6060
details: _details,
61-
group: Group.style);
61+
categories: {Category.style});
6262

6363
@override
6464
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AnnotateRedeclares extends LintRule {
5757
name: 'annotate_redeclares',
5858
description: _desc,
5959
details: _details,
60-
group: Group.style,
60+
categories: {Category.style},
6161
state: State.experimental());
6262

6363
@override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AvoidAnnotatingWithDynamic extends LintRule {
4747
name: 'avoid_annotating_with_dynamic',
4848
description: _desc,
4949
details: _details,
50-
group: Group.style);
50+
categories: {Category.style});
5151

5252
@override
5353
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class AvoidAs extends LintRule {
5252
name: 'avoid_as',
5353
description: _desc,
5454
details: _details,
55-
group: Group.style,
55+
categories: {Category.style},
5656
state: State.removed(since: dart2_12),
5757
);
5858

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AvoidBoolLiteralsInConditionalExpressions extends LintRule {
4242
name: 'avoid_bool_literals_in_conditional_expressions',
4343
description: _desc,
4444
details: _details,
45-
group: Group.style);
45+
categories: {Category.style});
4646

4747
@override
4848
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AvoidCatchesWithoutOnClauses extends LintRule {
6363
name: 'avoid_catches_without_on_clauses',
6464
description: _desc,
6565
details: _details,
66-
group: Group.style);
66+
categories: {Category.style});
6767

6868
@override
6969
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AvoidCatchingErrors extends LintRule {
5050
name: 'avoid_catching_errors',
5151
description: _desc,
5252
details: _details,
53-
group: Group.style);
53+
categories: {Category.style});
5454

5555
@override
5656
List<LintCode> get lintCodes => [classCode, subclassCode];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class AvoidClassesWithOnlyStaticMembers extends LintRule {
5656
name: 'avoid_classes_with_only_static_members',
5757
description: _desc,
5858
details: _details,
59-
group: Group.style);
59+
categories: {Category.style});
6060

6161
@override
6262
LintCode get lintCode => code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AvoidDoubleAndIntChecks extends LintRule {
5151
name: 'avoid_double_and_int_checks',
5252
description: _desc,
5353
details: _details,
54-
group: Group.style);
54+
categories: {Category.style});
5555

5656
@override
5757
LintCode get lintCode => code;

0 commit comments

Comments
 (0)