From ba1d2a0814460fee01619cefa2294d6dac1decd2 Mon Sep 17 00:00:00 2001 From: John Franey Date: Thu, 15 Nov 2018 14:06:15 -0400 Subject: [PATCH] feat(typescript): respect excluded globs in tslint Updates `tslint.js` to respect `linterOptions.exclude`() from `tslint.json`. Previously, this configuration option was ignored in favour of the following list of globs: ``` ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx', 'tests/**/*.ts', 'tests/**/*.tsx'] ``` See: https://palantir.github.io/tslint/usage/configuration/ --- packages/@vue/cli-plugin-typescript/lib/tslint.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-typescript/lib/tslint.js b/packages/@vue/cli-plugin-typescript/lib/tslint.js index d14d0d8d9b..1d34f90a70 100644 --- a/packages/@vue/cli-plugin-typescript/lib/tslint.js +++ b/packages/@vue/cli-plugin-typescript/lib/tslint.js @@ -80,7 +80,9 @@ module.exports = function lint (args = {}, api, silent) { patchProgram(this.program) } - const config = tslint.Configuration.findConfiguration(api.resolve('tslint.json')).results + const tslintConfigPath = api.resolve('tslint.json') + + const config = tslint.Configuration.findConfiguration(tslintConfigPath).results // create a patched config that disables the blank lines rule, // so that we get correct line numbers in error reports for *.vue files. const vueConfig = Object.assign(config) @@ -108,6 +110,14 @@ module.exports = function lint (args = {}, api, silent) { ? args._ : ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx', 'tests/**/*.ts', 'tests/**/*.tsx'] + // respect linterOptions.exclude from tslint.json + if (config.linterOptions && config.linterOptions.exclude) { + // use the raw tslint.json data because config contains absolute paths + const rawTslintConfig = JSON.parse(fs.readFileSync(tslintConfigPath, 'utf-8')) + const excludedGlobs = rawTslintConfig.linterOptions.exclude + excludedGlobs.forEach((g) => files.push('!' + g)) + } + return globby(files, { cwd }).then(files => { files.forEach(lint) if (silent) return