Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): always use project level tsconfigs with eslint #4657

Merged
merged 16 commits into from
Mar 5, 2021

Conversation

JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented Jan 31, 2021

Current Behavior

Currently, for non-Angular projects, we do not set the "project" parser option for typescript-eslint on an Nx project level, and therefore when ESLint runs on a project it is delegating up to the setting at the root.

As as result the TypeScript Program that gets created behind the scenes for the linting of applicable Nx projects scales with the size of the workspace instead of the size of the project. For large workspaces this is a significant overhead.

Expected Behavior

This PR changes things to always apply the "project" parser option on a project level, thus ensuring more efficient lint runs in terms of speed and memory pressure.

In testing this on 1 generated repo and 1 real-world (larger but still only "medium sized") workspace I have seen speed improvements of linting all projects be between 25-300%. For large workspaces the improvements should be even greater.

ADDITIONAL NOTES:

  • As you can see in the commits, before I began to make changes, I also increased the coverage of eslint config file contents so that we have greater confidence in both this change and any future tweaks we make.

  • In order to get this to work for all project types I also had to fix an existing inconsistency in the tsconfig.app.json files of Gatsby and Next projects vs their tsconfig.spec.json and workspace.json configs. For those two types (and only those two types), they included globs for .js(x) everywhere except their tsconfig.app.json. I walked Victor through this and he agreed we should make it consistent.

Related Issue(s)

Fixes #

@JamesHenry
Copy link
Collaborator Author

This improvement is substantial enough that we should think about adding a migration for it.

Fortunately, because everything currently works as is, it is not critical to include it straight away, but @FrozenPandaz I will let you make the call on whether or not you want the migration included in this PR, or it should go in a follow up.

@JamesHenry JamesHenry marked this pull request as ready for review February 2, 2021 11:23
@FrozenPandaz
Copy link
Collaborator

This improvement is substantial

Indeed! This shaved off 2s when linting workspace in this repo! 😄

we should think about adding a migration for it

I agree, please add the migration in this PR so that we can test it together and it gets released together.

"parserOptions": Object {
"project": Array [
"apps/my-app/tsconfig.*?.json",
expect(eslintConfig).toMatchInlineSnapshot(`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is purely the change to make the snapshot to capture the whole config, instead of just overrides

"parserOptions": Object {
"project": Array [
"libs/my-lib/tsconfig.*?.json",
expect(eslintConfig).toMatchInlineSnapshot(`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is purely the change to make the snapshot to capture the whole config, instead of just overrides

expect(eslintrcJson.extends).toContain('plugin:cypress/recommended');

const eslintrcJson = readJson(tree, 'apps/my-app-e2e/.eslintrc.json');
expect(eslintrcJson).toMatchInlineSnapshot(`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is purely the change to make the snapshot to capture the whole config, instead of just extends

expect(packageJson).toMatchObject({
devDependencies: {
'eslint-plugin-react': expect.anything(),
'eslint-plugin-react-hooks': expect.anything(),
},
});

const eslintJson = readJsonInTree(tree, '/apps/my-app/.eslintrc.json');
expect(eslintJson).toMatchInlineSnapshot(`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is purely the change to make the snapshot to capture the whole config, instead of just extends

@JamesHenry
Copy link
Collaborator Author

Ready for final review!

@binary64
Copy link

What about packages/cypress/src/generators/cypress-project/cypress-project.spec.ts:265, seems a hardcoded value

@FrozenPandaz
Copy link
Collaborator

What about packages/cypress/src/generators/cypress-project/cypress-project.spec.ts:265

Sorry, I'm not sure what you mean.. it's hardcoded but it's a snapshot so jest can update it easily.

@FrozenPandaz FrozenPandaz merged commit 48c7c7b into nrwl:master Mar 5, 2021
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants