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", "builder": "@nrwl/linter:eslint",
"options": Object { "options": Object {
"lintFilePatterns": Array [ "lintFilePatterns": Array [
"apps/testProject/something-ad-hoc/**/*.ts",
"apps/testProject/**/*.js", "apps/testProject/**/*.js",
"apps/testProject/**/*.jsx", "apps/testProject/**/*.jsx",
"apps/testProject/**/*.ts", "apps/testProject/**/*.ts",
"apps/testProject/**/*.tsx", "apps/testProject/**/*.tsx",
"apps/testProject/some-random-relative-file.ts", "apps/testProject/some-random-relative-file.ts",
"apps/testProject/something-ad-hoc/**/*.ts",
"apps/testProject/**/*.spec.ts", "apps/testProject/**/*.spec.ts",
"apps/testProject/**/*.spec.tsx", "apps/testProject/**/*.spec.tsx",
"apps/testProject/**/*.spec.js", "apps/testProject/**/*.spec.js",

View File

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