feat(typescript): respect excluded globs in tslint (#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/
This commit is contained in:
John Franey
2018-11-19 04:02:04 -04:00
committed by Haoqun Jiang
parent 7d2b345af3
commit af4e498b6e
@@ -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