fix(linter): use the tsConfig option to find tsconfigs for eslint migration (#3853)

This commit is contained in:
Jason Jean 2020-10-02 10:42:34 -04:00 committed by GitHub
parent da6f987631
commit a8db1f787a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 16 deletions

View File

@ -121,12 +121,12 @@ describe('Update eslint builder and config for 10.3.0', () => {
"builder": "@nrwl/linter:eslint",
"options": Object {
"lintFilePatterns": Array [
"apps/testProject/something-ad-hoc/**/*.ts",
"apps/testProject/**/*.js",
"apps/testProject/**/*.jsx",
"apps/testProject/**/*.ts",
"apps/testProject/**/*.tsx",
"apps/testProject/some-random-relative-file.ts",
"apps/testProject/something-ad-hoc/**/*.ts",
"apps/testProject/**/*.spec.ts",
"apps/testProject/**/*.spec.tsx",
"apps/testProject/**/*.spec.js",

View File

@ -21,25 +21,48 @@ function updateESLintBuilder(host: Tree) {
const tsconfigs = [];
if (options.tsConfig) {
const normalizedTsConfigOption = Array.isArray(options.tsConfig)
? options.tsConfig
: [options.tsConfig];
normalizedTsConfigOption.forEach((tsConfigPath) => {
try {
tsconfigs.push(readJsonInTree(host, tsConfigPath as string));
} catch {}
try {
tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.json`));
} catch {}
});
} else {
try {
tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.json`));
} catch {}
try {
tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.app.json`));
tsconfigs.push(
readJsonInTree(host, `${project.root}/tsconfig.app.json`)
);
} catch {}
try {
tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.lib.json`));
tsconfigs.push(
readJsonInTree(host, `${project.root}/tsconfig.lib.json`)
);
} catch {}
try {
tsconfigs.push(
readJsonInTree(host, `${project.root}/tsconfig.spec.json`)
);
} catch {}
try {
tsconfigs.push(
readJsonInTree(host, `${project.root}/tsconfig.e2e.json`)
);
} catch {}
}
const defaultLintFilePatterns = [`${project.root}/**/*.ts`];
// Merge any available `includes` and `files` from the tsconfig files
const lintFilePatterns = !tsconfigs.length
let lintFilePatterns = !tsconfigs.length
? defaultLintFilePatterns
: tsconfigs
.map((tsconfig) => {
@ -48,6 +71,8 @@ function updateESLintBuilder(host: Tree) {
.reduce((flat, val) => flat.concat(val), [])
.map((pattern) => join(normalize(project.root), pattern));
lintFilePatterns = [...new Set(lintFilePatterns)];
return { lintFilePatterns };
}, '@nrwl/linter:lint');
}