diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/linter.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/tslint/lib/linter.js')
-rw-r--r-- | node_modules/tslint/lib/linter.js | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/node_modules/tslint/lib/linter.js b/node_modules/tslint/lib/linter.js index e5581458a..85ec5b0cd 100644 --- a/node_modules/tslint/lib/linter.js +++ b/node_modules/tslint/lib/linter.js @@ -55,7 +55,7 @@ var Linter = (function () { readFile: function (file) { return fs.readFileSync(file, "utf8"); }, useCaseSensitiveFileNames: true, }; - var parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory)); + var parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory), { noEmit: true }); var host = ts.createCompilerHost(parsed.options, true); var program = ts.createProgram(parsed.fileNames, parsed.options, host); return program; @@ -81,9 +81,9 @@ var Linter = (function () { fileFailures = this.applyAllFixes(enabledRules, fileFailures, sourceFile, fileName); } // add rule severity to failures - var ruleSeverityMap = new Map(enabledRules.map(function (rule) { - return [rule.getOptions().ruleName, rule.getOptions().ruleSeverity]; - })); + var ruleSeverityMap = new Map(enabledRules.map( + // tslint:disable-next-line no-unnecessary-type-assertion + function (rule) { return [rule.getOptions().ruleName, rule.getOptions().ruleSeverity]; })); for (var _i = 0, fileFailures_1 = fileFailures; _i < fileFailures_1.length; _i++) { var failure = fileFailures_1[_i]; var severity = ruleSeverityMap.get(failure.getRuleName()); @@ -147,6 +147,7 @@ var Linter = (function () { // Only "protected" because a test directly accesses it. // tslint:disable-next-line member-ordering Linter.prototype.applyFixes = function (sourceFilePath, source, fixableFailures) { + var _this = this; var fixesByFile = createMultiMap(fixableFailures, function (f) { return [f.getFileName(), f.getFix()]; }); fixesByFile.forEach(function (fileFixes, filePath) { var fileNewSource; @@ -158,10 +159,17 @@ var Linter = (function () { var oldSource = fs.readFileSync(filePath, "utf-8"); fileNewSource = rule_1.Replacement.applyFixes(oldSource, fileFixes); } - fs.writeFileSync(filePath, fileNewSource, "utf-8"); + fs.writeFileSync(filePath, fileNewSource); + _this.updateProgram(filePath); }); return source; }; + Linter.prototype.updateProgram = function (sourceFilePath) { + if (this.program !== undefined && this.program.getSourceFile(sourceFilePath) !== undefined) { + var options = this.program.getCompilerOptions(); + this.program = ts.createProgram(this.program.getRootFileNames(), options, ts.createCompilerHost(options, true), this.program); + } + }; Linter.prototype.applyRule = function (rule, sourceFile) { try { if (this.program !== undefined && rule_1.isTypedRule(rule)) { @@ -172,11 +180,11 @@ var Linter = (function () { } } catch (error) { - if (error_1.isError(error)) { - error_1.showWarningOnce("Warning: " + error.message); + if (error_1.isError(error) && error.stack !== undefined) { + error_1.showWarningOnce(error.stack); } else { - console.warn("Warning: " + error); + error_1.showWarningOnce(String(error)); } return []; } @@ -192,12 +200,8 @@ var Linter = (function () { if (this.program !== undefined) { var sourceFile = this.program.getSourceFile(fileName); if (sourceFile === undefined) { - var INVALID_SOURCE_ERROR = (_a = ["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .js or .jsx extension.\n "], _a.raw = ["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .js or .jsx extension.\n "], utils_1.dedent(_a, fileName)); - throw new Error(INVALID_SOURCE_ERROR); - } - // check if the program has been type checked - if (!("resolvedModules" in sourceFile)) { - throw new Error("Program must be type checked before linting"); + var INVALID_SOURCE_ERROR = (_a = ["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.\n "], _a.raw = ["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.\n "], utils_1.dedent(_a, fileName)); + throw new error_1.FatalError(INVALID_SOURCE_ERROR); } return sourceFile; } @@ -206,13 +210,13 @@ var Linter = (function () { } var _a; }; + Linter.VERSION = "5.6.0"; + Linter.findConfiguration = configuration_1.findConfiguration; + Linter.findConfigurationPath = configuration_1.findConfigurationPath; + Linter.getRulesDirectories = configuration_1.getRulesDirectories; + Linter.loadConfigurationFromPath = configuration_1.loadConfigurationFromPath; return Linter; }()); -Linter.VERSION = "5.3.2"; -Linter.findConfiguration = configuration_1.findConfiguration; -Linter.findConfigurationPath = configuration_1.findConfigurationPath; -Linter.getRulesDirectories = configuration_1.getRulesDirectories; -Linter.loadConfigurationFromPath = configuration_1.loadConfigurationFromPath; function createMultiMap(inputs, getPair) { var map = new Map(); for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) { |