Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 28726f1

Browse files
authored
extension type support for non_constant_identifier_names (#4696)
1 parent 6b03b69 commit 28726f1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/src/rules/non_constant_identifier_names.dart

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class NonConstantIdentifierNames extends LintRule {
5656
registry.addCatchClause(this, visitor);
5757
registry.addConstructorDeclaration(this, visitor);
5858
registry.addDeclaredVariablePattern(this, visitor);
59+
registry.addExtensionTypeDeclaration(this, visitor);
5960
registry.addForEachPartsWithDeclaration(this, visitor);
6061
registry.addFormalParameterList(this, visitor);
6162
registry.addFunctionDeclaration(this, visitor);
@@ -105,6 +106,11 @@ class _Visitor extends SimpleAstVisitor<void> {
105106
checkIdentifier(node.name);
106107
}
107108

109+
@override
110+
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
111+
checkIdentifier(node.representation.constructorName?.name);
112+
}
113+
108114
@override
109115
void visitForEachPartsWithDeclaration(ForEachPartsWithDeclaration node) {
110116
checkIdentifier(node.loopVariable.name);

test/rules/non_constant_identifier_names_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ main() {
1616

1717
@reflectiveTest
1818
class NonConstantIdentifierNamesPatternsTest extends LintRuleTest {
19+
@override
20+
List<String> get experiments => ['inline-class'];
21+
1922
@override
2023
String get lintRule => 'non_constant_identifier_names';
2124

25+
test_extensionType_representationConstructorName() async {
26+
await assertDiagnostics(r'''
27+
extension type e.Efg(int i) {}
28+
''', [
29+
lint(17, 3),
30+
]);
31+
}
32+
2233
test_patternForStatement() async {
2334
await assertDiagnostics(r'''
2435
void f() {

0 commit comments

Comments
 (0)