Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Fix multiple --exclude arguments (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff authored and adidahiya committed Jun 1, 2017
1 parent b9c62b1 commit 1d8d928
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Option {
short?: string;
// Commander will camelCase option names.
name: keyof Argv | "rules-dir" | "formatters-dir" | "type-check";
type: "string" | "boolean";
type: "string" | "boolean" | "array";
describe: string; // Short, used for usage message
description: string; // Long, used for `--help`
}
Expand Down Expand Up @@ -74,7 +74,7 @@ const options: Option[] = [
{
short: "e",
name: "exclude",
type: "string",
type: "array",
describe: "exclude globs from path expansion",
description: dedent`
A filename or glob which indicates files to exclude from linting.
Expand Down Expand Up @@ -187,9 +187,18 @@ const options: Option[] = [
},
];

function collect(val: string, memo: string[]) {
memo.push(val);
return memo;
}

for (const option of options) {
const commanderStr = optionUsageTag(option) + (option.type === "string" ? ` [${option.name}]` : "");
commander.option(commanderStr, option.describe);
const commanderStr = optionUsageTag(option) + optionParam(option);
if (option.type === "array") {
commander.option(commanderStr, option.describe, collect, []);
} else {
commander.option(commanderStr, option.describe);
}
}

commander.on("--help", () => {
Expand Down Expand Up @@ -249,3 +258,14 @@ run({
function optionUsageTag({short, name}: Option) {
return short !== undefined ? `-${short}, --${name}` : `--${name}`;
}

function optionParam(option: Option) {
switch (option.type) {
case "string":
return ` [${option.name}]`;
case "array":
return ` <${option.name}>`;
case "boolean":
return "";
}
}
13 changes: 13 additions & 0 deletions test/executable/executableTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) {
done();
});
});

it("can handle multiple '--exclude' globs", (done) => {
execCli(
[
"-c", "test/files/multiple-excludes/tslint.json",
"--exclude", "'test/files/multiple-excludes/invalid.test.ts'",
"--exclude", "'test/files/multiple-excludes/invalid2*'",
"'test/files/multiple-excludes/**.ts'",
], (err) => {
assert.isNull(err, "process should exit without an error");
done();
});
});
});

describe("--type-check", () => {
Expand Down
1 change: 1 addition & 0 deletions test/files/multiple-excludes/invalid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = 42
1 change: 1 addition & 0 deletions test/files/multiple-excludes/invalid2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
5 changes: 5 additions & 0 deletions test/files/multiple-excludes/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"semicolon": [true, "always"]
}
}
1 change: 1 addition & 0 deletions test/files/multiple-excludes/valid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = 42;

0 comments on commit 1d8d928

Please sign in to comment.