Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Support unnamed libraries #3730

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/src/rules/library_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitLibraryDirective(LibraryDirective node) {
if (!isLowerCaseUnderScoreWithDots(node.name2.toString())) {
rule.reportLint(node.name2);
var name = node.name2;
if (name != null && !isLowerCaseUnderScoreWithDots(name.toString())) {
rule.reportLint(name);
}
}
}
2 changes: 2 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import 'discarded_futures_test.dart' as discarded_futures;
import 'file_names_test.dart' as file_names;
import 'flutter_style_todos_test.dart' as flutter_style_todos;
import 'hash_and_equals_test.dart' as hash_and_equals;
import 'library_names_test.dart' as library_names;
import 'library_private_types_in_public_api_test.dart'
as library_private_types_in_public_api;
import 'literal_only_boolean_expressions_test.dart'
Expand Down Expand Up @@ -106,6 +107,7 @@ void main() {
file_names.main();
flutter_style_todos.main();
hash_and_equals.main();
library_names.main();
library_private_types_in_public_api.main();
literal_only_boolean_expressions.main();
missing_whitespace_between_adjacent_strings.main();
Expand Down
55 changes: 55 additions & 0 deletions test/rules/library_names_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(LibraryNamesTest);
});
}

@reflectiveTest
class LibraryNamesTest extends LintRuleTest {
@override
List<String> get experiments => ['unnamed-libraries'];

@override
String get lintRule => 'library_names';

test_libraryWithoutName() async {
await assertNoDiagnostics('''
library;
''');
}

test_lowercase() async {
await assertNoDiagnostics('''
library foo;
''');
}

test_noLibrary() async {
await assertNoDiagnostics('''
''');
}

test_titlecase() async {
await assertDiagnostics('''
library Foo;
''', [
lint(8, 3),
]);
}

test_uppercaseInDots() async {
await assertDiagnostics('''
library one.Two.three;
''', [
lint(8, 13),
]);
}
}
7 changes: 0 additions & 7 deletions test_data/rules/library_names.dart

This file was deleted.