diff --git a/test/integration/avoid_relative_lib_imports.dart b/test/integration/avoid_relative_lib_imports.dart deleted file mode 100644 index 750dc140f..000000000 --- a/test/integration/avoid_relative_lib_imports.dart +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2020, 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:io'; - -import 'package:analyzer/src/lint/io.dart'; -import 'package:linter/src/analyzer.dart'; -import 'package:linter/src/cli.dart' as cli; -import 'package:test/test.dart'; - -import '../mocks.dart'; -import '../test_constants.dart'; - -void main() { - group('avoid_relative_lib_imports', () { - var currentOut = outSink; - var collectingOut = CollectingSink(); - setUp(() { - exitCode = 0; - outSink = collectingOut; - }); - tearDown(() { - collectingOut.buffer.clear(); - outSink = currentOut; - exitCode = 0; - }); - - test('avoid relative lib imports', () async { - await cli.runLinter([ - '$integrationTestDir/avoid_relative_lib_imports', - '--rules=avoid_relative_lib_imports', - ], LinterOptions()); - expect( - collectingOut.trim(), - stringContainsInOrder( - ['main.dart 3:8', '2 files analyzed, 1 issue found, in'])); - expect(exitCode, 1); - }); - }); -} diff --git a/test/integration_test.dart b/test/integration_test.dart index e3f976bba..6a7c60bc6 100644 --- a/test/integration_test.dart +++ b/test/integration_test.dart @@ -15,8 +15,6 @@ import 'package:yaml/yaml.dart'; import '../test_data/rules/experiments/experiments.dart'; import 'integration/always_require_non_null_named_parameters.dart' as always_require_non_null_named_parameters; -import 'integration/avoid_relative_lib_imports.dart' - as avoid_relative_lib_imports; import 'integration/avoid_web_libraries_in_flutter.dart' as avoid_web_libraries_in_flutter; import 'integration/close_sinks.dart' as close_sinks; @@ -163,7 +161,6 @@ void ruleTests() { lines_longer_than_80_chars.main(); always_require_non_null_named_parameters.main(); prefer_const_constructors_in_immutables.main(); - avoid_relative_lib_imports.main(); public_member_api_docs.main(); secure_pubspec_urls.main(); sort_pub_dependencies.main(); diff --git a/test/rules/all.dart b/test/rules/all.dart index a813c601d..c04430db4 100644 --- a/test/rules/all.dart +++ b/test/rules/all.dart @@ -16,6 +16,7 @@ import 'avoid_private_typedef_functions_test.dart' as avoid_private_typedef_functions; import 'avoid_redundant_argument_values_test.dart' as avoid_redundant_argument_values; +import 'avoid_relative_lib_imports_test.dart' as avoid_relative_lib_imports; import 'avoid_renaming_method_parameters_test.dart' as avoid_renaming_method_parameters; import 'avoid_returning_this_test.dart' as avoid_returning_this; @@ -116,6 +117,7 @@ void main() { avoid_init_to_null.main(); avoid_private_typedef_functions.main(); avoid_redundant_argument_values.main(); + avoid_relative_lib_imports.main(); avoid_renaming_method_parameters.main(); avoid_returning_this.main(); avoid_setters_without_getters.main(); diff --git a/test/rules/avoid_relative_lib_imports_test.dart b/test/rules/avoid_relative_lib_imports_test.dart new file mode 100644 index 000000000..1e3fa8a12 --- /dev/null +++ b/test/rules/avoid_relative_lib_imports_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2023, 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(AvoidRelativeLibImportsTest); + }); +} + +@reflectiveTest +class AvoidRelativeLibImportsTest extends LintRuleTest { + @override + bool get addJsPackageDep => true; + + @override + String get lintRule => 'avoid_relative_lib_imports'; + + test_externalPackage() async { + await assertNoDiagnostics(r''' +/// This provides [JS]. +import 'package:js/js.dart'; +'''); + } + + test_samePackage_relativeUri() async { + newFile('$testPackageLibPath/lib.dart', r''' +class C {} +'''); + var test = newFile('$testPackageRootPath/test/test.dart', r''' +/// This provides [C]. +import '../lib/lib.dart'; +'''); + var lib2Result = await resolveFile(test.path); + await assertDiagnosticsIn(lib2Result.errors, [ + lint(30, 17), + ]); + } +} diff --git a/test_data/integration/avoid_relative_lib_imports/.dart_tool/package_config.json b/test_data/integration/avoid_relative_lib_imports/.dart_tool/package_config.json deleted file mode 100644 index 0a2d277fe..000000000 --- a/test_data/integration/avoid_relative_lib_imports/.dart_tool/package_config.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "p6", - "rootUri": "../../p6/", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generated": "2022-06-30T01:27:31.576781Z", - "generator": "pub", - "generatorVersion": "2.17.0" -} diff --git a/test_data/integration/avoid_relative_lib_imports/lib/dummy.dart b/test_data/integration/avoid_relative_lib_imports/lib/dummy.dart deleted file mode 100644 index e69de29bb..000000000 diff --git a/test_data/integration/avoid_relative_lib_imports/lib/main.dart b/test_data/integration/avoid_relative_lib_imports/lib/main.dart deleted file mode 100644 index e0c110918..000000000 --- a/test_data/integration/avoid_relative_lib_imports/lib/main.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:p6/p6_lib.dart'; //OK - -import '../lib/dummy.dart'; //LINT diff --git a/test_data/rules/avoid_relative_lib_imports.dart b/test_data/rules/avoid_relative_lib_imports.dart deleted file mode 100644 index 2665b972a..000000000 --- a/test_data/rules/avoid_relative_lib_imports.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2018, 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 avoid_relative_lib_imports` - -import '../integration/avoid_relative_lib_imports/lib/dummy.dart'; //LINT -import 'avoid_catching_errors.dart'; //OK -