From ea697517a02cf33e947a062c196b4b9a2bef5e14 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 25 Sep 2024 08:58:19 -0400 Subject: [PATCH 1/2] fix(linter): add files entry to angular flat config to avoid applying TS rules to JSON files --- e2e/angular/src/projects.test.ts | 3 ++ .../eslint-plugin/src/flat-configs/angular.ts | 30 ++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/e2e/angular/src/projects.test.ts b/e2e/angular/src/projects.test.ts index ac2d6f5b49185..d26e440034672 100644 --- a/e2e/angular/src/projects.test.ts +++ b/e2e/angular/src/projects.test.ts @@ -499,6 +499,9 @@ describe('Angular Projects', () => { `Building entry point '@${proj}/${lib}/${entryPoint}'` ); expect(buildOutput).toContain('Successfully ran target build'); + + expect(() => runCLI(`lint ${lib}`)).not.toThrow(); + expect(() => runCLI(`lint ${childLib}`)).not.toThrow(); }); it('should support generating libraries with a scoped name when --project-name-and-root-format=as-provided', () => { diff --git a/packages/eslint-plugin/src/flat-configs/angular.ts b/packages/eslint-plugin/src/flat-configs/angular.ts index 12880957aa35f..e0abe64e0cf88 100644 --- a/packages/eslint-plugin/src/flat-configs/angular.ts +++ b/packages/eslint-plugin/src/flat-configs/angular.ts @@ -13,14 +13,24 @@ import tseslint from 'typescript-eslint'; * This configuration is intended to be combined with other configs from this * package. */ -export default tseslint.config(...angularEslint.configs.tsRecommended, { - languageOptions: { - globals: { - ...globals.browser, - ...globals.es2015, - ...globals.node, +export default tseslint.config( + ...angularEslint.configs.tsRecommended.map((c) => ({ + // Files need to be specified or else typescript-eslint rules will be + // applied to non-TS files. For example, buildable/publishable libs + // add rules to *.json files, and TS rules should not apply to them. + // See: https://github.com/nrwl/nx/issues/28069 + files: ['**/*.ts'], + ...c, + })), + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.es2015, + ...globals.node, + }, }, - }, - processor: angularEslint.processInlineTemplates, - plugins: { '@angular-eslint': angularEslint.tsPlugin }, -}); + processor: angularEslint.processInlineTemplates, + plugins: { '@angular-eslint': angularEslint.tsPlugin }, + } +); From a8b970635bdd730426e745aba1a65287c8783479 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 25 Sep 2024 12:32:43 -0400 Subject: [PATCH 2/2] fix(angular): update e2e tests --- e2e/angular/src/projects.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/angular/src/projects.test.ts b/e2e/angular/src/projects.test.ts index d26e440034672..f191fbe9d13bb 100644 --- a/e2e/angular/src/projects.test.ts +++ b/e2e/angular/src/projects.test.ts @@ -500,8 +500,8 @@ describe('Angular Projects', () => { ); expect(buildOutput).toContain('Successfully ran target build'); - expect(() => runCLI(`lint ${lib}`)).not.toThrow(); - expect(() => runCLI(`lint ${childLib}`)).not.toThrow(); + expect(() => runCLI(`lint ${lib} --fix`)).not.toThrow(); + expect(() => runCLI(`lint ${childLib} --fix`)).not.toThrow(); }); it('should support generating libraries with a scoped name when --project-name-and-root-format=as-provided', () => {