Skip to content

Commit 349e626

Browse files
pqCommit Queue
authored and
Commit Queue
committed
verify linter source sorting
Fixes: https://github.com/dart-lang/linter/issues/2368 Change-Id: I498e271dc32348115a34472b44688be8de2169a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323901 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 84f65be commit 349e626

Some content is hidden

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

43 files changed

+677
-668
lines changed

pkg/analysis_server/test/verify_sorted_test.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ void main() {
2828
buildTestsForAnalyzerPlugin();
2929
});
3030

31+
group('linter', () {
32+
buildTestsForLinter();
33+
});
34+
3135
group('nnbd_migration', () {
3236
buildTestsForNnbdMigration();
3337
});
@@ -50,13 +54,10 @@ void buildTests({
5054
excludedPaths: excludedPaths,
5155
resourceProvider: provider,
5256
);
53-
var contexts = collection.contexts;
54-
if (contexts.length != 1) {
55-
fail('The directory $packagePath contains multiple analysis contexts.');
57+
for (var context in collection.contexts) {
58+
buildTestsIn(context.currentSession, packagePath, excludedPaths,
59+
provider.getFolder(packagePath));
5660
}
57-
58-
buildTestsIn(contexts[0].currentSession, packagePath, excludedPaths,
59-
provider.getFolder(packagePath));
6061
}
6162

6263
void buildTestsForAnalysisServer() {
@@ -120,6 +121,12 @@ void buildTestsForAnalyzerPlugin() {
120121
);
121122
}
122123

124+
void buildTestsForLinter() {
125+
buildTests(packagePath: 'linter', excludedPaths: [
126+
'test_data',
127+
]);
128+
}
129+
123130
void buildTestsForNnbdMigration() {
124131
buildTests(
125132
packagePath: 'nnbd_migration',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ class AvoidEmptyElse extends LintRule {
2828
correctionMessage:
2929
'Try removing the empty statement or removing the else clause.');
3030

31-
@override
32-
LintCode get lintCode => code;
33-
3431
AvoidEmptyElse()
3532
: super(
3633
name: 'avoid_empty_else',
3734
description: _desc,
3835
details: _details,
3936
group: Group.errors);
4037

38+
@override
39+
LintCode get lintCode => code;
40+
4141
@override
4242
void registerNodeProcessors(
4343
NodeLintRegistry registry, LinterContext context) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class _Visitor extends SimpleAstVisitor<void> {
9393
}
9494
}
9595

96+
@override
97+
void visitGenericFunctionType(GenericFunctionType node) {
98+
checkParams(node.parameters.parameters);
99+
}
100+
96101
@override
97102
void visitMethodDeclaration(MethodDeclaration node) {
98103
var declaredElement = node.declaredElement;
@@ -106,11 +111,6 @@ class _Visitor extends SimpleAstVisitor<void> {
106111
}
107112
}
108113

109-
@override
110-
void visitGenericFunctionType(GenericFunctionType node) {
111-
checkParams(node.parameters.parameters);
112-
}
113-
114114
bool _isOverridingMember(Element member) {
115115
var classElement = member.thisOrAncestorOfType<ClassElement>();
116116
if (classElement == null) return false;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ class AvoidRelativeLibImports extends LintRule {
4747
"Try fixing the relative path or changing the import to a 'package:' "
4848
'import.');
4949

50-
@override
51-
LintCode get lintCode => code;
52-
5350
AvoidRelativeLibImports()
5451
: super(
5552
name: 'avoid_relative_lib_imports',
5653
description: _desc,
5754
details: _details,
5855
group: Group.errors);
5956

57+
@override
58+
LintCode get lintCode => code;
59+
6060
@override
6161
void registerNodeProcessors(
6262
NodeLintRegistry registry, LinterContext context) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ set speed(int ms);
2727
''';
2828

2929
class AvoidReturnTypesOnSetters extends LintRule {
30-
@override
31-
bool get canUseParsedResult => true;
32-
3330
static const LintCode code = LintCode(
3431
'avoid_return_types_on_setters', 'Unnecessary return type on a setter.',
3532
correctionMessage: 'Try removing the return type.');
@@ -41,6 +38,9 @@ class AvoidReturnTypesOnSetters extends LintRule {
4138
details: _details,
4239
group: Group.style);
4340

41+
@override
42+
bool get canUseParsedResult => true;
43+
4444
@override
4545
LintCode get lintCode => code;
4646

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ class CollectionMethodsUnrelatedType extends LintRule {
8888
class _Visitor extends UnrelatedTypesProcessors {
8989
_Visitor(super.rule, super.typeSystem, super.typeProvider);
9090

91+
@override
92+
List<MethodDefinition> get indexOperators => [
93+
// Argument to `Map<K, V>.[]` should be assignable to `K`.
94+
MethodDefinitionForElement(
95+
typeProvider.mapElement,
96+
'[]',
97+
ExpectedArgumentKind.assignableToCollectionTypeArgument,
98+
),
99+
];
100+
91101
@override
92102
List<MethodDefinition> get methods => [
93103
// Argument to `Iterable<E>.contains` should be assignable to `E`.
@@ -141,14 +151,4 @@ class _Visitor extends UnrelatedTypesProcessors {
141151
ExpectedArgumentKind.assignableToCollectionTypeArgument,
142152
),
143153
];
144-
145-
@override
146-
List<MethodDefinition> get indexOperators => [
147-
// Argument to `Map<K, V>.[]` should be assignable to `K`.
148-
MethodDefinitionForElement(
149-
typeProvider.mapElement,
150-
'[]',
151-
ExpectedArgumentKind.assignableToCollectionTypeArgument,
152-
),
153-
];
154154
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ if (overflowChars != other.overflowChars) {
5151
''';
5252

5353
class CurlyBracesInFlowControlStructures extends LintRule {
54-
@override
55-
bool get canUseParsedResult => true;
56-
5754
static const LintCode code = LintCode(
5855
'curly_braces_in_flow_control_structures',
5956
'Statements in {0} should be enclosed in a block.',
@@ -66,6 +63,9 @@ class CurlyBracesInFlowControlStructures extends LintRule {
6663
details: _details,
6764
group: Group.style);
6865

66+
@override
67+
bool get canUseParsedResult => true;
68+
6969
@override
7070
LintCode get lintCode => code;
7171

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class LibraryAnnotations extends LintRule {
6868
class _Visitor extends SimpleAstVisitor<void> {
6969
final LibraryAnnotations rule;
7070

71-
_Visitor(this.rule);
72-
7371
Directive? firstDirective;
7472

73+
_Visitor(this.rule);
74+
7575
@override
7676
void visitCompilationUnit(CompilationUnit node) {
7777
if (node.directives.isNotEmpty) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class _Visitor extends SimpleAstVisitor<void> {
6161

6262
_Visitor(this.rule, this.context);
6363

64+
bool isBool(DartType? type) =>
65+
type != null &&
66+
type.isDartCoreBool &&
67+
context.typeSystem.isNonNullable(type);
68+
6469
@override
6570
void visitBinaryExpression(BinaryExpression node) {
6671
if (node.operator.type == TokenType.EQ_EQ ||
@@ -74,9 +79,4 @@ class _Visitor extends SimpleAstVisitor<void> {
7479
}
7580
}
7681
}
77-
78-
bool isBool(DartType? type) =>
79-
type != null &&
80-
type.isDartCoreBool &&
81-
context.typeSystem.isNonNullable(type);
8282
}

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

Lines changed: 1 addition & 0 deletions
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+
89
import '../analyzer.dart';
910

1011
const _desc = r"Don't assign a variable to itself.";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ typedef F = void Function();
3333
''';
3434

3535
class PreferGenericFunctionTypeAliases extends LintRule {
36-
@override
37-
bool get canUseParsedResult => true;
38-
3936
static const LintCode code = LintCode('prefer_generic_function_type_aliases',
4037
"Use the generic function type syntax in 'typedef's.",
4138
correctionMessage: "Try using the generic function type syntax ('{0}').");
@@ -47,6 +44,9 @@ class PreferGenericFunctionTypeAliases extends LintRule {
4744
details: _details,
4845
group: Group.style);
4946

47+
@override
48+
bool get canUseParsedResult => true;
49+
5050
@override
5151
LintCode get lintCode => code;
5252

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ bool isJavaStyle(Comment comment) {
4343
}
4444

4545
class SlashForDocComments extends LintRule {
46-
@override
47-
bool get canUseParsedResult => true;
48-
4946
static const LintCode code = LintCode('slash_for_doc_comments',
5047
"Use the end-of-line form ('///') for doc comments.",
5148
correctionMessage: "Try rewriting the comment to use '///'.");
@@ -57,6 +54,9 @@ class SlashForDocComments extends LintRule {
5754
details: _details,
5855
group: Group.style);
5956

57+
@override
58+
bool get canUseParsedResult => true;
59+
6060
@override
6161
LintCode get lintCode => code;
6262

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ m(){
3434
''';
3535

3636
class UnnecessaryConst extends LintRule {
37-
@override
38-
bool get canUseParsedResult => true;
39-
4037
static const LintCode code = LintCode(
4138
'unnecessary_const', "Unnecessary 'const' keyword.",
4239
correctionMessage: 'Try removing the keyword.');
@@ -48,6 +45,9 @@ class UnnecessaryConst extends LintRule {
4845
details: _details,
4946
group: Group.style);
5047

48+
@override
49+
bool get canUseParsedResult => true;
50+
5151
@override
5252
LintCode get lintCode => code;
5353

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ class _Visitor extends SimpleAstVisitor<void> {
8585
LintCode getErrorCode(Object? type) =>
8686
type == null ? UnnecessaryFinal.withoutType : UnnecessaryFinal.withType;
8787

88+
(Token?, AstNode?) getParameterDetails(FormalParameter node) {
89+
var parameter = node is DefaultFormalParameter ? node.parameter : node;
90+
return switch (parameter) {
91+
FieldFormalParameter() => (parameter.keyword, parameter.type),
92+
SimpleFormalParameter() => (parameter.keyword, parameter.type),
93+
SuperFormalParameter() => (parameter.keyword, parameter.type),
94+
_ => (null, null),
95+
};
96+
}
97+
8898
@override
8999
void visitDeclaredVariablePattern(DeclaredVariablePattern node) {
90100
var keyword = node.keyword;
@@ -138,14 +148,4 @@ class _Visitor extends SimpleAstVisitor<void> {
138148
rule.reportLintForToken(node.variables.keyword, errorCode: errorCode);
139149
}
140150
}
141-
142-
(Token?, AstNode?) getParameterDetails(FormalParameter node) {
143-
var parameter = node is DefaultFormalParameter ? node.parameter : node;
144-
return switch (parameter) {
145-
FieldFormalParameter() => (parameter.keyword, parameter.type),
146-
SimpleFormalParameter() => (parameter.keyword, parameter.type),
147-
SuperFormalParameter() => (parameter.keyword, parameter.type),
148-
_ => (null, null),
149-
};
150-
}
151151
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'package:analyzer/dart/ast/visitor.dart';
77

88
import '../analyzer.dart';
99

10-
const _name = 'unnecessary_library_directive';
11-
1210
const _desc =
1311
'Avoid library directives unless they have documentation comments or '
1412
'annotations.';
@@ -37,6 +35,8 @@ NOTE: Due to limitations with this lint, libraries with parts will not be
3735
flagged for unnecessary library directives.
3836
''';
3937

38+
const _name = 'unnecessary_library_directive';
39+
4040
class UnnecessaryLibraryDirective extends LintRule {
4141
static const LintCode code = LintCode(
4242
_name,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ m(){
3232
''';
3333

3434
class UnnecessaryNew extends LintRule {
35-
@override
36-
bool get canUseParsedResult => true;
37-
3835
static const LintCode code = LintCode(
3936
'unnecessary_new', "Unnecessary 'new' keyword.",
4037
correctionMessage: "Try removing the 'new' keyword.");
@@ -46,6 +43,9 @@ class UnnecessaryNew extends LintRule {
4643
details: _details,
4744
group: Group.style);
4845

46+
@override
47+
bool get canUseParsedResult => true;
48+
4949
@override
5050
LintCode get lintCode => code;
5151

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ Remove unnecessary backslashes in strings.
2828
''';
2929

3030
class UnnecessaryStringEscapes extends LintRule {
31-
@override
32-
bool get canUseParsedResult => true;
33-
3431
static const LintCode code = LintCode(
3532
'unnecessary_string_escapes', 'Unnecessary escape in string literal.',
3633
correctionMessage: "Remove the '\\' escape.");
@@ -42,6 +39,9 @@ class UnnecessaryStringEscapes extends LintRule {
4239
details: _details,
4340
group: Group.style);
4441

42+
@override
43+
bool get canUseParsedResult => true;
44+
4545
@override
4646
LintCode get lintCode => code;
4747

0 commit comments

Comments
 (0)