Skip to content

Commit

Permalink
linter: Allow each LintRule multiple categories
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
srawlins authored and Commit Queue committed Jun 7, 2024
1 parent 63d6e6f commit 6c6b104
Show file tree
Hide file tree
Showing 252 changed files with 274 additions and 297 deletions.
2 changes: 1 addition & 1 deletion pkg/analysis_server/test/lsp/code_actions_fixes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DeprecatedCamelCaseTypes extends LintRule {
DeprecatedCamelCaseTypes()
: super(
name: 'camel_case_types',
group: Group.style,
categories: {Category.style},
state: State.deprecated(),
description: '',
details: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class InternalLint extends LintRule {
InternalLint()
: super(
name: 'internal_lint',
group: Group.style,
categories: {Category.style},
state: State.internal(),
description: '',
details: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DeprecatedRule extends LintRule {
name: 'deprecated_rule',
description: '',
details: '...',
group: Group.errors,
categories: {Category.errors},
state: State.deprecated(since: dart2_12),
);
}
Expand All @@ -32,7 +32,7 @@ class RemovedRule extends LintRule {
name: 'removed_rule',
description: '',
details: '...',
group: Group.errors,
categories: {Category.errors},
state: State.removed());
}

Expand Down
27 changes: 7 additions & 20 deletions pkg/analyzer/lib/src/lint/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,18 @@ export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
export 'package:analyzer/src/lint/state.dart'
show dart2_12, dart3, dart3_3, State;

abstract class Group {
/// A group representing possible coding errors.
final class Category {
/// A category representing possible coding errors.
static const String errors = 'errors';

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

/// A group representing matters of style, largely derived from Effective
/// A category representing matters of style, largely derived from Effective
/// Dart.
static const String style = 'style';
}

@visibleForTesting
class Hyperlink {
final String _label;
final String _href;
final bool _bold;

const Hyperlink(this._label, this._href, {bool bold = false}) : _bold = bold;

String get html => '<a href="$_href">${_emph(_label)}</a>';

String _emph(String msg) => _bold ? '<strong>$msg</strong>' : msg;
}

/// The result of attempting to evaluate an expression.
class LinterConstantEvaluationResult {
/// The value of the expression, or `null` if has [errors].
Expand Down Expand Up @@ -213,8 +200,8 @@ abstract class LintRule {
/// Short description suitable for display in console output.
final String description;

/// Lint group (for example, 'style').
final String group;
/// Lint groups (for example, 'style', 'errors', 'pub').
final Set<String> categories;

/// Lint name.
final String name;
Expand All @@ -233,7 +220,7 @@ abstract class LintRule {

LintRule({
required this.name,
required this.group,
required this.categories,
required this.description,
required this.details,
State? state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RemovedLint extends LintRule {
RemovedLint()
: super(
name: 'removed_lint',
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart3),
description: '',
details: '',
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RemovedLint extends LintRule {
RemovedLint()
: super(
name: 'removed_lint',
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
description: '',
details: '',
Expand Down Expand Up @@ -65,7 +65,7 @@ class ReplacingLint extends LintRule {
ReplacingLint()
: super(
name: 'replacing_lint',
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart3),
description: '',
details: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _AvoidIntRule extends LintRule {
name: 'avoid_int',
description: '',
details: '',
group: Group.errors,
categories: {Category.errors},
);

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/test/src/lint/lint_rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class TestRule extends LintRule {
name: 'test_rule',
description: '',
details: '... tl;dr ...',
group: Group.errors,
categories: {Category.errors},
);
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/test/src/options/apply_options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@ class TestRule extends LintRule {
name: 'fantastic_test_rule',
description: '',
details: '',
group: Group.style,
categories: {Category.style},
);

TestRule.withName(String name)
: super(
name: name,
description: '',
details: '',
group: Group.style,
categories: {Category.style},
);
}
18 changes: 9 additions & 9 deletions pkg/analyzer/test/src/options/options_rule_validator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DeprecatedLint extends LintRule {
DeprecatedLint()
: super(
name: 'deprecated_lint',
group: Group.style,
categories: {Category.style},
state: State.deprecated(),
description: '',
details: '',
Expand All @@ -38,7 +38,7 @@ class DeprecatedLintWithReplacement extends LintRule {
DeprecatedLintWithReplacement()
: super(
name: 'deprecated_lint_with_replacement',
group: Group.style,
categories: {Category.style},
state: State.deprecated(replacedBy: 'replacing_lint'),
description: '',
details: '',
Expand All @@ -49,7 +49,7 @@ class DeprecatedSince3Lint extends LintRule {
DeprecatedSince3Lint()
: super(
name: 'deprecated_since_3_lint',
group: Group.style,
categories: {Category.style},
state: State.deprecated(since: dart3),
description: '',
details: '',
Expand Down Expand Up @@ -293,7 +293,7 @@ class RemovedIn2_12Lint extends LintRule {
RemovedIn2_12Lint()
: super(
name: 'removed_in_2_12_lint',
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart2_12),
description: '',
details: '',
Expand All @@ -304,7 +304,7 @@ class ReplacedLint extends LintRule {
ReplacedLint()
: super(
name: 'replaced_lint',
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart3, replacedBy: 'replacing_lint'),
description: '',
details: '',
Expand All @@ -315,7 +315,7 @@ class ReplacingLint extends LintRule {
ReplacingLint()
: super(
name: 'replacing_lint',
group: Group.style,
categories: {Category.style},
description: '',
details: '',
);
Expand All @@ -325,7 +325,7 @@ class RuleNeg extends LintRule {
RuleNeg()
: super(
name: 'rule_neg',
group: Group.style,
categories: {Category.style},
description: '',
details: '',
);
Expand All @@ -338,7 +338,7 @@ class RulePos extends LintRule {
RulePos()
: super(
name: 'rule_pos',
group: Group.style,
categories: {Category.style},
description: '',
details: '',
);
Expand All @@ -351,7 +351,7 @@ class StableLint extends LintRule {
StableLint()
: super(
name: 'stable_lint',
group: Group.style,
categories: {Category.style},
state: State.stable(),
description: '',
details: '',
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/test/src/task/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,14 @@ class TestRule extends LintRule {
name: 'fantastic_test_rule',
description: '',
details: '',
group: Group.style,
categories: {Category.style},
);

TestRule.withName(String name)
: super(
name: name,
description: '',
details: '',
group: Group.style,
categories: {Category.style},
);
}
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export 'package:analyzer/src/lint/linter.dart'
dart2_12,
dart3,
dart3_3,
Group,
Category,
LintFilter,
LintRule,
LinterContext,
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/always_declare_return_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AlwaysDeclareReturnTypes extends LintRule {
name: 'always_declare_return_types',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AlwaysPutControlBodyOnNewLine extends LintRule {
name: 'always_put_control_body_on_new_line',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AlwaysPutRequiredNamedParametersFirst extends LintRule {
name: 'always_put_required_named_parameters_first',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AlwaysRequireNonNullNamedParameters extends LintRule {
description: _desc,
details: _details,
state: State.removed(since: dart3_3),
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/always_specify_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AlwaysSpecifyTypes extends LintRule {
name: 'always_specify_types',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
List<String> get incompatibleRules =>
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/always_use_package_imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AlwaysUsePackageImports extends LintRule {
name: 'always_use_package_imports',
description: _desc,
details: _details,
group: Group.errors);
categories: {Category.errors});

@override
List<String> get incompatibleRules => const ['prefer_relative_imports'];
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/annotate_overrides.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AnnotateOverrides extends LintRule {
name: 'annotate_overrides',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/annotate_redeclares.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AnnotateRedeclares extends LintRule {
name: 'annotate_redeclares',
description: _desc,
details: _details,
group: Group.style,
categories: {Category.style},
state: State.experimental());

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AvoidAnnotatingWithDynamic extends LintRule {
name: 'avoid_annotating_with_dynamic',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/avoid_as.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AvoidAs extends LintRule {
name: 'avoid_as',
description: _desc,
details: _details,
group: Group.style,
categories: {Category.style},
state: State.removed(since: dart2_12),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AvoidBoolLiteralsInConditionalExpressions extends LintRule {
name: 'avoid_bool_literals_in_conditional_expressions',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AvoidCatchesWithoutOnClauses extends LintRule {
name: 'avoid_catches_without_on_clauses',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/avoid_catching_errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AvoidCatchingErrors extends LintRule {
name: 'avoid_catching_errors',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
List<LintCode> get lintCodes => [classCode, subclassCode];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AvoidClassesWithOnlyStaticMembers extends LintRule {
name: 'avoid_classes_with_only_static_members',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/linter/lib/src/rules/avoid_double_and_int_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AvoidDoubleAndIntChecks extends LintRule {
name: 'avoid_double_and_int_checks',
description: _desc,
details: _details,
group: Group.style);
categories: {Category.style});

@override
LintCode get lintCode => code;
Expand Down
Loading

0 comments on commit 6c6b104

Please sign in to comment.