From 5fde37b0694efb7f58b14a1420f131b1f1d32eb6 Mon Sep 17 00:00:00 2001 From: Phil Quitslund Date: Mon, 24 Jul 2023 10:27:57 -0700 Subject: [PATCH] misc. tidying up (#4602) --- lib/src/cli.dart | 16 ++++------------ lib/src/extensions.dart | 8 ++++++++ test/all.dart | 6 ++++-- test/{util => }/annotation_test.dart | 2 +- test/verify_reflective_test_suites.dart | 6 ++++-- 5 files changed, 21 insertions(+), 17 deletions(-) rename test/{util => }/annotation_test.dart (98%) diff --git a/lib/src/cli.dart b/lib/src/cli.dart index 7ff84d694..544efa23b 100644 --- a/lib/src/cli.dart +++ b/lib/src/cli.dart @@ -11,12 +11,13 @@ import 'package:analyzer/src/lint/registry.dart'; // ignore: implementation_impo import 'package:args/args.dart'; import 'analyzer.dart'; +import 'extensions.dart'; import 'formatter.dart'; import 'rules.dart'; const processFileFailedExitCode = 65; - const unableToProcessExitCode = 64; + String? getRoot(List paths) => paths.length == 1 && Directory(paths.first).existsSync() ? paths.first @@ -123,9 +124,7 @@ Future runLinter(List args, LinterOptions initialLintOptions) async { } var packageConfigFile = options['packages'] as String?; - packageConfigFile = packageConfigFile != null - ? _absoluteNormalizedPath(packageConfigFile) - : null; + packageConfigFile = packageConfigFile?.toAbsoluteNormalizedPath(); var stats = options['stats'] as bool; var benchmark = options['benchmark'] as bool; @@ -141,7 +140,7 @@ Future runLinter(List args, LinterOptions initialLintOptions) async { for (var path in options.rest) { filesToLint.addAll( collectFiles(path) - .map((file) => _absoluteNormalizedPath(file.path)) + .map((file) => file.path.toAbsoluteNormalizedPath()) .map(File.new), ); } @@ -177,10 +176,3 @@ $err $stack'''); } } - -String _absoluteNormalizedPath(String path) { - var pathContext = PhysicalResourceProvider.INSTANCE.pathContext; - return pathContext.normalize( - pathContext.absolute(path), - ); -} diff --git a/lib/src/extensions.dart b/lib/src/extensions.dart index 5675c1508..64c9653d8 100644 --- a/lib/src/extensions.dart +++ b/lib/src/extensions.dart @@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:analyzer/src/dart/element/member.dart'; // ignore: implementation_imports import 'package:collection/collection.dart'; @@ -477,6 +478,13 @@ extension NullableAstNodeExtension on AstNode? { } } +extension StringExtension on String { + String toAbsoluteNormalizedPath() { + var pathContext = PhysicalResourceProvider.INSTANCE.pathContext; + return pathContext.normalize(pathContext.absolute(this)); + } +} + extension TokenExtension on Token? { bool get isFinal => this?.keyword == Keyword.FINAL; } diff --git a/test/all.dart b/test/all.dart index 9be63fd49..7b7987ef8 100644 --- a/test/all.dart +++ b/test/all.dart @@ -4,7 +4,8 @@ import 'package:analyzer/src/lint/io.dart'; -import 'ascii_utils_test.dart' as ascii_utils; +import 'annotation_test.dart' as annotation_test; +import 'ascii_utils_test.dart' as ascii_utils_test; import 'doc_test.dart' as doc_test; import 'engine_test.dart' as engine_test; import 'formatter_test.dart' as formatter_test; @@ -30,7 +31,8 @@ void main() { // Redirect output. outSink = MockIOSink(); - ascii_utils.main(); + annotation_test.main(); + ascii_utils_test.main(); doc_test.main(); engine_test.main(); formatter_test.main(); diff --git a/test/util/annotation_test.dart b/test/annotation_test.dart similarity index 98% rename from test/util/annotation_test.dart rename to test/annotation_test.dart index 1e7681772..0a1c4f074 100644 --- a/test/util/annotation_test.dart +++ b/test/annotation_test.dart @@ -6,7 +6,7 @@ import 'package:analyzer/error/error.dart'; import 'package:linter/src/test_utilities/annotation.dart'; import 'package:test/test.dart'; -import 'annotation_matcher.dart'; +import 'util/annotation_matcher.dart'; void main() { test('extraction', () { diff --git a/test/verify_reflective_test_suites.dart b/test/verify_reflective_test_suites.dart index 41c2eaada..30906f171 100644 --- a/test/verify_reflective_test_suites.dart +++ b/test/verify_reflective_test_suites.dart @@ -11,11 +11,13 @@ import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; +import 'test_constants.dart'; + void main() { group('check reflective test suites', () { group('rules', () { - var testDirPath = PhysicalResourceProvider.INSTANCE.pathContext - .absolute('test', 'rules'); + var testDirPath = + PhysicalResourceProvider.INSTANCE.pathContext.absolute(ruleTestDir); _VerifyTests(testDirPath).build(); }); });