Skip to content

Commit 47ecb53

Browse files
parloughCommit Queue
authored andcommitted
[linter] Mark unnecessary_final and prefer_final_in_for_each as incompatible
Change-Id: Ifa4af7c5ab4c5e68ae3e71bc6fc6a3b30394927b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391022 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ce913cf commit 47ecb53

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class PreferFinalInForEach extends LintRule {
1818
description: _desc,
1919
);
2020

21+
@override
22+
List<String> get incompatibleRules => const [LintNames.unnecessary_final];
23+
2124
@override
2225
List<LintCode> get lintCodes => [
2326
LinterLintCode.prefer_final_in_for_each_pattern,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ class UnnecessaryFinal extends LintRule {
1919
);
2020

2121
@override
22-
List<String> get incompatibleRules =>
23-
const [LintNames.prefer_final_locals, LintNames.prefer_final_parameters];
22+
List<String> get incompatibleRules => const [
23+
LintNames.prefer_final_locals,
24+
LintNames.prefer_final_parameters,
25+
LintNames.prefer_final_in_for_each
26+
];
2427

2528
@override
2629
List<LintCode> get lintCodes => [

pkg/linter/tool/machine/rules.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@
374374
"categories": [
375375
"style"
376376
],
377-
"state": "removed",
377+
"state": "stable",
378378
"incompatible": [],
379379
"sets": [],
380-
"fixStatus": "noFix",
381-
"details": "**DON'T** check for `null` in custom `==` operators.\n\nAs `null` is a special value, no instance of any class (other than `Null`) can\nbe equivalent to it. Thus, it is redundant to check whether the other instance\nis `null`.\n\n**BAD:**\n```dart\nclass Person {\n final String? name;\n\n @override\n operator ==(Object? other) =>\n other != null && other is Person && name == other.name;\n}\n```\n\n**GOOD:**\n```dart\nclass Person {\n final String? name;\n\n @override\n operator ==(Object? other) => other is Person && name == other.name;\n}\n```\n\nThis rule has been removed.",
380+
"fixStatus": "hasFix",
381+
"details": "**DON'T** check for `null` in custom `==` operators.\n\nAs `null` is a special value, no instance of any class (other than `Null`) can\nbe equivalent to it. Thus, it is redundant to check whether the other instance\nis `null`.\n\n**BAD:**\n```dart\nclass Person {\n final String? name;\n\n @override\n operator ==(Object? other) =>\n other != null && other is Person && name == other.name;\n}\n```\n\n**GOOD:**\n```dart\nclass Person {\n final String? name;\n\n @override\n operator ==(Object? other) => other is Person && name == other.name;\n}\n```",
382382
"sinceDartSdk": "2.0"
383383
},
384384
{
@@ -1877,7 +1877,9 @@
18771877
"style"
18781878
],
18791879
"state": "stable",
1880-
"incompatible": [],
1880+
"incompatible": [
1881+
"unnecessary_final"
1882+
],
18811883
"sets": [],
18821884
"fixStatus": "hasFix",
18831885
"details": "**DO** prefer declaring for-each loop variables as final if they are not\nreassigned later in the code.\n\nDeclaring for-each loop variables as final when possible is a good practice\nbecause it helps avoid accidental reassignments and allows the compiler to do\noptimizations.\n\n**BAD:**\n```dart\nfor (var element in elements) { // LINT\n print('Element: $element');\n}\n```\n\n**GOOD:**\n```dart\nfor (final element in elements) {\n print('Element: $element');\n}\n```\n\n**GOOD:**\n```dart\nfor (var element in elements) {\n element = element + element;\n print('Element: $element');\n}\n```",
@@ -2589,7 +2591,8 @@
25892591
"state": "stable",
25902592
"incompatible": [
25912593
"prefer_final_locals",
2592-
"prefer_final_parameters"
2594+
"prefer_final_parameters",
2595+
"prefer_final_in_for_each"
25932596
],
25942597
"sets": [],
25952598
"fixStatus": "hasFix",

0 commit comments

Comments
 (0)