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

Bug: nested plugins cannot be found when nested in a shared config (6.0.0) #11884

Closed
wants to merge 4 commits into from
Closed

Bug: nested plugins cannot be found when nested in a shared config (6.0.0) #11884

wants to merge 4 commits into from

Conversation

nevir
Copy link
Contributor

@nevir nevir commented Jun 23, 2019

TL;DR: if a shared config package has plugins that npm or yarn decides to install as descendents of it, those plugins cannot be found by the config factory.

This is a reproduction PR to highlight the issue—I haven't determined a fix yet, and would love pointers if you all have ideas!

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug report (template)

Tell us about your environment

  • ESLint Version: 6.0.0
  • Node Version: 10.15.1
  • npm Version: 6.9.0

Please show your full configuration:

See the fixtures for real files

Package Layout & Configuration

Package Tree:

<root>
  eslint-config-awesome
    awesome-parser
    eslint-plugin-awesome

<root>/.eslintrc.yml:

extends:
  - awesome

eslint-config-awesome/index.js:

module.exports = {
  parser: 'awesome-parser',
  plugins: ['awesome'],
  rules: {
    'awesome/is-awesome': [2]
  }
};

What did you do? Please include the actual source code causing the issue.

eslint any-file.js

What did you expect to happen?

Eslint would make it to linting the desired file

What actually happened? Please include the actual, raw output from ESLint.

Error: Failed to load plugin 'awesome' declared in '.eslintrc.yml » eslint-config-awesome': Cannot find module 'eslint-plugin-awesome'

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jun 23, 2019
@nevir nevir changed the title Nevir/nested configs with plugins parsers 6.0.0 Bug: nested plugins cannot be found when nested in a shared config Jun 23, 2019
@nevir nevir changed the title 6.0.0 Bug: nested plugins cannot be found when nested in a shared config Bug [6.0.0]: nested plugins cannot be found when nested in a shared config Jun 23, 2019
@nevir nevir changed the title Bug [6.0.0]: nested plugins cannot be found when nested in a shared config Bug: nested plugins cannot be found when nested in a shared config (6.0.0) Jun 23, 2019
@nevir
Copy link
Contributor Author

nevir commented Jun 23, 2019

Honoring importerPath in ConfigArrayFactory#_loadPlugin fixes this specific issue, but triggers other failures.

Interestingly, honoring importerPath is already the behavior for extended configs, and parsers. Smells like it might actually be the right path to take, but I don't know this well enough yet…

"awesome/is-awesome": [2]
}
};
const actual = getConfig(factory, file);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This throws with:

     Error: Failed to load plugin 'awesome' declared in '.eslintrc.yml » eslint-config-awesome': Cannot find module 'eslint-plugin-awesome'
Require stack:
- /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/__placeholder__.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
      at Function.resolve (internal/modules/cjs/helpers.js:32:19)
      at Object.resolve (lib/shared/relative-module-resolver.js:44:50)
      at ConfigArrayFactory._loadPlugin (lib/cli-engine/config-array-factory.js:840:39)
      at names.reduce (lib/cli-engine/config-array-factory.js:729:33)
      at Array.reduce (<anonymous>)
      at ConfigArrayFactory._loadPlugins (lib/cli-engine/config-array-factory.js:725:22)
      at ConfigArrayFactory._normalizeObjectConfigDataBody (lib/cli-engine/config-array-factory.js:551:32)
      at _normalizeObjectConfigDataBody.next (<anonymous>)
      at ConfigArrayFactory._normalizeObjectConfigData (lib/cli-engine/config-array-factory.js:490:20)
      at _normalizeObjectConfigData.next (<anonymous>)
      at ConfigArrayFactory._normalizeObjectConfigDataBody (lib/cli-engine/config-array-factory.js:544:25)
      at _normalizeObjectConfigDataBody.next (<anonymous>)
      at ConfigArrayFactory._normalizeObjectConfigData (lib/cli-engine/config-array-factory.js:490:20)
      at _normalizeObjectConfigData.next (<anonymous>)
      at createConfigArray (lib/cli-engine/config-array-factory.js:306:25)
      at ConfigArrayFactory.loadInDirectory (lib/cli-engine/config-array-factory.js:399:16)
      at CascadingConfigArrayFactory._loadConfigInAncestors (lib/cli-engine/cascading-config-array-factory.js:293:46)
      at CascadingConfigArrayFactory.getConfigArrayForFile (lib/cli-engine/cascading-config-array-factory.js:238:18)
      at getConfig (tests/lib/cli-engine/cascading-config-array-factory.js:144:22)
      at Context.it (tests/lib/cli-engine/cascading-config-array-factory.js:590:32)

Copy link
Contributor Author

@nevir nevir Jun 23, 2019

Choose a reason for hiding this comment

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

Debug output leading up to the failure:

  eslint:config-array-factory Loading YAML config file: /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/.eslintrc.yml +0ms
  eslint:config-array-factory Config file found: /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/.eslintrc.yml +5ms
  eslint:config-array-factory Loading {extends:"awesome"} relative to /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/.eslintrc.yml +15ms
  eslint:config-array-factory Loaded: eslint-config-awesome@1.0.0 (/private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/node_modules/eslint-config-awesome/index.js) +1ms
  eslint:config-array-factory Loading JS config file: /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/node_modules/eslint-config-awesome/index.js +0ms
  eslint:config-array-factory Loading parser "awesome-parser" from /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/node_modules/eslint-config-awesome/index.js +1ms
  eslint:config-array-factory Loaded: awesome-parser@1.0.0 (/private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/node_modules/eslint-config-awesome/node_modules/awesome-parser/index.js) +2ms
  eslint:config-array-factory Loading plugin "awesome" from /private/var/folders/j6/0rhhpj0x0db7yqhhby7x27_r0000gn/T/eslint/fixtures/config-hierarchy/nested-plugins-parser/node_modules/eslint-config-awesome/index.js +1ms
  eslint:config-array-factory Failed to load plugin 'awesome' declared in '.eslintrc.yml » eslint-config-awesome'. +1ms

Copy link
Contributor Author

@nevir nevir Jun 23, 2019

Choose a reason for hiding this comment

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

Note that the ConfigArrayFactory is trying to resolve plugin 'awesome' relative to the root package, not eslint-config-awesome (but the require stack thinks otherwise)

relativeTo points to:
eslint/fixtures/config-hierarchy/nested-plugins-parser/__placeholder__.js

@mysticatea
Copy link
Member

mysticatea commented Jun 23, 2019

Hi. Thank you for your contribution.

But this is by design. All plugins must be in $CWD/node_modules (or the ancestors) because rule ID must be identified to a rule. You can see some long discussion:

@mysticatea mysticatea closed this Jun 23, 2019
@nevir
Copy link
Contributor Author

nevir commented Jun 24, 2019

Ah, doh :( Thanks for the background 👍 That's a tricky set of constraints to navigate…

@nevir nevir deleted the nevir/nested-configs-with-plugins-parsers branch June 24, 2019 15:39
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 21, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants