fix for prefixed identifiers (#2091)
diff --git a/lib/src/rules/exhaustive_cases.dart b/lib/src/rules/exhaustive_cases.dart
index 12815da..0132862 100644
--- a/lib/src/rules/exhaustive_cases.dart
+++ b/lib/src/rules/exhaustive_cases.dart
@@ -119,12 +119,13 @@
for (var member in statement.members) {
if (member is SwitchCase) {
var expression = member.expression;
- // todo (pq): add a test to ensure that this handles prefixed identifiers.
if (expression is Identifier) {
var element = expression.staticElement;
if (element is PropertyAccessorElement) {
enumConstantNames.remove(element.name);
}
+ } else if (expression is PropertyAccess) {
+ enumConstantNames.remove(expression.propertyName.name);
}
}
}
diff --git a/test/_data/exhaustive_cases/a.dart b/test/_data/exhaustive_cases/a.dart
new file mode 100644
index 0000000..3e5c627
--- /dev/null
+++ b/test/_data/exhaustive_cases/a.dart
@@ -0,0 +1,16 @@
+// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'e.dart' as prefixed;
+
+void e(prefixed.E e) {
+ // Missing case.
+ switch(e) { // LINT
+ case prefixed.E.e :
+ print('e');
+ break;
+ case prefixed.E.f :
+ print('e');
+ }
+}
diff --git a/test/_data/exhaustive_cases/e.dart b/test/_data/exhaustive_cases/e.dart
new file mode 100644
index 0000000..097db1e
--- /dev/null
+++ b/test/_data/exhaustive_cases/e.dart
@@ -0,0 +1,13 @@
+// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Enum-like
+class E {
+ final int i;
+ const E._(this.i);
+
+ static const e = E._(1);
+ static const f = E._(2);
+ static const g = E._(3);
+}
diff --git a/test/integration_test.dart b/test/integration_test.dart
index 7c2622e..8a0d4fc 100644
--- a/test/integration_test.dart
+++ b/test/integration_test.dart
@@ -21,6 +21,24 @@
void defineTests() {
group('integration', () {
+ group('exhaustive_cases', () {
+ final currentOut = outSink;
+ final collectingOut = CollectingSink();
+ setUp(() => outSink = collectingOut);
+ tearDown(() {
+ collectingOut.buffer.clear();
+ outSink = currentOut;
+ });
+ test('exhaustive_cases', () async {
+ await cli.runLinter([
+ 'test/_data/exhaustive_cases',
+ '--rules=exhaustive_cases',
+ ], LinterOptions());
+ expect(collectingOut.trim(),
+ contains('2 files analyzed, 1 issue found, in'));
+ });
+ });
+
group('avoid_web_libraries_in_flutter', () {
final currentOut = outSink;
final collectingOut = CollectingSink();