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] auto-detect error with monorepo-like project structure #874

Closed
WORMSS opened this issue Aug 10, 2021 · 6 comments · Fixed by #889
Closed

[no-deprecated-functions] auto-detect error with monorepo-like project structure #874

WORMSS opened this issue Aug 10, 2021 · 6 comments · Fixed by #889

Comments

@WORMSS
Copy link

WORMSS commented Aug 10, 2021

Changing the auto detect from

const jestPath = require.resolve('jest/package.json', {
      paths: [process.cwd()]
    });

to

const jestPath = require.resolve('jest/package.json', {
      paths: [process.cwd(), __dirname]
    });

fixes the bug introduced 15 months ago with non-root level projects.

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 10, 2021

Could you provide some more details on the problem you're encountering and what your setup is?

@WORMSS
Copy link
Author

WORMSS commented Aug 10, 2021

The node_modules is not at the root of vscode.
We have many sub-projects that all work together, I've listed 3 below, but so far we have 13 and growing.

root/
 - projects/
   - core/
     - src/
     - package.json
   - web-core/
     - src/
     - package.json
   - web-core-unit-tests/
     - node_modules/ < where eslint is running eslint-plugin-jest from
     - src/
       - factories/
           - ListItemFactory.spec.ts < the file that throws a jest/no-deprecated-functions
     - package.json < the one that has jest as a dependency

image

Adding __dirname will allow require.resolve to go from

root/projects/web-core-unit-tests/node_modules/eslint-plugin-jest/lib/rules/ < search for jest.. NOPE
root/projects/web-core-unit-tests/node_modules/eslint-plugin-jest/lib/ < search for jest.. NOPE
root/projects/web-core-unit-tests/node_modules/eslint-plugin-jest/ < search for jest.. NOPE
root/projects/web-core-unit-tests/node_modules/ < search for jest.. NOPE
root/projects/web-core-unit-tests/ < search for jest.. YES.... (since this is where the package.json is)

instead of starting at root/projects (cwd) and working it's way down.. at that point, it's too late.

root/projects/ < search for jest... NOPE
root/ < search for jest... NOPE
/ < search for jest... NOPE... NOPE ALL THE WAY DOWN

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 10, 2021

Have a look at my comment here about this - specifically, in this setup you really should have these dev dependencies at the top level of your project, as tools & editors like VSCode will grab the first instance they can find of packages like eslint, and use that for all the nested projects which could give incorrect results if the versions are not consistent (vs running from the command line, which'll use the version installed per each project).

You can also specify the jest version explicitly - I'd say you should be able to easily write a basic hack to read that from the respective package.json if you're using an .eslintrc.js but tbh that might have the same issue when in VSCode.

I'm not outright against adding __dirname, but will need to do some thinking about it first to make sure it's not going to cause other problems - one thing in particular I'd like to look more into first is that IntelliJ doesn't have this issue with the same setup, so it's interesting that VSCode does.

Also, could you confirm the location of your eslint config in this structure?

@G-Rath G-Rath changed the title Fix auto detect error [no-deprecated-function] auto-detect error with monorepo-like project structure Aug 10, 2021
@G-Rath G-Rath changed the title [no-deprecated-function] auto-detect error with monorepo-like project structure [no-deprecated-functions] auto-detect error with monorepo-like project structure Aug 10, 2021
@WORMSS
Copy link
Author

WORMSS commented Aug 10, 2021

There is an .eslintrc.js in every root/projects/* folder..

module.exports = {
  root: true,
  extends: ['@yottaltd/eslint-config/lib/defaults', '@yottaltd/eslint-config/lib/unit-tests'],
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
};

As far as I can tell, they are all identical to the one above.

@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