Skip to content

Commit 6a9c709

Browse files
pqCommit Queue
authored and
Commit Queue
committed
don't lint unnecessary lib names pre unnamedLibraries
Related to: https://github.com/dart-lang/lints/issues/181 Change-Id: I4a247fa93c6659d5082d2cb6047aedc6a13a4209 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359321 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 19decc4 commit 6a9c709

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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';
56
import 'package:analyzer/dart/ast/ast.dart';
67
import 'package:analyzer/dart/ast/visitor.dart';
78

@@ -65,6 +66,11 @@ class UnnecessaryLibraryName extends LintRule {
6566
@override
6667
void registerNodeProcessors(
6768
NodeLintRegistry registry, LinterContext context) {
69+
if (!context.currentUnit.unit.featureSet
70+
.isEnabled(Feature.unnamedLibraries)) {
71+
return;
72+
}
73+
6874
var visitor = _Visitor(this);
6975
registry.addLibraryDirective(this, visitor);
7076
}

pkg/linter/test/rules/unnecessary_library_name_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ library name;
2525
]);
2626
}
2727

28+
test_namedLibrary_preUnnamedLibraries() async {
29+
await assertNoDiagnostics(r'''
30+
// @dart = 2.14
31+
library name;
32+
''');
33+
}
34+
2835
test_unnamedLibrary() async {
2936
await assertNoDiagnostics(r'''
3037
library;

0 commit comments

Comments
 (0)