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

Commit

Permalink
Handle custom rules directories correctly when using --test (#1195)
Browse files Browse the repository at this point in the history
* rulesDirectory is resolved relative to location of tslint.json file
* --rules-dir CLI option is not ignored

Fixes #1178
  • Loading branch information
jkillian committed May 3, 2016
1 parent a1071e6 commit 193de54
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export interface TestResult {
};
}

export function runTest(testDirectory: string): TestResult {
export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult {
const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`));
const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8"));
const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null);
const results: TestResult = { directory: testDirectory, results: {} };

for (const fileToLint of filesToLint) {
Expand All @@ -54,7 +54,7 @@ export function runTest(testDirectory: string): TestResult {
configuration: tslintConfig,
formatter: "prose",
formattersDirectory: "",
rulesDirectory: "",
rulesDirectory,
};
const linter = new Linter(fileBasename, fileTextWithoutMarkup, lintOptions);
const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ if (argv.i != null) {
}

if (argv.test != null) {
const results = runTest(argv.test);
const results = runTest(argv.test, argv.r);
const didAllTestsPass = consoleTestResultHandler(results);
process.exit(didAllTestsPass ? 0 : 1);
}
Expand Down
7 changes: 7 additions & 0 deletions test/check-bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ expectOut $? 0 "tslint --test did not exit correctly for a passing test"
./bin/tslint --test test/files/incorrect-rule-test
expectOut $? 1 "tslint --test did not exit correctly for a failing test"

# ensure --test command works correctly with custom rules
./bin/tslint --test test/files/custom-rule-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules"

./bin/tslint -r test/files/custom-rules-2 --test test/files/custom-rule-cli-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules from the CLI"

if [ $num_failures != 0 ]; then
echo "Failed $num_failures tests"
exit 1
Expand Down
1 change: 1 addition & 0 deletions test/files/custom-rule-cli-rule-test/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = 5;
5 changes: 5 additions & 0 deletions test/files/custom-rule-cli-rule-test/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-fail": true
}
}
1 change: 1 addition & 0 deletions test/files/custom-rule-rule-test/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = 5;
6 changes: 6 additions & 0 deletions test/files/custom-rule-rule-test/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rulesDirectory": "../custom-rules-2",
"rules": {
"no-fail": true
}
}

0 comments on commit 193de54

Please sign in to comment.