Skip to content

Commit

Permalink
Trim single quotes from files and exclusion globs. Addresses palantir…
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMH committed Nov 4, 2016
1 parent 0f72c61 commit bfdfb62
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
DEFAULT_CONFIG,
findConfiguration,
} from "./configuration";
import {consoleTestResultHandler, runTest} from "./test";
import { consoleTestResultHandler, runTest } from "./test";
import * as Linter from "./tslintMulti";

let processed = optimist
Expand All @@ -49,6 +49,7 @@ let processed = optimist
e: {
alias: "exclude",
describe: "exclude globs from path expansion",
type: "string",
},
force: {
describe: "return status code 0 even if there are lint errors",
Expand Down Expand Up @@ -296,7 +297,19 @@ if (argv.project != null) {
}
}

const trimSingleQuotes = (str: string) => str.replace(/^'|'$/g, "");

let ignorePatterns: string[] = [];
if (argv.e) {
const excludeArguments: string[] = Array.isArray(argv.e) ? argv.e : [argv.e];

ignorePatterns = excludeArguments.map(trimSingleQuotes);
}

files = files
.map((file: string) => glob.sync(file, { ignore: argv.e, nodir: true }))
.reduce((a: string[], b: string[]) => a.concat(b));
// remove single quotes which break mathing on Windows when glob is passed in single quotes
.map(trimSingleQuotes)
.map((file: string) => glob.sync(file, { ignore: ignorePatterns, nodir: true }))
.reduce((a: string[], b: string[]) => a.concat(b));

processFiles(files, program);
29 changes: 29 additions & 0 deletions test/executable/executableTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,35 @@ describe("Executable", function() {

});
});

describe("globs and quotes", () => {
// when glob pattern is passed without quotes in npm script `process.env` will contain:
// on Windows - pattern string without any quotes
// on Linux - list of files that mathes glob (may differ from `glob` module results)

it("exits with code 2 if correctly finds file containing lint errors when glob is in double quotes", (done) => {
// when glob pattern is passed in double quotes in npm script `process.env` will contain:
// on Windows - pattern string without any quotes
// on Linux - pattern string without any quotes (glob is not expanded)
execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/**/tslint.ts"], (err) => {
assert.isNotNull(err, "process should exit with error");
assert.strictEqual(err.code, 2, "error code should be 2");
done();
});
});

it("exits with code 2 if correctly finds file containing lint errors when glob is in single quotes", (done) => {
// when glob pattern is passed in single quotes in npm script `process.env` will contain:
// on Windows - pattern string wrapped in single quotes
// on Linux - pattern string without any quotes (glob is not expanded)
execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "'src/**/tslint.ts'"], (err) => {
assert.isNotNull(err, "process should exit with error");
assert.strictEqual(err.code, 2, "error code should be 2");
done();
});
});

});
});

type ExecFileCallback = (error: any, stdout: string, stderr: string) => void;
Expand Down

0 comments on commit bfdfb62

Please sign in to comment.