Skip to content

Commit

Permalink
fix(linter): add files entry to angular flat config to avoid applying…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
2 people authored and FrozenPandaz committed Sep 26, 2024
1 parent 77d8387 commit 25c6f2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions e2e/angular/src/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 projects with --project-name-and-root-format=derived', () => {
Expand Down
30 changes: 20 additions & 10 deletions packages/eslint-plugin/src/flat-configs/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
);

0 comments on commit 25c6f2c

Please sign in to comment.