|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +var tslint_1 = require("tslint"); |
| 4 | +var typescript_service_1 = require("typescript-service"); |
| 5 | +var languageService; |
| 6 | +exports.rules = { |
| 7 | + config: { |
| 8 | + meta: { |
| 9 | + docs: { |
| 10 | + description: 'Wraps a TSLint configuration and lints the whole source using TSLint', |
| 11 | + category: 'TSLint', |
| 12 | + }, |
| 13 | + fixable: false, |
| 14 | + schema: [ |
| 15 | + { |
| 16 | + type: 'object', |
| 17 | + properties: { |
| 18 | + rules: { |
| 19 | + type: 'object', |
| 20 | + additionalProperties: true, |
| 21 | + }, |
| 22 | + rulesDirectory: { |
| 23 | + type: 'array', |
| 24 | + items: { |
| 25 | + type: 'string', |
| 26 | + }, |
| 27 | + }, |
| 28 | + configFile: { |
| 29 | + type: 'string', |
| 30 | + }, |
| 31 | + compilerOptions: { |
| 32 | + type: 'object', |
| 33 | + additionalProperties: true, |
| 34 | + }, |
| 35 | + }, |
| 36 | + additionalProperties: false, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + create: function (context) { |
| 41 | + var fileName = context.getFilename(); |
| 42 | + var sourceCode = context.getSourceCode().text; |
| 43 | + var _a = context.options[0], tslintRules = _a.rules, tslintRulesDirectory = _a.rulesDirectory, configFile = _a.configFile, compilerOptions = _a.compilerOptions; |
| 44 | + var tslintOptions = { |
| 45 | + formatter: 'json', |
| 46 | + fix: false, |
| 47 | + rulesDirectory: tslintRulesDirectory, |
| 48 | + }; |
| 49 | + var rawConfig = {}; |
| 50 | + rawConfig.rules = tslintRules || {}; |
| 51 | + rawConfig.rulesDirectory = tslintRulesDirectory || []; |
| 52 | + var tslintConfig = tslint_1.Configuration.parseConfigFile(rawConfig); |
| 53 | + var program = undefined; |
| 54 | + if (fileName !== '<input>' && configFile) { |
| 55 | + if (!languageService) { |
| 56 | + languageService = typescript_service_1.createService({ configFile: configFile, compilerOptions: compilerOptions }); |
| 57 | + } |
| 58 | + program = languageService.getProgram(); |
| 59 | + } |
| 60 | + var tslint = new tslint_1.Linter(tslintOptions, program); |
| 61 | + tslint.lint(fileName, sourceCode, tslintConfig); |
| 62 | + var result = tslint.getResult(); |
| 63 | + if (result.failures && result.failures.length) { |
| 64 | + result.failures.forEach(function (failure) { |
| 65 | + var start = failure.getStartPosition().getLineAndCharacter(); |
| 66 | + var end = failure.getEndPosition().getLineAndCharacter(); |
| 67 | + context.report({ |
| 68 | + message: failure.getFailure() + " (tslint:" + failure.getRuleName() + ")", |
| 69 | + loc: { |
| 70 | + start: { |
| 71 | + line: start.line + 1, |
| 72 | + column: start.character, |
| 73 | + }, |
| 74 | + end: { |
| 75 | + line: end.line + 1, |
| 76 | + column: end.character, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }); |
| 80 | + }); |
| 81 | + } |
| 82 | + return {}; |
| 83 | + }, |
| 84 | + }, |
| 85 | +}; |
0 commit comments