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] no-extraneous-dependencies: allow incorrect paths in packageDir #3012

Merged

Conversation

chabb
Copy link

@chabb chabb commented Jun 3, 2024

This rule can potentially fails ( = reports incorrect errors ) in a monorepo settings; this is due to the fact that the building of the map of the available installed dependencies stops when there is an error ( e.g when the path to the package.json does not point to an existing package.json file )

  • If you pass only one path to a package.json file, then this path should be correct, this is ok
  • If you pass multiple paths, there are some situations when those paths point to a wrong path, this happens typically in a nx monorepo. The problem is that the parsing of the package.json files stop is one of the path is wrong, and then the rule will give us false positive. One example is a nx monorepo with a pre-commit hook that runs eslint
    -- NX will run eslint in the projects folder, so we need to grab the root package.json
    -- The pre-commit hook will run eslint in the root folder, so one of the path given will be an incorrect path, but we do not want to throw there, otherwise the rull will fail

- If you pass only one path to a package.json file, then this path
should be correct
- If you pass multiple paths, there are some situations when those paths
point to a wrong path, this happens typically in a nx monorepo with husky
-- NX will run eslint in the projects folder, so we need to grab the
root package.json
-- Husky will run in the root folder, so one of the path given will be
an incorrect path, but we do not want throw there, otherwise the rull
will fail
@chabb chabb changed the title [fix] no-extraneous-dependencies allow wrong path [fix] no-extraneous-dependencies allow incorrect paths in packageDir Jun 3, 2024
@chabb chabb force-pushed the fix/allow-incorrect-path-if-mulitple-paths branch from 11aebc1 to f0c9fd2 Compare June 3, 2024 11:57
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.90%. Comparing base (6554bd5) to head (f0c9fd2).

Current head f0c9fd2 differs from pull request most recent head fc361a9

Please upload reports for the commit fc361a9 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3012      +/-   ##
==========================================
+ Coverage   95.87%   95.90%   +0.03%     
==========================================
  Files          78       78              
  Lines        3293     3296       +3     
  Branches     1156     1158       +2     
==========================================
+ Hits         3157     3161       +4     
+ Misses        136      135       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danymarques
Copy link

Would be nice to have this merged! We also have issues with this.

@alaingiller
Copy link

Same here, this rule doesn't work in a nx monorepo setup

@hedinfaok
Copy link

As a workaround, I run nx run-many -t lint in the repo root directory. The eslint config file is also in the repo root directory.

    'import/no-extraneous-dependencies': [
      'warn',
      {
        packageDir: [
          __dirname, // <root>/package.json
          process.cwd(), // <project>/package.json
        ],
      },
    ],

@ljharb ljharb force-pushed the fix/allow-incorrect-path-if-mulitple-paths branch from f0c9fd2 to fc361a9 Compare June 25, 2024 06:30
@ljharb ljharb changed the title [fix] no-extraneous-dependencies allow incorrect paths in packageDir [Fix] no-extraneous-dependencies: allow incorrect paths in packageDir Jun 25, 2024
@ljharb ljharb merged commit fc361a9 into import-js:main Jun 25, 2024
309 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants