Skip to content

Commit 51da20a

Browse files
committed
Commandline options plumbing.
1 parent f9eb46a commit 51da20a

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

bin/lint.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import 'dart:io';
77
import 'package:args/args.dart';
88
import 'package:dart_lint/src/io.dart';
99

10-
1110
const processFileFailedExitCode = 65;
1211
const unableToProcessExitCode = 64;
1312

1413
isLinterErrorCode(int code) =>
1514
code == unableToProcessExitCode || code == processFileFailedExitCode;
1615

17-
1816
void main(List<String> args) {
1917
var parser = new ArgParser(allowTrailingOptions: true);
2018

21-
parser.addFlag(
22-
"help",
23-
abbr: "h",
24-
negatable: false,
25-
help: "Shows usage information.");
19+
parser
20+
..addFlag("help",
21+
abbr: "h", negatable: false, help: "Shows usage information.")
22+
..addOption('dart-sdk', help: 'Custom path to a Dart SDK.')
23+
..addOption('package-root',
24+
abbr: 'p',
25+
help: 'Custom package root. (Discouraged.) Remove to use package information computed by pub.');
2626

2727
var options;
2828
try {
@@ -48,7 +48,7 @@ void main(List<String> args) {
4848
var file = new File(path);
4949
if (file.existsSync()) {
5050
print("Linting $path...");
51-
if (!processFile(file)) {
51+
if (!lintFile(file)) {
5252
exitCode = processFileFailedExitCode;
5353
}
5454
} else {
@@ -59,14 +59,13 @@ void main(List<String> args) {
5959
}
6060

6161
void printUsage(ArgParser parser, [String error]) {
62-
6362
var message = "Lints Dart source files.";
6463
if (error != null) {
6564
message = error;
6665
}
6766

6867
stdout.write('''$message
69-
Usage: dartlint <files>
68+
Usage: lint <library_files>
7069
${parser.usage}
7170
7271
For more information, see https://github.com/dart-lang/dart_lint

lib/src/io.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:dart_lint/src/linter.dart';
1313
/// '.dart' extension.
1414
///
1515
/// Returns `true` if successful or `false` if an error occurred.
16-
bool processFile(FileSystemEntity file) {
16+
bool lintFile(FileSystemEntity file, {String dartSdkPath, String packageRoot}) {
1717
var path = file.path;
1818

1919
if (file is Link) {
@@ -27,6 +27,12 @@ bool processFile(FileSystemEntity file) {
2727
}
2828

2929
DartLinter linter = new DartLinter();
30+
if (dartSdkPath != null) {
31+
linter.options.dartSdkPath = dartSdkPath;
32+
}
33+
if (packageRoot != null) {
34+
linter.options.packageRootPath = packageRoot;
35+
}
3036

3137
try {
3238
linter.lintFile(file);

lib/src/linter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ abstract class DartLinter {
6565

6666
Iterable<AnalysisErrorInfo> lintLibrarySource(
6767
{String libraryName, String libraryContents});
68+
69+
LinterOptions get options;
6870
}
6971

7072
class Group {

0 commit comments

Comments
 (0)