Skip to content

Commit

Permalink
misc. tidying up (#4602)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored Jul 24, 2023
1 parent 9119243 commit 5fde37b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
16 changes: 4 additions & 12 deletions lib/src/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> paths) =>
paths.length == 1 && Directory(paths.first).existsSync()
? paths.first
Expand Down Expand Up @@ -123,9 +124,7 @@ Future runLinter(List<String> 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;
Expand All @@ -141,7 +140,7 @@ Future runLinter(List<String> 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),
);
}
Expand Down Expand Up @@ -177,10 +176,3 @@ $err
$stack''');
}
}

String _absoluteNormalizedPath(String path) {
var pathContext = PhysicalResourceProvider.INSTANCE.pathContext;
return pathContext.normalize(
pathContext.absolute(path),
);
}
8 changes: 8 additions & 0 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions test/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
6 changes: 4 additions & 2 deletions test/verify_reflective_test_suites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 5fde37b

Please sign in to comment.