diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/tslint/lib/linter.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/tslint/lib/linter.js')
-rw-r--r-- | node_modules/tslint/lib/linter.js | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/node_modules/tslint/lib/linter.js b/node_modules/tslint/lib/linter.js index 7662ed8d4..4c642d922 100644 --- a/node_modules/tslint/lib/linter.js +++ b/node_modules/tslint/lib/linter.js @@ -15,6 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); var fs = require("fs"); var path = require("path"); var ts = require("typescript"); @@ -48,14 +50,32 @@ var Linter = /** @class */ (function () { */ Linter.createProgram = function (configFile, projectDirectory) { if (projectDirectory === void 0) { projectDirectory = path.dirname(configFile); } - var config = ts.readConfigFile(configFile, ts.sys.readFile).config; + var config = ts.readConfigFile(configFile, ts.sys.readFile); + if (config.error !== undefined) { + throw new error_1.FatalError(ts.formatDiagnostics([config.error], { + getCanonicalFileName: function (f) { return f; }, + getCurrentDirectory: process.cwd, + getNewLine: function () { return "\n"; }, + })); + } var parseConfigHost = { fileExists: fs.existsSync, readDirectory: ts.sys.readDirectory, readFile: function (file) { return fs.readFileSync(file, "utf8"); }, useCaseSensitiveFileNames: true, }; - var parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory), { noEmit: true }); + var parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(projectDirectory), { noEmit: true }); + if (parsed.errors !== undefined) { + // ignore warnings and 'TS18003: No inputs were found in config file ...' + var errors = parsed.errors.filter(function (d) { return d.category === ts.DiagnosticCategory.Error && d.code !== 18003; }); + if (errors.length !== 0) { + throw new error_1.FatalError(ts.formatDiagnostics(errors, { + getCanonicalFileName: function (f) { return f; }, + getCurrentDirectory: process.cwd, + getNewLine: function () { return "\n"; }, + })); + } + } var host = ts.createCompilerHost(parsed.options, true); var program = ts.createProgram(parsed.fileNames, parsed.options, host); return program; @@ -65,7 +85,11 @@ var Linter = /** @class */ (function () { * files and excludes declaration (".d.ts") files. */ Linter.getFileNames = function (program) { - return program.getSourceFiles().map(function (s) { return s.fileName; }).filter(function (l) { return l.substr(-5) !== ".d.ts"; }); + return utils_1.mapDefined(program.getSourceFiles(), function (file) { + return file.fileName.endsWith(".d.ts") || program.isSourceFileFromExternalLibrary(file) + ? undefined + : file.fileName; + }); }; Linter.prototype.lint = function (fileName, source, configuration) { if (configuration === void 0) { configuration = configuration_1.DEFAULT_CONFIG; } @@ -93,16 +117,12 @@ var Linter = /** @class */ (function () { this.failures = this.failures.concat(fileFailures); }; Linter.prototype.getResult = function () { - var formatter; - var formattersDirectory = configuration_1.getRelativePath(this.options.formattersDirectory); var formatterName = this.options.formatter !== undefined ? this.options.formatter : "prose"; - var Formatter = formatterLoader_1.findFormatter(formatterName, formattersDirectory); - if (Formatter !== undefined) { - formatter = new Formatter(); - } - else { + var Formatter = formatterLoader_1.findFormatter(formatterName, this.options.formattersDirectory); + if (Formatter === undefined) { throw new Error("formatter '" + formatterName + "' not found"); } + var formatter = new Formatter(); var output = formatter.format(this.failures, this.fixes); var errorCount = this.failures.filter(function (failure) { return failure.getRuleSeverity() === "error"; }).length; return { @@ -179,10 +199,10 @@ var Linter = /** @class */ (function () { } catch (error) { if (error_1.isError(error) && error.stack !== undefined) { - error_1.showWarningOnce(error.stack); + error_1.showRuleCrashWarning(error.stack, rule.getOptions().ruleName, sourceFile.fileName); } else { - error_1.showWarningOnce(String(error)); + error_1.showRuleCrashWarning(String(error), rule.getOptions().ruleName, sourceFile.fileName); } return []; } @@ -198,7 +218,7 @@ var Linter = /** @class */ (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, .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)); + var INVALID_SOURCE_ERROR = utils_1.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.\n "], ["\n Invalid source file: ", ". Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.\n "])), fileName); throw new error_1.FatalError(INVALID_SOURCE_ERROR); } return sourceFile; @@ -206,15 +226,15 @@ var Linter = /** @class */ (function () { else { return utils.getSourceFile(fileName, source); } - var _a; }; - Linter.VERSION = "5.8.0"; + Linter.VERSION = "5.11.0"; Linter.findConfiguration = configuration_1.findConfiguration; Linter.findConfigurationPath = configuration_1.findConfigurationPath; Linter.getRulesDirectories = configuration_1.getRulesDirectories; Linter.loadConfigurationFromPath = configuration_1.loadConfigurationFromPath; return Linter; }()); +exports.Linter = Linter; function createMultiMap(inputs, getPair) { var map = new Map(); for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) { @@ -233,4 +253,4 @@ function createMultiMap(inputs, getPair) { } return map; } -module.exports = Linter; +var templateObject_1; |