Skip to content

Commit b2bdedf

Browse files
pqCommit Queue
authored and
Commit Queue
committed
[wildcards] remove wildcard opinions from non_constant_identifier_names
TL;DR this returns the lint to a pre-wildcard feature laissez faire attitude towards underscores. There's ongoing conversation about how we want to nudge folks to avoid needless use of underscores on #56595 but it's not likely to happen in this lint (and almost certainly not before the feature is enabled). Change-Id: I9aff2bc225616336655cddbc2635b427265497bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381903 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 5efa2e3 commit b2bdedf

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/analysis/features.dart';
65
import 'package:analyzer/dart/ast/ast.dart';
76
import 'package:analyzer/dart/ast/token.dart';
87
import 'package:analyzer/dart/ast/visitor.dart';
9-
import 'package:analyzer/dart/element/element.dart';
108

119
import '../analyzer.dart';
1210
import '../extensions.dart';
@@ -50,7 +48,7 @@ class NonConstantIdentifierNames extends LintRule {
5048
@override
5149
void registerNodeProcessors(
5250
NodeLintRegistry registry, LinterContext context) {
53-
var visitor = _Visitor(this, context.libraryElement);
51+
var visitor = _Visitor(this);
5452
registry.addCatchClause(this, visitor);
5553
registry.addConstructorDeclaration(this, visitor);
5654
registry.addDeclaredVariablePattern(this, visitor);
@@ -68,14 +66,9 @@ class NonConstantIdentifierNames extends LintRule {
6866
}
6967

7068
class _Visitor extends SimpleAstVisitor<void> {
71-
/// Whether the `wildcard_variables` feature is enabled.
72-
final bool _wildCardVariablesEnabled;
73-
7469
final LintRule rule;
7570

76-
_Visitor(this.rule, LibraryElement? library)
77-
: _wildCardVariablesEnabled =
78-
library?.featureSet.isEnabled(Feature.wildcard_variables) ?? false;
71+
_Visitor(this.rule);
7972

8073
void checkIdentifier(Token? id, {bool underscoresOk = false}) {
8174
if (id == null) {
@@ -93,10 +86,8 @@ class _Visitor extends SimpleAstVisitor<void> {
9386

9487
@override
9588
void visitCatchClause(CatchClause node) {
96-
checkIdentifier(node.exceptionParameter?.name,
97-
underscoresOk: !_wildCardVariablesEnabled);
98-
checkIdentifier(node.stackTraceParameter?.name,
99-
underscoresOk: !_wildCardVariablesEnabled);
89+
checkIdentifier(node.exceptionParameter?.name, underscoresOk: true);
90+
checkIdentifier(node.stackTraceParameter?.name, underscoresOk: true);
10091
}
10192

10293
@override
@@ -129,7 +120,7 @@ class _Visitor extends SimpleAstVisitor<void> {
129120
for (var p in node.parameters) {
130121
if (inAugmentation && p.isNamed) continue;
131122
if (p is! FieldFormalParameter) {
132-
checkIdentifier(p.name, underscoresOk: !_wildCardVariablesEnabled);
123+
checkIdentifier(p.name, underscoresOk: true);
133124
}
134125
}
135126
}

pkg/linter/test/rules/non_constant_identifier_names_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ augment int Xx = 2;
392392
''');
393393
}
394394

395+
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/5048')
395396
test_catch_underscores() async {
396397
await assertDiagnostics(r'''
397398
f() {
@@ -470,12 +471,9 @@ class A {
470471
}
471472

472473
test_formalParams_underscores() async {
473-
await assertDiagnostics(r'''
474+
await assertNoDiagnostics(r'''
474475
f(int _, int __, int ___) {}
475-
''', [
476-
lint(13, 2),
477-
lint(21, 3),
478-
]);
476+
''');
479477
}
480478

481479
test_formalParams_underscores_preWildcards() async {

0 commit comments

Comments
 (0)