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(linter): use swc over ts-node for workspace lint rule registration #8694

Merged
merged 3 commits into from
Jan 27, 2022

Conversation

meeroslav
Copy link
Contributor

Current Behavior

Expected Behavior

Related Issue(s)

Fixes #7758

@vercel
Copy link

vercel bot commented Jan 25, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/FCn7HRgixr6GnDMM2p5mVZ8SCx8d
✅ Preview: https://nx-dev-git-fork-meeroslav-fix-linter-7758-2-nrwl.vercel.app

[Deployment for 66f09d0 canceled]

Copy link
Collaborator

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

I think we can also replace tsconfig-paths with native swc-node capabilities based on seeing this PR and the issue it closed: swc-project/swc-node#608

Please could you explore that before we finalize this change?

@meeroslav
Copy link
Contributor Author

I think we can also replace tsconfig-paths with native swc-node capabilities based on seeing this PR and the issue it closed: Brooooooklyn/swc-node#608

Please could you explore that before we finalize this change?

Turns out @swc-node/register already handles the paths, so that entire code block was obsolete.

@JamesHenry
Copy link
Collaborator

JamesHenry commented Jan 26, 2022

@meeroslav cool just AFK right now but do we have an e2e test which covers using a workspace lib in rule to ensure it is working as before? The tsconfig-paths dep is still in there FYI, it can probably be removed now

@meeroslav
Copy link
Contributor Author

@JamesHenry, I removed the tsconfig-paths, thanks for the reminder.

We do have an E2E test which checks if the workspace-lint is working.

Additionally, I used this rule to test if the using workspace projects and nrwl/* packages in rules work. Is there something else that should be checked?

Copy link
Collaborator

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Yes, we need to ensure that we can users can use utilities from their own Nx workspaces in their lint rules.

I have done a local build using this branch in order to create a workspace and that use-case is no longer working after this change, I'll ping you to walk you through it

try {
/**
* Currently we only support applying the rules from the user's workspace plugin object
* (i.e. not other things that plugings can expose like configs, processors etc)
*/
const { rules } = require(WORKSPACE_PLUGIN_DIR);

if (registrationCleanup) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking out loud, maybe this should come in a finally {} block so that it still happens in the error case? Not sure how much leakage is likely to occur with this though, so maybe it's not actually not an issue...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's very unlikely that registration succeeds but requiring the project fails, but I guess it's better be safe than sorry.

In the previous version we never did the cleanup at all, and we never noticed any leaks.
I realised that by doing the cleanup we save few hundred milliseconds per run. I haven't had time to investigate why.

@@ -315,7 +335,32 @@ function updateGeneratedRuleImplementation(

return ts.visitEachChild(node, visit, context);
}
return ts.visitNode(rootNode, visit);
/**
* Add lib import as a first line of the rule file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please could we add the "why" behind this for the benefit of other engineers who weren't directly involved in this PR? It might not be clear why we felt this was important

@meeroslav meeroslav merged commit 541d4e2 into nrwl:master Jan 27, 2022
@meeroslav meeroslav deleted the fix/linter-7758-2 branch January 27, 2022 15:55
@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 19, 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.

creating a single @nrwl/linter:workspace-rule slows down eslint / linting significantly
3 participants