Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Update linter to use new driver-based engine (#743). #754

Merged
merged 8 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions bin/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// 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';
import 'dart:io';
import 'dart:math' as math;

import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/lint/config.dart';
import 'package:analyzer/src/lint/io.dart';
Expand All @@ -16,8 +18,8 @@ import 'package:linter/src/analyzer.dart';
import 'package:linter/src/formatter.dart';
import 'package:linter/src/rules.dart';

void main(List<String> args) {
runLinter(args, new LinterOptions());
Future main(List<String> args) async {
await runLinter(args, new LinterOptions());
}

const processFileFailedExitCode = 65;
Expand All @@ -27,7 +29,7 @@ const unableToProcessExitCode = 64;
String getRoot(List<String> paths) =>
paths.length == 1 && new Directory(paths[0]).existsSync() ? paths[0] : null;

isLinterErrorCode(int code) =>
bool isLinterErrorCode(int code) =>
code == unableToProcessExitCode || code == processFileFailedExitCode;

void printUsage(ArgParser parser, IOSink out, [String error]) {
Expand All @@ -44,7 +46,7 @@ For more information, see https://github.com/dart-lang/linter
''');
}

void runLinter(List<String> args, LinterOptions initialLintOptions) {
Future runLinter(List<String> args, LinterOptions initialLintOptions) async {
// Force the rule registry to be populated.
registerLintRules();

Expand Down Expand Up @@ -150,7 +152,7 @@ void runLinter(List<String> args, LinterOptions initialLintOptions) {

lintOptions
..packageConfigPath = packageConfigFile
..visitTransitiveClosure = options['visit-transitive-closure'];
..resourceProvider = PhysicalResourceProvider.INSTANCE;

List<File> filesToLint = [];
for (var path in options.rest) {
Expand All @@ -166,7 +168,7 @@ void runLinter(List<String> args, LinterOptions initialLintOptions) {

try {
final timer = new Stopwatch()..start();
List<AnalysisErrorInfo> errors = linter.lintFiles(filesToLint);
List<AnalysisErrorInfo> errors = await linter.lintFiles(filesToLint);
timer.stop();

if (errors.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage: https://github.com/dart-lang/linter
environment:
sdk: '>=1.12.0 <2.0.0-dev.infinity'
dependencies:
analyzer: ^0.30.0
analyzer: ^0.31.0-alpha.0
args: '>=0.12.1 <0.14.0'
glob: ^1.0.3
meta: ^1.0.2
Expand All @@ -20,5 +20,5 @@ dev_dependencies:
matcher: ^0.12.0
mockito: ^1.0.0
path: '>=0.9.0 <2.0.0'
test: ^0.12.0
test: ^0.12.24+1
unscripted: ^0.6.2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2017, 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.
library dummy_lib;

import 'dummy.dart';

Expand Down
27 changes: 14 additions & 13 deletions test/engine_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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';
import 'dart:io';

import 'package:analyzer/dart/ast/ast.dart' show AstNode, AstVisitor;
Expand All @@ -26,7 +27,7 @@ main() {
}

/// Linter engine tests
void defineLinterEngineTests() {
Future defineLinterEngineTests() {
group('engine', () {
group('reporter', () {
_test(String label, String expected, report(PrintingReporter r)) {
Expand Down Expand Up @@ -147,39 +148,39 @@ void defineLinterEngineTests() {
exitCode = 0;
errorSink = stderr;
});
test('smoke', () {
test('smoke', () async {
FileSystemEntity firstRuleTest =
new Directory(ruleDir).listSync().firstWhere((f) => isDartFile(f));
dartlint.main([firstRuleTest.path]);
await dartlint.main([firstRuleTest.path]);
expect(dartlint.isLinterErrorCode(exitCode), isFalse);
});
test('no args', () {
dartlint.main([]);
test('no args', () async {
await dartlint.main([]);
expect(exitCode, equals(dartlint.unableToProcessExitCode));
});
test('help', () {
dartlint.main(['-h']);
test('help', () async {
await dartlint.main(['-h']);
// Help shouldn't generate an error code
expect(dartlint.isLinterErrorCode(exitCode), isFalse);
});
test('unknown arg', () {
dartlint.main(['-XXXXX']);
test('unknown arg', () async {
await dartlint.main(['-XXXXX']);
expect(exitCode, equals(dartlint.unableToProcessExitCode));
});
test('custom sdk path', () {
test('custom sdk path', () async {
// Smoke test to ensure a custom sdk path doesn't sink the ship
FileSystemEntity firstRuleTest =
new Directory(ruleDir).listSync().firstWhere((f) => isDartFile(f));
var sdk = getSdkPath();
dartlint.main(['--dart-sdk', sdk, firstRuleTest.path]);
await dartlint.main(['--dart-sdk', sdk, firstRuleTest.path]);
expect(dartlint.isLinterErrorCode(exitCode), isFalse);
});
test('custom package root', () {
test('custom package root', () async {
// Smoke test to ensure a custom package root doesn't sink the ship
FileSystemEntity firstRuleTest =
new Directory(ruleDir).listSync().firstWhere((f) => isDartFile(f));
var packageDir = new Directory('.').path;
dartlint.main(['--package-root', packageDir, firstRuleTest.path]);
await dartlint.main(['--package-root', packageDir, firstRuleTest.path]);
expect(dartlint.isLinterErrorCode(exitCode), isFalse);
});
});
Expand Down
78 changes: 39 additions & 39 deletions test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ defineTests() {
exitCode = 0;
});
group('config', () {
test('excludes', () {
dartlint
test('excludes', () async {
await dartlint
.main(['test/_data/p2', '-c', 'test/_data/p2/lintconfig.yaml']);
expect(exitCode, 1);
expect(
collectingOut.trim(),
stringContainsInOrder(
['4 files analyzed, 1 issue found (2 filtered), in']));
});
test('overrrides', () {
dartlint
test('overrrides', () async {
await dartlint
.main(['test/_data/p2', '-c', 'test/_data/p2/lintconfig2.yaml']);
expect(exitCode, 0);
expect(collectingOut.trim(),
stringContainsInOrder(['4 files analyzed, 0 issues found, in']));
});
test('default', () {
dartlint.main(['test/_data/p2']);
test('default', () async {
await dartlint.main(['test/_data/p2']);
expect(exitCode, 1);
expect(collectingOut.trim(),
stringContainsInOrder(['4 files analyzed, 3 issues found, in']));
Expand All @@ -66,8 +66,8 @@ defineTests() {
collectingOut.buffer.clear();
outSink = currentOut;
});
test('bad pubspec', () {
dartlint.main(['test/_data/p3', 'test/_data/p3/_pubpspec.yaml']);
test('bad pubspec', () async {
await dartlint.main(['test/_data/p3', 'test/_data/p3/_pubpspec.yaml']);
expect(collectingOut.trim(),
startsWith('1 file analyzed, 0 issues found, in'));
});
Expand All @@ -80,10 +80,10 @@ defineTests() {
collectingOut.buffer.clear();
outSink = currentOut;
});
test('no warnings due to bad canonicalization', () {
test('no warnings due to bad canonicalization', () async {
var packagesFilePath =
new File('test/_data/p4/_packages').absolute.path;
dartlint.runLinter(['--packages', packagesFilePath, 'test/_data/p4'],
await dartlint.runLinter(['--packages', packagesFilePath, 'test/_data/p4'],
new LinterOptions([]));
expect(collectingOut.trim(),
startsWith('3 files analyzed, 0 issues found, in'));
Expand All @@ -103,9 +103,9 @@ defineTests() {
exitCode = 0;
});
group('.packages', () {
test('basic', () {
test('basic', () async {
// Requires .packages to analyze cleanly.
dartlint
await dartlint
.main(['test/_data/p5', '--packages', 'test/_data/p5/_packages']);
// Should have 0 issues.
expect(exitCode, 0);
Expand All @@ -127,8 +127,8 @@ defineTests() {
});

// https://github.com/dart-lang/linter/issues/246
test('overrides across libraries', () {
dartlint.main(
test('overrides across libraries', () async {
await dartlint.main(
['test/_data/overridden_fields', '--rules', 'overridden_fields']);
expect(exitCode, 1);
expect(
Expand All @@ -151,9 +151,9 @@ defineTests() {
exitCode = 0;
});

test('close sinks', () {
test('close sinks', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/close_sinks',
Expand Down Expand Up @@ -183,8 +183,8 @@ defineTests() {
exitCode = 0;
});

test('cancel subscriptions', () {
dartlint.main([
test('cancel subscriptions', () async {
await dartlint.main([
'test/_data/cancel_subscriptions',
'--rules=cancel_subscriptions'
]);
Expand Down Expand Up @@ -212,9 +212,9 @@ defineTests() {
exitCode = 0;
});

test('dart_directives_go_first', () {
test('dart_directives_go_first', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/dart_directives_go_first',
Expand All @@ -236,9 +236,9 @@ defineTests() {
]));
});

test('package_directives_before_relative', () {
test('package_directives_before_relative', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/package_directives_before_relative',
Expand All @@ -260,9 +260,9 @@ defineTests() {
]));
});

test('third_party_package_directives_before_own', () {
test('third_party_package_directives_before_own', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/third_party_package_directives_before_own',
Expand All @@ -284,15 +284,14 @@ defineTests() {
]));
});

test('export_directives_after_import_directives', () {
test('export_directives_after_import_directives', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/export_directives_after_import_directives',
'--rules=directives_ordering'
]);
expect(exitCode, 1);
expect(
collectingOut.trim(),
stringContainsInOrder([
Expand All @@ -302,11 +301,12 @@ defineTests() {
"export 'dummy2.dart'; // LINT",
'5 files analyzed, 2 issues found, in'
]));
expect(exitCode, 1);
});

test('sort_directive_sections_alphabetically', () {
test('sort_directive_sections_alphabetically', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/sort_directive_sections_alphabetically',
Expand Down Expand Up @@ -344,9 +344,9 @@ defineTests() {
]));
});

test('lint_one_node_no_more_than_once', () {
test('lint_one_node_no_more_than_once', () async {
var packagesFilePath = new File('.packages').absolute.path;
dartlint.main([
await dartlint.main([
'--packages',
packagesFilePath,
'test/_data/directives_ordering/lint_one_node_no_more_than_once',
Expand Down Expand Up @@ -376,8 +376,8 @@ defineTests() {
exitCode = 0;
});

test('only throw errors', () {
dartlint.main(
test('only throw errors', () async {
await dartlint.main(
['test/_data/only_throw_errors', '--rules=only_throw_errors']);
expect(exitCode, 1);
expect(
Expand Down Expand Up @@ -406,8 +406,8 @@ defineTests() {
exitCode = 0;
});

test('only throw errors', () {
dartlint.runLinter([
test('only throw errors', () async {
await dartlint.runLinter([
'test/_data/always_require_non_null_named_parameters',
'--rules=always_require_non_null_named_parameters'
], new LinterOptions()..enableAssertInitializer = true);
Expand All @@ -432,8 +432,8 @@ defineTests() {
exitCode = 0;
});

test('only throw errors', () {
dartlint.runLinter([
test('only throw errors', () async {
await dartlint.runLinter([
'test/_data/prefer_asserts_in_initializer_lists',
'--rules=prefer_asserts_in_initializer_lists'
], new LinterOptions()..enableAssertInitializer = true);
Expand All @@ -458,8 +458,8 @@ defineTests() {
exitCode = 0;
});

test('only throw errors', () {
dartlint.runLinter([
test('only throw errors', () async {
await dartlint.runLinter([
'test/_data/prefer_const_constructors_in_immutables',
'--rules=prefer_const_constructors_in_immutables'
], new LinterOptions()..enableAssertInitializer = true);
Expand Down
Loading