From 6cf6572390fbe7e7eed3cfff51f1f98058ddc20e Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 26 Sep 2022 13:53:22 -0700 Subject: [PATCH 1/3] Support unnamed libraries --- lib/src/rules/library_names.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/rules/library_names.dart b/lib/src/rules/library_names.dart index a16f3c5fa..bd77b0b1a 100644 --- a/lib/src/rules/library_names.dart +++ b/lib/src/rules/library_names.dart @@ -57,8 +57,9 @@ class _Visitor extends SimpleAstVisitor { @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); } } } From 48ffc8cbea6bf77d46685be8a78cf0d4ca027fb2 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 26 Sep 2022 21:10:24 -0700 Subject: [PATCH 2/3] switch to unit tests --- test/rules/library_names_test.dart | 55 ++++++++++++++++++++++++++++++ test_data/rules/library_names.dart | 7 ---- 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 test/rules/library_names_test.dart delete mode 100644 test_data/rules/library_names.dart diff --git a/test/rules/library_names_test.dart b/test/rules/library_names_test.dart new file mode 100644 index 000000000..288deb090 --- /dev/null +++ b/test/rules/library_names_test.dart @@ -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 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), + ]); + } +} diff --git a/test_data/rules/library_names.dart b/test_data/rules/library_names.dart deleted file mode 100644 index fd9fcd765..000000000 --- a/test_data/rules/library_names.dart +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2015, 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. - -// test w/ `dart test -N library_names` - -library Foo; //LINT [9:3] From 16fbf347325f3ddcd1798fb8eed514d68b47ba5b Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 26 Sep 2022 21:21:28 -0700 Subject: [PATCH 3/3] all --- test/rules/all.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/rules/all.dart b/test/rules/all.dart index 214e0c6f5..5090ca1aa 100644 --- a/test/rules/all.dart +++ b/test/rules/all.dart @@ -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' @@ -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();