Skip to content

Commit

Permalink
don't lint unnecessary lib names pre unnamedLibraries
Browse files Browse the repository at this point in the history
Related to: dart-lang/lints#181

Change-Id: I4a247fa93c6659d5082d2cb6047aedc6a13a4209
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359321
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and Commit Queue committed Mar 25, 2024
1 parent 19decc4 commit 6a9c709
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/linter/lib/src/rules/unnecessary_library_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';

Expand Down Expand Up @@ -65,6 +66,11 @@ class UnnecessaryLibraryName extends LintRule {
@override
void registerNodeProcessors(
NodeLintRegistry registry, LinterContext context) {
if (!context.currentUnit.unit.featureSet
.isEnabled(Feature.unnamedLibraries)) {
return;
}

var visitor = _Visitor(this);
registry.addLibraryDirective(this, visitor);
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/linter/test/rules/unnecessary_library_name_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ library name;
]);
}

test_namedLibrary_preUnnamedLibraries() async {
await assertNoDiagnostics(r'''
// @dart = 2.14
library name;
''');
}

test_unnamedLibrary() async {
await assertNoDiagnostics(r'''
library;
Expand Down

0 comments on commit 6a9c709

Please sign in to comment.