Skip to content

Commit 9f524df

Browse files
pqCommit Queue
authored andcommitted
[primary constructors] non_constant_identifier_names support
Fixes: #62016 Bug: #62016 Change-Id: I8f397d99ba7a6a6ac8d3d3abb65579c97be5ed0e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462743 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent f72f7d2 commit 9f524df

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class NonConstantIdentifierNames extends AnalysisRule {
4040
registry.addFunctionDeclaration(this, visitor);
4141
registry.addMethodDeclaration(this, visitor);
4242
registry.addPatternField(this, visitor);
43+
registry.addPrimaryConstructorName(this, visitor);
4344
registry.addRecordLiteral(this, visitor);
4445
registry.addRecordTypeAnnotation(this, visitor);
4546
registry.addVariableDeclaration(this, visitor);
@@ -130,6 +131,11 @@ class _Visitor extends SimpleAstVisitor<void> {
130131
}
131132
}
132133

134+
@override
135+
void visitPrimaryConstructorName(PrimaryConstructorName node) {
136+
checkIdentifier(node.name, underscoresOk: true);
137+
}
138+
133139
@override
134140
void visitRecordLiteral(RecordLiteral node) {
135141
for (var fieldExpression in node.fields) {

pkg/linter/test/rules/non_constant_identifier_names_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,27 @@ class C {
802802
);
803803
}
804804

805+
test_primaryConstructor_lowerCase() async {
806+
await assertNoDiagnostics(r'''
807+
class C.named();
808+
''');
809+
}
810+
811+
test_primaryConstructor_underscores() async {
812+
await assertNoDiagnostics(r'''
813+
class C.___();
814+
''');
815+
}
816+
817+
test_primaryConstructor_upperCase() async {
818+
await assertDiagnostics(
819+
r'''
820+
class C.Named();
821+
''',
822+
[lint(8, 5)],
823+
);
824+
}
825+
805826
test_topLevelFunction() async {
806827
await assertDiagnostics(
807828
r'''

0 commit comments

Comments
 (0)