From 5d9c76bdec949ac8055e6b69f3bb36a7fb7ed651 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 17 Feb 2021 10:42:09 -0600 Subject: [PATCH] fix(angular): check for root tslint.json before updating to support ESlint (#4816) Closes #4761 --- .../src/generators/init/init.spec.ts | 7 ++++ .../workspace/src/generators/init/init.ts | 42 ++++++++++--------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/workspace/src/generators/init/init.spec.ts b/packages/workspace/src/generators/init/init.spec.ts index 951c5bf2f9c90..329b9c27e0a04 100644 --- a/packages/workspace/src/generators/init/init.spec.ts +++ b/packages/workspace/src/generators/init/init.spec.ts @@ -312,6 +312,13 @@ describe('workspace', () => { const prettierIgnore = tree.read('/.prettierignore').toString(); expect(prettierIgnore).toBe('# existing ignore rules'); }); + + it('should work with no root tslint.json', async () => { + tree.delete('/tslint.json'); + await initGenerator(tree, { name: 'myApp' }); + + expect(tree.exists('/tslint.json')).toBe(false); + }); }); describe('preserve angular cli layout', () => { diff --git a/packages/workspace/src/generators/init/init.ts b/packages/workspace/src/generators/init/init.ts index 4b72228276a84..8e9fae02a526a 100755 --- a/packages/workspace/src/generators/init/init.ts +++ b/packages/workspace/src/generators/init/init.ts @@ -294,27 +294,29 @@ function updateTsConfigsJson(host: Tree, options: Schema) { } function updateTsLint(host: Tree) { - updateJson(host, 'tslint.json', (tslintJson) => { - [ - 'no-trailing-whitespace', - 'one-line', - 'quotemark', - 'typedef-whitespace', - 'whitespace', - ].forEach((key) => { - tslintJson[key] = undefined; + if (host.exists(`tslint.json`)) { + updateJson(host, 'tslint.json', (tslintJson) => { + [ + 'no-trailing-whitespace', + 'one-line', + 'quotemark', + 'typedef-whitespace', + 'whitespace', + ].forEach((key) => { + tslintJson[key] = undefined; + }); + tslintJson.rulesDirectory = tslintJson.rulesDirectory || []; + tslintJson.rulesDirectory.push('node_modules/@nrwl/workspace/src/tslint'); + tslintJson.rules['nx-enforce-module-boundaries'] = [ + true, + { + allow: [], + depConstraints: [{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }], + }, + ]; + return tslintJson; }); - tslintJson.rulesDirectory = tslintJson.rulesDirectory || []; - tslintJson.rulesDirectory.push('node_modules/@nrwl/workspace/src/tslint'); - tslintJson.rules['nx-enforce-module-boundaries'] = [ - true, - { - allow: [], - depConstraints: [{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }], - }, - ]; - return tslintJson; - }); + } } function updateProjectTsLint(host: Tree, options: Schema) {