Skip to content

Commit a75691f

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
linter: Remove unused fields in Group
Well, to be honest, remove all instances of Group. Instead, "groups" are Strings. Because there was only one field left, a Group is just a... name of a group. Also, LintRule is no longer Comparable because that does not seem to have served a purpose... Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I6e058139631dc1b06a4072a2549f156d1622c673 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369782 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 0b6aff7 commit a75691f

File tree

3 files changed

+11
-79
lines changed

3 files changed

+11
-79
lines changed

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

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,16 @@ 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-
class Group implements Comparable<Group> {
39-
/// Defined rule groups.
40-
static const Group errors =
41-
Group._('errors', description: 'Possible coding errors.');
42-
static const Group pub = Group._('pub',
43-
description: 'Pub-related rules.',
44-
link: Hyperlink('See the <strong>Pubspec Format</strong>',
45-
'https://dart.dev/tools/pub/pubspec'));
46-
static const Group style = Group._('style',
47-
description:
48-
'Matters of style, largely derived from the official Dart Style Guide.',
49-
link: Hyperlink('See the <strong>Style Guide</strong>',
50-
'https://dart.dev/guides/language/effective-dart/style'));
51-
52-
/// List of builtin groups in presentation order.
53-
@visibleForTesting
54-
static const Iterable<Group> builtin = [errors, style, pub];
38+
abstract class Group {
39+
/// A group representing possible coding errors.
40+
static const String errors = 'errors';
5541

56-
final String name;
57-
58-
@visibleForTesting
59-
final bool custom;
60-
61-
final String description;
62-
63-
final Hyperlink? link;
64-
65-
factory Group(String name, {String description = '', Hyperlink? link}) {
66-
var n = name.toLowerCase();
67-
return builtin.firstWhere((g) => g.name == n,
68-
orElse: () =>
69-
Group._(name, custom: true, description: description, link: link));
70-
}
42+
/// A group representing Pub-related rules.
43+
static const String pub = 'pub';
7144

72-
const Group._(this.name,
73-
{this.custom = false, required this.description, this.link});
74-
75-
@override
76-
int compareTo(Group other) => name.compareTo(other.name);
45+
/// A group representing matters of style, largely derived from Effective
46+
/// Dart.
47+
static const String style = 'style';
7748
}
7849

7950
@visibleForTesting
@@ -229,7 +200,7 @@ abstract class LintFilter {
229200
}
230201

231202
/// Describes a lint rule.
232-
abstract class LintRule implements Comparable<LintRule> {
203+
abstract class LintRule {
233204
/// Used to report lint warnings.
234205
/// NOTE: this is set by the framework before any node processors start
235206
/// visiting nodes.
@@ -243,7 +214,7 @@ abstract class LintRule implements Comparable<LintRule> {
243214
final String description;
244215

245216
/// Lint group (for example, 'style').
246-
final Group group;
217+
final String group;
247218

248219
/// Lint name.
249220
final String name;
@@ -294,15 +265,6 @@ abstract class LintRule implements Comparable<LintRule> {
294265

295266
set reporter(ErrorReporter value) => _reporter = value;
296267

297-
@override
298-
int compareTo(LintRule other) {
299-
var g = group.compareTo(other.group);
300-
if (g != 0) {
301-
return g;
302-
}
303-
return name.compareTo(other.name);
304-
}
305-
306268
/// Return a visitor to be passed to pubspecs to perform lint
307269
/// analysis.
308270
/// Lint errors are reported via this [Linter]'s error [reporter].

pkg/linter/test/engine_test.dart

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ void defineLinterEngineTests() {
3636
});
3737
});
3838

39-
group('groups', () {
40-
test('factory', () {
41-
expect(Group('style').custom, isFalse);
42-
expect(Group('pub').custom, isFalse);
43-
expect(Group('errors').custom, isFalse);
44-
expect(Group('Kustom').custom, isTrue);
45-
});
46-
test('builtins', () {
47-
expect(Group.builtin.contains(Group.style), isTrue);
48-
expect(Group.builtin.contains(Group.errors), isTrue);
49-
expect(Group.builtin.contains(Group.pub), isTrue);
50-
});
51-
});
52-
5339
group('lint driver', () {
5440
test('pubspec', () {
5541
var visited = false;
@@ -82,17 +68,6 @@ void defineLinterEngineTests() {
8268
link.html, '<a href="http://dart.dev"><strong>dart</strong></a>');
8369
});
8470
});
85-
86-
group('rule', () {
87-
test('comparing', () {
88-
LintRule r1 = MockLintRule('Bar', Group('acme'));
89-
LintRule r2 = MockLintRule('Foo', Group('acme'));
90-
expect(r1.compareTo(r2), -1);
91-
LintRule r3 = MockLintRule('Bar', Group('acme'));
92-
LintRule r4 = MockLintRule('Bar', Group('woody'));
93-
expect(r3.compareTo(r4), -1);
94-
});
95-
});
9671
});
9772
});
9873
}
@@ -112,11 +87,6 @@ class MockLinter extends LintRule {
11287
PubspecVisitor getPubspecVisitor() => MockPubspecVisitor(nodeVisitor);
11388
}
11489

115-
class MockLintRule extends LintRule {
116-
MockLintRule(String name, Group group)
117-
: super(name: name, group: group, description: '', details: '');
118-
}
119-
12090
class MockPubspecVisitor extends PubspecVisitor {
12191
final NodeVisitor? nodeVisitor;
12292

pkg/linter/tool/machine.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Future<String> getMachineListing(
7272
{
7373
'name': rule.name,
7474
'description': rule.description,
75-
'group': rule.group.name,
75+
'group': rule.group,
7676
'state': rule.state.label,
7777
'incompatible': rule.incompatibleRules,
7878
'sets': [

0 commit comments

Comments
 (0)