Skip to content

Commit af4e498

Browse files
johnfraneyhaoqunjiang
authored andcommitted
feat(typescript): respect excluded globs in tslint (vuejs#2961)
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/
1 parent 7d2b345 commit af4e498

File tree

1 file changed

+11
-1
lines changed
  • packages/@vue/cli-plugin-typescript/lib

1 file changed

+11
-1
lines changed

packages/@vue/cli-plugin-typescript/lib/tslint.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ module.exports = function lint (args = {}, api, silent) {
8080
patchProgram(this.program)
8181
}
8282

83-
const config = tslint.Configuration.findConfiguration(api.resolve('tslint.json')).results
83+
const tslintConfigPath = api.resolve('tslint.json')
84+
85+
const config = tslint.Configuration.findConfiguration(tslintConfigPath).results
8486
// create a patched config that disables the blank lines rule,
8587
// so that we get correct line numbers in error reports for *.vue files.
8688
const vueConfig = Object.assign(config)
@@ -108,6 +110,14 @@ module.exports = function lint (args = {}, api, silent) {
108110
? args._
109111
: ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx', 'tests/**/*.ts', 'tests/**/*.tsx']
110112

113+
// respect linterOptions.exclude from tslint.json
114+
if (config.linterOptions && config.linterOptions.exclude) {
115+
// use the raw tslint.json data because config contains absolute paths
116+
const rawTslintConfig = JSON.parse(fs.readFileSync(tslintConfigPath, 'utf-8'))
117+
const excludedGlobs = rawTslintConfig.linterOptions.exclude
118+
excludedGlobs.forEach((g) => files.push('!' + g))
119+
}
120+
111121
return globby(files, { cwd }).then(files => {
112122
files.forEach(lint)
113123
if (silent) return

0 commit comments

Comments
 (0)