fix(linter): add files entry to angular flat config to avoid applying TS rules to JSON files (#28102)

This PR fixes an issue with buildable/publishable Angular libs, where TS
rules are being applied to JSON files.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28069

---------

Co-authored-by: James Henry <james@henry.sc>
This commit is contained in:
Jack Hsu 2024-09-25 13:12:24 -04:00 committed by GitHub
parent 04cf92a58c
commit 7e1cf531ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 10 deletions

View File

@ -499,6 +499,9 @@ describe('Angular Projects', () => {
`Building entry point '@${proj}/${lib}/${entryPoint}'`
);
expect(buildOutput).toContain('Successfully ran target build');
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', () => {

View File

@ -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 },
}
);