Skip to content

Commit 7c8b697

Browse files
Fixed tests in test folders (#194)
* Fixed avoid_late_keyword_allow_initialized_test.dart * Fixed avoid_late_keyword_no_generics_test.dart * Fixed avoid_late_keyword_with_generics_test.dart * Fixed avoid_using_api external_source test * Fixed no_magic_number_allowed_in_widget_params_test.dart * Fixed alphabetize_by_type_test.dart * Fixed prefer_match_file_name_rule.dart * Fixed function_lines_of_code_rule.dart * Deleted avoid_unused_parameters_test folder * Update lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart --------- Co-authored-by: Yurii Prykhodko <[email protected]>
1 parent 3e1711b commit 7c8b697

File tree

12 files changed

+127
-57
lines changed

12 files changed

+127
-57
lines changed

lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,28 @@ class FunctionLinesOfCodeRule
5050
) {
5151
void checkNode(AstNode node) => _checkNode(resolver, reporter, node);
5252

53-
context.registry.addDeclaration((declarationNode) {
54-
final isIgnored = config.parameters.exclude.shouldIgnore(declarationNode);
53+
void checkDeclarationNode(Declaration node) {
54+
final isIgnored = config.parameters.exclude.shouldIgnore(node);
55+
if (isIgnored) {
56+
return;
57+
}
58+
checkNode(node);
59+
}
5560

56-
if (isIgnored) return;
61+
// Check for an anonymous function
62+
void checkFunctionExpressionNode(FunctionExpression node) {
63+
// If a FunctionExpression is an immediate child of a FunctionDeclaration
64+
// this means it's a named function, which are already check as part of
65+
// addFunctionDeclaration call.
66+
if (node.parent is FunctionDeclaration) {
67+
return;
68+
}
69+
checkNode(node);
70+
}
5771

58-
context.registry.addMethodDeclaration(checkNode);
59-
context.registry.addFunctionDeclaration(checkNode);
60-
context.registry.addFunctionExpression(checkNode);
61-
});
72+
context.registry.addFunctionDeclaration(checkDeclarationNode);
73+
context.registry.addMethodDeclaration(checkDeclarationNode);
74+
context.registry.addFunctionExpression(checkFunctionExpressionNode);
6275
}
6376

6477
void _checkNode(

lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ class PreferMatchFileNameRule extends SolidLintRule {
8787
if (_doNormalizedNamesMatch(
8888
resolver.source.fullName,
8989
firstDeclaration.token.lexeme,
90-
)) return;
90+
)) {
91+
return;
92+
}
9193

9294
final nodeType =
9395
humanReadableNodeType(firstDeclaration.parent).toLowerCase();

lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/// alphabetical-by-type option enabled
77
88
class CorrectAlphabeticalByTypeClass {
9-
final int a = 1;
109
final double e = 1;
10+
final int a = 1;
1111
}
1212

1313
class WrongAlphabeticalByTypeClass {

lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,68 @@ class ColorTween {}
1414
/// `avoid_late_keyword`
1515
/// allow_initialized option disabled
1616
class AvoidLateKeyword {
17-
/// expect_lint: avoid_late_keyword
17+
/// ignored_types: Animation
1818
late final Animation animation1;
1919

20+
/// ignored_types: Animation
2021
late final animation2 = AnimationController();
2122

23+
/// ignored_types: Animation
2224
late final animation3 = SubAnimationController();
2325

2426
/// expect_lint: avoid_late_keyword
2527
late final ColorTween colorTween1;
2628

29+
/// expect_lint: avoid_late_keyword
2730
late final colorTween2 = ColorTween();
2831

32+
/// expect_lint: avoid_late_keyword
2933
late final colorTween3 = colorTween2;
3034

31-
/// expect_lint: avoid_late_keyword
35+
/// ignored_types: Animation
3236
late final AnimationController controller1;
3337

38+
/// expect_lint: avoid_late_keyword
3439
late final field1 = 'string';
3540

3641
/// expect_lint: avoid_late_keyword
3742
late final String field2;
3843

44+
/// expect_lint: avoid_late_keyword
3945
late final String field3 = 'string';
4046

4147
/// expect_lint: avoid_late_keyword
4248
late final field4;
4349

4450
void test() {
45-
/// expect_lint: avoid_late_keyword
51+
/// ignored_types: Animation
4652
late final Animation animation1;
4753

54+
/// ignored_types: Animation
4855
late final animation2 = AnimationController();
4956

57+
/// ignored_types: Animation
5058
late final animation3 = SubAnimationController();
5159

5260
/// expect_lint: avoid_late_keyword
5361
late final ColorTween colorTween1;
5462

63+
/// expect_lint: avoid_late_keyword
5564
late final colorTween2 = ColorTween();
5665

66+
/// expect_lint: avoid_late_keyword
5767
late final colorTween3 = colorTween2;
5868

59-
/// expect_lint: avoid_late_keyword
69+
/// ignored_types: Animation
6070
late final AnimationController controller1;
6171

72+
/// expect_lint: avoid_late_keyword
6273
late final local1 = 'string';
6374

6475
/// expect_lint: avoid_late_keyword
6576
late final String local2;
6677

78+
/// expect_lint: avoid_late_keyword
6779
late final String local4 = 'string';
6880

6981
/// expect_lint: avoid_late_keyword

lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@ class AvoidLateKeyword {
1515
/// expect_lint: avoid_late_keyword
1616
late final NotAllowed na1;
1717

18-
/// expect_lint: avoid_late_keyword
18+
/// ignored_types: Subscription
1919
late final Subscription subscription1;
2020

21-
/// expect_lint: avoid_late_keyword
21+
/// ignored_types: Subscription
2222
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;
2323

24-
/// expect_lint: avoid_late_keyword
24+
/// ignored_types: Subscription
2525
late final Subscription<List<int>> subscription3;
2626

27-
/// expect_lint: avoid_late_keyword
27+
/// ignored_types: Subscription
2828
late final Subscription<List<List<int>>> subscription4;
2929

30-
/// expect_lint: avoid_late_keyword
30+
/// ignored_types: Subscription
3131
late final Subscription<Map<dynamic, String>> subscription5;
3232

3333
void test() {
3434
/// expect_lint: avoid_late_keyword
3535
late final NotAllowed na1;
3636

37-
/// expect_lint: avoid_late_keyword
37+
/// ignored_types: Subscription
3838
late final Subscription subscription1;
3939

40-
/// expect_lint: avoid_late_keyword
40+
/// ignored_types: Subscription
4141
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;
4242

43-
/// expect_lint: avoid_late_keyword
43+
/// ignored_types: Subscription
4444
late final Subscription<List<int>> subscription3;
4545

46-
/// expect_lint: avoid_late_keyword
46+
/// ignored_types: Subscription
4747
late final Subscription<List<List<int>>> subscription4;
4848

49-
/// expect_lint: avoid_late_keyword
49+
/// ignored_types: Subscription
5050
late final Subscription<Map<dynamic, String>> subscription5;
5151
}
5252
}

lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class AnimationController {}
77

88
class SubAnimationController extends AnimationController {}
99

10+
class Allowed {}
11+
1012
class NotAllowed {}
1113

1214
class Subscription<T> {}
@@ -18,19 +20,22 @@ class ConcreteTypeWithNoGenerics {}
1820
/// `avoid_late_keyword`
1921
/// allow_initialized option enabled
2022
class AvoidLateKeyword {
21-
/// expect_lint: avoid_late_keyword
23+
/// ignored_types: ColorTween
2224
late final ColorTween colorTween;
2325

24-
/// expect_lint: avoid_late_keyword
26+
/// ignored_types: AnimationController
2527
late final AnimationController controller1;
2628

27-
/// expect_lint: avoid_late_keyword
29+
/// ignored_types: AnimationController
2830
late final SubAnimationController controller2;
2931

32+
/// ignored_types: AnimationController
3033
late final controller3 = AnimationController();
3134

35+
/// ignored_types: AnimationController
3236
late final controller4 = SubAnimationController();
3337

38+
/// allow_initialized: true
3439
late final field1 = 'string';
3540

3641
/// expect_lint: avoid_late_keyword
@@ -42,43 +47,47 @@ class AvoidLateKeyword {
4247
/// expect_lint: avoid_late_keyword
4348
late final NotAllowed na1;
4449

45-
late final na2 = NotAllowed();
50+
/// allow_initialized: true
51+
late final a = Allowed();
4652

4753
/// expect_lint: avoid_late_keyword
4854
late final Subscription<String> subscription1;
4955

50-
/// expect_lint: avoid_late_keyword
56+
/// ignored_types: Subscription<ConcreteTypeWithNoGenerics>
5157
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;
5258

53-
/// expect_lint: avoid_late_keyword
59+
/// ignored_types: Subscription<List<Object?>>
5460
late final Subscription<List<String>> subscription3;
5561

56-
/// expect_lint: avoid_late_keyword
62+
/// ignored_types: Subscription<List<Object?>>
5763
late final Subscription<List<List<int>>> subscription4;
5864

59-
/// expect_lint: avoid_late_keyword
65+
/// ignored_types: Subscription<Map<dynamic, String>>
6066
late final Subscription<Map<dynamic, String>> subscription5;
6167

62-
/// expect_lint: avoid_late_keyword
68+
/// ignored_types: Subscription<Map<dynamic, String>>
6369
late final Subscription<Map<String, String>> subscription6;
6470

6571
/// expect_lint: avoid_late_keyword
6672
late final Subscription<Map<String, dynamic>> subscription7;
6773

6874
void test() {
69-
/// expect_lint: avoid_late_keyword
75+
/// ignored_types: ColorTween
7076
late final ColorTween colorTween;
7177

72-
/// expect_lint: avoid_late_keyword
78+
/// ignored_types: AnimationController
7379
late final AnimationController controller1;
7480

75-
/// expect_lint: avoid_late_keyword
81+
/// ignored_types: AnimationController
7682
late final SubAnimationController controller2;
7783

84+
/// ignored_types: AnimationController
7885
late final controller3 = AnimationController();
7986

87+
/// ignored_types: AnimationController
8088
late final controller4 = SubAnimationController();
8189

90+
/// allow_initialized: true
8291
late final local1 = 'string';
8392

8493
/// expect_lint: avoid_late_keyword
@@ -90,15 +99,16 @@ class AvoidLateKeyword {
9099
/// expect_lint: avoid_late_keyword
91100
late final NotAllowed na1;
92101

93-
late final na2 = NotAllowed();
102+
/// allow_initialized: true
103+
late final a = Allowed();
94104

95105
/// expect_lint: avoid_late_keyword
96106
late final Subscription<String> subscription1;
97107

98-
/// expect_lint: avoid_late_keyword
108+
/// ignored_types: Subscription<ConcreteTypeWithNoGenerics>
99109
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;
100110

101-
/// expect_lint: avoid_late_keyword
111+
/// ignored_types: Subscription<List<String>>
102112
late final Subscription<List<String>> subscription3;
103113
}
104114
}

lint_test/avoid_unused_parameters_test/analysis_options.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// expect_lint: avoid_global_state
21
int banned = 5;

lint_test/avoid_using_api/external_source/lib/external_source.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ const test2 = 'Hello World';
2121

2222
void test() {}
2323

24-
// expect_lint: avoid_global_state
2524
int banned = 5;

lint_test/function_lines_of_code_test/analysis_options.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ custom_lint:
77
- function_lines_of_code:
88
max_lines: 5
99
exclude:
10-
- longFunctionExcluded
11-
- longMethodExcluded
10+
- class_name: ClassWithLongMethods
11+
method_name: longMethodExcluded
12+
- method_name: longFunctionExcluded
13+
- longFunctionExcludedByDeclarationName
14+
- longMethodExcludedByDeclarationName

0 commit comments

Comments
 (0)