linter: move tests for three rules

* library_prefixes
* no_leading_underscores_for_library_prefixes
* package_prefixed_library_names

Change-Id: I641a547d572abc5001d42ceaed0dd216e0d07338
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370460
Auto-Submit: Sam Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Sam Rawlins 2024-06-10 14:33:07 +00:00 committed by Commit Queue
parent e18c43a21e
commit 38e60413a0
7 changed files with 132 additions and 30 deletions

View file

@ -116,6 +116,7 @@ import 'leading_newlines_in_multiline_strings_test.dart'
as leading_newlines_in_multiline_strings;
import 'library_annotations_test.dart' as library_annotations;
import 'library_names_test.dart' as library_names;
import 'library_prefixes_test.dart' as library_prefixes;
import 'library_private_types_in_public_api_test.dart'
as library_private_types_in_public_api;
import 'lines_longer_than_80_chars_test.dart' as lines_longer_than_80_chars;
@ -128,6 +129,8 @@ import 'missing_whitespace_between_adjacent_strings_test.dart'
as missing_whitespace_between_adjacent_strings;
import 'no_adjacent_strings_in_list_test.dart' as no_adjacent_strings_in_list;
import 'no_duplicate_case_values_test.dart' as no_duplicate_case_values;
import 'no_leading_underscores_for_library_prefixes_test.dart'
as no_leading_underscores_for_library_prefixes;
import 'no_leading_underscores_for_local_identifiers_test.dart'
as no_leading_underscores_for_local_identifiers;
import 'no_literal_bool_comparisons_test.dart' as no_literal_bool_comparisons;
@ -146,6 +149,8 @@ import 'one_member_abstracts_test.dart' as one_member_abstracts;
import 'only_throw_errors_test.dart' as only_throw_errors;
import 'overridden_fields_test.dart' as overridden_fields;
import 'package_names_test.dart' as package_names;
import 'package_prefixed_library_names_test.dart'
as package_prefixed_library_names;
import 'parameter_assignments_test.dart' as parameter_assignments;
import 'prefer_adjacent_string_concatenation_test.dart'
as prefer_adjacent_string_concatenation;
@ -362,6 +367,7 @@ void main() {
leading_newlines_in_multiline_strings.main();
library_annotations.main();
library_names.main();
library_prefixes.main();
library_private_types_in_public_api.main();
lines_longer_than_80_chars.main();
literal_only_boolean_expressions.main();
@ -370,6 +376,7 @@ void main() {
missing_whitespace_between_adjacent_strings.main();
no_adjacent_strings_in_list.main();
no_duplicate_case_values.main();
no_leading_underscores_for_library_prefixes.main();
no_leading_underscores_for_local_identifiers.main();
no_literal_bool_comparisons.main();
no_logic_in_create_state.main();
@ -385,6 +392,7 @@ void main() {
only_throw_errors.main();
overridden_fields.main();
package_names.main();
package_prefixed_library_names.main();
parameter_assignments.main();
prefer_adjacent_string_concatenation.main();
prefer_asserts_in_initializer_lists.main();

View file

@ -0,0 +1,58 @@
// Copyright (c) 2024, 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:analyzer/src/error/analyzer_error_code.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../rule_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(LibraryPrefixesTest);
});
}
@reflectiveTest
class LibraryPrefixesTest extends LintRuleTest {
@override
List<AnalyzerErrorCode> get ignoredErrorCodes =>
[WarningCode.UNUSED_IMPORT, WarningCode.UNUSED_LOCAL_VARIABLE];
@override
String get lintRule => 'library_prefixes';
test_camelCase() async {
await assertDiagnostics(r'''
import 'dart:async' as dartAsync;
''', [
lint(23, 9),
]);
}
test_leadingDollar() async {
await assertNoDiagnostics(r'''
import 'dart:async' as $async;
''');
}
test_leadingUnderscore() async {
await assertNoDiagnostics(r'''
import 'dart:async' as _async;
''');
}
test_leadingUnderscore_withNumbers() async {
await assertNoDiagnostics(r'''
import 'dart:async' as _i1;
''');
}
test_numberWithLeadingUnderscore() async {
await assertDiagnostics(r'''
import 'dart:async' as _1;
''', [
lint(23, 2),
]);
}
}

View file

@ -0,0 +1,38 @@
// Copyright (c) 2024, 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:analyzer/src/error/analyzer_error_code.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../rule_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NoLeadingUnderscoresForLibraryPrefixesTest);
});
}
@reflectiveTest
class NoLeadingUnderscoresForLibraryPrefixesTest extends LintRuleTest {
@override
List<AnalyzerErrorCode> get ignoredErrorCodes =>
[WarningCode.UNUSED_IMPORT, WarningCode.UNUSED_LOCAL_VARIABLE];
@override
String get lintRule => 'no_leading_underscores_for_library_prefixes';
test_leadingUnderscore() async {
await assertDiagnostics(r'''
import 'dart:async' as _async;
''', [
lint(23, 6),
]);
}
test_snakeCase() async {
await assertNoDiagnostics(r'''
import 'dart:async' as dart_async;
''');
}
}

View file

@ -0,0 +1,28 @@
// Copyright (c) 2024, 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(PackagePrefixedLibraryNamesTest);
});
}
@reflectiveTest
class PackagePrefixedLibraryNamesTest extends LintRuleTest {
@override
String get lintRule => 'package_prefixed_library_names';
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3395')
test_badName() async {
await assertDiagnostics(r'''
library linter.not_where_it_should_be;
''', [
lint(8, 29),
]);
}
}

View file

@ -1,16 +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.
import 'dart:async' as _async; //OK
import 'dart:collection' as $collection; //OK
import 'dart:convert' as _1; //LINT
import 'dart:core' as _i1; //OK
import 'dart:math' as dartMath; //LINT [23:8]
main() {
_i1.print(dartMath.pi);
_i1.print(_async.Timer);
_i1.print(new $collection.LinkedHashSet<_i1.String>());
_i1.print(_1.json);
}

View file

@ -1,8 +0,0 @@
// Copyright (c) 2021, 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 'dart:async' as _async; // LINT
import 'dart:convert' as _convert; // LINT
import 'dart:core' as dart_core; // OK
import 'dart:math' as dart_math; // OK

View file

@ -1,6 +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.
// See: https://github.com/dart-lang/linter/issues/3395
library linter.not_where_it_should_be; //FAILING