diff --git a/src/linter.ts b/src/linter.ts index 1ea133a65f5..89390c9eb16 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -64,7 +64,7 @@ class Linter { readFile: (file) => fs.readFileSync(file, "utf8"), useCaseSensitiveFileNames: true, }; - const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory)); + const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory), {noEmit: true}); const host = ts.createCompilerHost(parsed.options, true); const program = ts.createProgram(parsed.fileNames, parsed.options, host); diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 244bf48a222..468f0b571b7 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -367,7 +367,12 @@ function getUnusedCheckedProgram(program: ts.Program, checkParameters: boolean): } function makeUnusedCheckedProgram(program: ts.Program, checkParameters: boolean): ts.Program { - const options = { ...program.getCompilerOptions(), noUnusedLocals: true, ...(checkParameters ? { noUnusedParameters: true } : null) }; + const options = { + ...program.getCompilerOptions(), + noEmit: true, + noUnusedLocals: true, + ...(checkParameters ? { noUnusedParameters: true } : null), + }; const sourceFilesByName = new Map( program.getSourceFiles().map<[string, ts.SourceFile]>((s) => [getCanonicalFileName(s.fileName), s])); diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 40e5b081e09..2fe996bd49c 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -328,6 +328,16 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) { done(); }); }); + + it("can handles 'allowJs' correctly", (done) => { + execCli( + [ "-p", "test/files/tsconfig-allow-js/tsconfig.json"], + (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); }); describe("--type-check", () => { diff --git a/test/files/tsconfig-allow-js/testfile.test.js b/test/files/tsconfig-allow-js/testfile.test.js new file mode 100644 index 00000000000..7c6d6c73d3d --- /dev/null +++ b/test/files/tsconfig-allow-js/testfile.test.js @@ -0,0 +1 @@ +module.exports = {} \ No newline at end of file diff --git a/test/files/tsconfig-allow-js/tsconfig.json b/test/files/tsconfig-allow-js/tsconfig.json new file mode 100644 index 00000000000..6858b1bde18 --- /dev/null +++ b/test/files/tsconfig-allow-js/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "allowJs": true, + "noEmit": false + } +} \ No newline at end of file diff --git a/test/files/tsconfig-allow-js/tslint.json b/test/files/tsconfig-allow-js/tslint.json new file mode 100644 index 00000000000..8b3ddc16690 --- /dev/null +++ b/test/files/tsconfig-allow-js/tslint.json @@ -0,0 +1,8 @@ +{ + "jsRules": { + "eofline": true, + "semicolon": [ + true, "always" + ] + } +} \ No newline at end of file diff --git a/test/rules/strict-boolean-expressions/allow-boolean-undefined-union/test.ts.lint b/test/rules/strict-boolean-expressions/allow-boolean-undefined-union/test.ts.lint index 01cddf91ef4..1b97b9d01fd 100644 --- a/test/rules/strict-boolean-expressions/allow-boolean-undefined-union/test.ts.lint +++ b/test/rules/strict-boolean-expressions/allow-boolean-undefined-union/test.ts.lint @@ -7,9 +7,7 @@ if (get()) {} if (get()) {} if (get()) {} - ~~~~~~~~~~~ [err % ("'if' condition", 'is always truthy')] if (get()) {} - ~~~~~~~~~~~~~~~~~~ [err % ("'if' condition", 'is always truthy')] if (get()) {} ~~~~~~~~~~~~~~~~~~~~~~~~ [err % ("'if' condition", 'is always falsy')] if (get()) {}