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

NPM scope not working when targeting files. #4800

Closed
satazor opened this Issue Dec 24, 2015 · 15 comments

Comments

Projects
None yet
6 participants
@satazor
Copy link
Contributor

satazor commented Dec 24, 2015

#3136 gave us support for user scoped npm packages but it doesn't support targeting specific files.

Consider the following eslint-config package structure:

rules/
   best-pratices.js
   errors.js
   ...
es5.js
es6.js
index.js

Using "extends": "@satazor" works great because it uses the index.js file but using @satazor/es5 or @satazor/eslint-config/es5 results in an error:

Error: Cannot find module '@satazor/eslint-config-es5'
Error: Cannot find module '@satazor/eslint-config-eslint-config/es5'

Is this expected or a bug? If it is expected how I am able to extend the es5.js configuration?

@eslintbot

This comment has been minimized.

Copy link

eslintbot commented Dec 24, 2015

@satazor Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage label Dec 24, 2015

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 24, 2015

/cc @ljharb

@gyandeeps

This comment has been minimized.

Copy link
Member

gyandeeps commented Dec 24, 2015

@satazor please answer all the question from the second comment.
Also can you run eslint with --debug flag and share the output.

@btmills

This comment has been minimized.

Copy link
Member

btmills commented Dec 24, 2015

@satazor see https://github.com/btmills/eslint-config-btmills for an example of how to do this.

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 24, 2015

@btmills It works in your cause because your package name is suffied with -btmills, mine isn't :(

@gyandeeps will do in my next comment.

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 24, 2015

@eslintbot

  1. $ ./node_modules/.bin/eslint -v
    v1.10.3

  2. I don't have the source coded pushed yet, but:

// package.json of my eslint-config
{
  "name": "@satazor/eslint-config",
}
// .eslintrc trying to extend the config
{
  "extends": "@satazor/eslint-config/es5"
}

Also tried @satazor/es5 to no avail

$ ./node_modules/.bin/eslint addons --debug
  eslint:cli Running on files +0ms
  eslint:glob-util Creating list of files to process. +33ms
  eslint:cli-engine Processing /Users/satazor/Work/own/eslint-config/addons/browser.js +19ms
  eslint:cli-engine Linting /Users/satazor/Work/own/eslint-config/addons/browser.js +1ms
  eslint:config Constructing config for /Users/satazor/Work/own/eslint-config/addons/browser.js +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /Users/satazor/Work/own/eslint-config/.eslintrc +2ms
  eslint:config-file Loading config file: /Users/satazor/Work/own/eslint-config/.eslintrc +0ms
  eslint:config-file Loading @satazor/eslint-config/es5 +39ms
  eslint:config-file Loading config package: @satazor/eslint-config-eslint-config/es5 +0ms
  eslint:config-file Error reading package: @satazor/eslint-config-eslint-config/es5 +0ms
/Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:332
            throw e;
            ^

Error: Cannot read config package: @satazor/eslint-config-eslint-config/es5
Error: Cannot find module '@satazor/eslint-config-eslint-config/es5'
Referenced from: /Users/satazor/Work/own/eslint-config/.eslintrc
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at loadPackage (/Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:168:16)
    at loadConfigFile (/Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:212:18)
    at load (/Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:385:18)
    at /Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:326:36
    at Array.reduceRight (native)
    at applyExtends (/Users/satazor/Work/own/eslint-config/node_modules/eslint/lib/config/config-file.js:309:28)

Output is similar with @satazor/es5

  1. I would except the "extends" to work accordingly. When not using scopes or using a suffix for the package name it works correctly.

For now I'll just suffix my config with -satazor, just like @btmills did. Though I would say that the setup explained here should have worked.

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Dec 24, 2015

@satazor the reason that doesn't work is because @satazor/es5 is a scoped package name already. In other words, the shortcut of just listing your npm username is unique and does not behave like require. you'd need @satazor/eslint-config/es5 to be able to use the require slash-delving behavior.

Based on your comment, however, even that doesn't work, so I'd say that's a bug with the "eslint-config" scope module shortcut.

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 24, 2015

@ljharb as I explained above, using @satazor/eslint-config/es5 gives the same error. Apparently the name of the module must be eslint-config-XXX, even when using scopes.

@nzakas nzakas added bug core accepted and removed triage labels Dec 24, 2015

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Dec 24, 2015

I'm sure that's just something I missed when I added the @username/eslint-config shortcut.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 24, 2015

You cannot use @satazor/es5 because package names must begin with eslint-config, so this is behaving correctly.

The @satazor/eslint-config/es5 should work, that's a bug.

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 24, 2015

@nzakas understood, I will work on a failing test + fix soon. Not sure if it is today or tomorrow because it's XMAS 👪

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 25, 2015

@nzakas @ljharb I have a failing test + fix ready in a branch based on master. Shall I make another PR based on the 1.x branch so we can publish a new version sooner?

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Dec 25, 2015

@satazor i'm not a maintainer but it seems to me that it's a bug that should be fixed in both 1.x and 2.x.

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 25, 2015

I kind of agree with that too, I will make two PR's then

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Dec 25, 2015

Sorry for the commits mess.

PR based on master branch: #4803
PR based on 1.x branch: #4804 (closed, will be manually cherry-picked)

@nzakas nzakas closed this in #4803 Dec 28, 2015

deepsweet referenced this issue in rebem/eslint-config Jan 17, 2016

jonathansamines added a commit to jonathansamines/eslint that referenced this issue May 16, 2017

jonathansamines added a commit to jonathansamines/eslint that referenced this issue May 16, 2017

Docs: Add missing docs for scoped modules
Added missing documentation for npm scoped modules in sharable configuration developer-guide (refs eslint#3136) (eslint#4800)

ilyavolodin added a commit that referenced this issue May 21, 2017

Docs: Add missing documentation for scoped modules in sharable config…
… developer-guide (#8610)

* Docs: Add missing docs for scoped modules

Added missing documentation for npm scoped modules in sharable configuration developer-guide (refs #3136) (#4800)

* Docs: Update docs to add disclaimers about resolution errors

Update the documentation to add additional information of cases where conflicts could happen between scoped modules

* Docs: Fix typo in shareable-config developer-guide

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.