Skip to content

Commit 65ec797

Browse files
authored
enhanced enum support for avoid_equals_and_hash_code_on_mutable_classes (dart-archive/linter#3233)
* enhanced enum support for `avoid_equals_and_hash_code_on_mutable_classes` * - stale todo * fmt * test update * fmt
1 parent f5d28a7 commit 65ec797

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

test/rules/all.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'annotate_overrides_test.dart' as annotate_overrides;
66
import 'avoid_annotating_with_dynamic_test.dart'
77
as avoid_annotating_with_dynamic;
8+
import 'avoid_equals_and_hash_code_on_mutable_classes_test.dart'
9+
as avoid_equals_and_hash_code_on_mutable_classes;
810
import 'avoid_function_literals_in_foreach_calls_test.dart'
911
as avoid_function_literals_in_foreach_calls;
1012
import 'avoid_init_to_null_test.dart' as avoid_init_to_null;
@@ -68,6 +70,7 @@ import 'void_checks_test.dart' as void_checks;
6870
void main() {
6971
annotate_overrides.main();
7072
avoid_annotating_with_dynamic.main();
73+
avoid_equals_and_hash_code_on_mutable_classes.main();
7174
avoid_function_literals_in_foreach_calls.main();
7275
avoid_setters_without_getters.main();
7376
avoid_init_to_null.main();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test_reflective_loader/test_reflective_loader.dart';
6+
7+
import '../rule_test_support.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(AvoidEqualsAndHashCodeOnMutableClassesTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class AvoidEqualsAndHashCodeOnMutableClassesTest extends LintRuleTest {
17+
@override
18+
bool get addMetaPackageDep => true;
19+
20+
@override
21+
List<String> get experiments => [
22+
EnableString.enhanced_enums,
23+
];
24+
25+
@override
26+
String get lintRule => 'avoid_equals_and_hash_code_on_mutable_classes';
27+
28+
@FailingTest(
29+
issue: 'https://github.com/dart-lang/linter/issues/3094',
30+
reason: 'Needs new analyzer')
31+
test_enums() async {
32+
// Enums are constant by design.
33+
await assertNoDiagnostics(r'''
34+
enum E {
35+
e(1), f(2), g(3);
36+
final int key;
37+
const E(this.key);
38+
bool operator ==(Object other) => other is E && other.key == key;
39+
int get hashCode => key.hashCode;
40+
}
41+
''');
42+
}
43+
}

0 commit comments

Comments
 (0)