Skip to content

Commit

Permalink
extension type support for non_constant_identifier_names (#4696)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored Aug 14, 2023
1 parent 6b03b69 commit 28726f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/rules/non_constant_identifier_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NonConstantIdentifierNames extends LintRule {
registry.addCatchClause(this, visitor);
registry.addConstructorDeclaration(this, visitor);
registry.addDeclaredVariablePattern(this, visitor);
registry.addExtensionTypeDeclaration(this, visitor);
registry.addForEachPartsWithDeclaration(this, visitor);
registry.addFormalParameterList(this, visitor);
registry.addFunctionDeclaration(this, visitor);
Expand Down Expand Up @@ -105,6 +106,11 @@ class _Visitor extends SimpleAstVisitor<void> {
checkIdentifier(node.name);
}

@override
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
checkIdentifier(node.representation.constructorName?.name);
}

@override
void visitForEachPartsWithDeclaration(ForEachPartsWithDeclaration node) {
checkIdentifier(node.loopVariable.name);
Expand Down
11 changes: 11 additions & 0 deletions test/rules/non_constant_identifier_names_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ main() {

@reflectiveTest
class NonConstantIdentifierNamesPatternsTest extends LintRuleTest {
@override
List<String> get experiments => ['inline-class'];

@override
String get lintRule => 'non_constant_identifier_names';

test_extensionType_representationConstructorName() async {
await assertDiagnostics(r'''
extension type e.Efg(int i) {}
''', [
lint(17, 3),
]);
}

test_patternForStatement() async {
await assertDiagnostics(r'''
void f() {
Expand Down

0 comments on commit 28726f1

Please sign in to comment.