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

no-deprecated-functions rule probably should try to find jest from its own directory upwards, not from cwd #886

Closed
billbalm opened this issue Sep 3, 2021 · 4 comments · Fixed by #889

Comments

@billbalm
Copy link

billbalm commented Sep 3, 2021

If we have multiple projects in a parent directory like this:

workspace/
├── project1/
│   └── node_modules/
│       ├── eslint/
│       ├── eslint-plugin-jest/
│       └── jest/
└── project2/
    └── node_modules/
        ├── eslint/
        ├── eslint-plugin-jest/
        └── jest/

Then if we run eslint in project1 from workspace folder, require.resolve throws
because from working directory it can't resolve jest/package.json. Now if we remove this line it
works obviously: https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/no-deprecated-functions.ts#L45

Easy to reproduce with @dbaeumer's plugin for VSCode.
If we open workspace folder above in VSCode, no-deprecated-functions rule throws.

Not sure if there's a strong reason to resolve jest from process.cwd(). If not, can we remove that line?

@G-Rath
Copy link
Collaborator

G-Rath commented Sep 12, 2021

It's because I was silly 😅 I can't remember why I actually included it, but I've tried it locally without and nothing seems to have broken so far.

I'm going to make a draft PR removing it - would you mind applying it to a few projects (ideally both monorepo and not) and seeing if it all still works? (both in any editor tools you use and from the command line)

@billbalm
Copy link
Author

Awesome @G-Rath

I tested it a bit on my end as well and it behaves okay.

Simply const jestPath = require.resolve('jest/package.json') resolves it to the nearest node_modules/jest folder by default and respects module.paths.

With NODE_PATH set, e.g. export NODE_PATH=$(node root -g), it even finds global jest if not locally installed.

Thanks

@github-actions
Copy link

🎉 This issue has been resolved in version 24.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 25.0.0-next.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants