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

Cannot use "extends" within package.json #2754

Closed
keithamus opened this issue Jun 11, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@keithamus
Copy link
Contributor

commented Jun 11, 2015

Not sure if this is me being stupid or not - but I cannot seem to load the extends directive within the package.json eslintConfig.

If I have an .eslintrc file with the following:

{
    "extends": "strict"
}

All works fine. Now if I try to put that in my package.json:

"eslintConfig": {
  "extends": "strict"
}
"devDependencies": {
  "eslint-config-strict": "^1.1.0"
}

It reverts to the default eslint configuration - i.e. not extending from the strict config. I couldn't read anything in the docs suggesting this was not allowed.

@gyandeeps gyandeeps added the triage label Jun 11, 2015

@gyandeeps

This comment has been minimized.

Copy link
Member

commented Jun 11, 2015

Can you please run eslint using the DEBUG flag and share the output.

DEBUG=eslint:* eslint [path]
@nzakas

This comment has been minimized.

Copy link
Member

commented Jun 12, 2015

Looks like we aren't properly loading package.json configs around here: https://github.com/eslint/eslint/blob/master/lib/config.js#L221

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jun 12, 2015

I've trimmed out sensitive info. The file is a bit of a mess so produces errors in both default and the eslint-config-strict settings, but you can clearly see the package.json is ignoring the extends directive:

$ cat package.json | grep eslintConfig -B1 -A4
  },
  "eslintConfig": {
    "extends": "strict"
  }
}

$ eslint . # with package.json
  eslint:cli Running on files +0ms
  eslint:cli-engine Processing <file> +6ms
  eslint:cli-engine Linting /Users/<file> +3ms
  eslint:config Constructing config for /Users/<file> +1ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /Users/<folder>/package.json +1ms
  eslint:config Using /Users/<folder>/package.json +4ms
  eslint:config Merging command line environment settings +9ms

<file>
   2:11  error  "require" is not defined                       no-undef
   2:19  error  Strings must use doublequote                   quotes
   3:31  error  "process" is not defined                       no-undef
   4:9   error  "require" is not defined                       no-undef
   4:17  error  Strings must use doublequote                   quotes
   5:18  error  "require" is not defined                       no-undef
   5:26  error  Strings must use doublequote                   quotes
   7:0   error  Missing "use strict" statement                 strict
   9:52  error  object is already declared in the upper scope  no-shadow
  10:39  error  Strings must use doublequote                   quotes
  19:17  error  "require" is not defined                       no-undef
  21:17  error  "file" is not defined                          no-undef
  23:20  error  "require" is not defined                       no-undef
  23:28  error  Strings must use doublequote                   quotes
  26:4   error  Strings must use doublequote                   quotes
  27:4   error  Strings must use doublequote                   quotes
  28:4   error  Strings must use doublequote                   quotes
  29:4   error  Strings must use doublequote                   quotes
  30:4   error  Strings must use doublequote                   quotes
  31:4   error  Strings must use doublequote                   quotes
  32:4   error  Strings must use doublequote                   quotes
  33:4   error  Strings must use doublequote                   quotes
  34:4   error  Strings must use doublequote                   quotes
  35:4   error  Strings must use doublequote                   quotes
  35:13  error  Unexpected trailing comma                      comma-dangle
  37:0   error  "require" is not defined                       no-undef
  37:8   error  Strings must use doublequote                   quotes
  37:19  error  "file" is not defined                          no-undef

✖ 28 problems (28 errors, 0 warnings)

Here's with the .eslintrc in place:

$ cat .eslintrc
{
    "extends": "strict"
}

$ eslint . # with .eslintrc

  eslint:cli Running on files +0ms
  eslint:cli-engine Processing <file> +7ms
  eslint:cli-engine Linting /Users/<file> +2ms
  eslint:config Constructing config for /Users/<file> +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /Users/<folder>/.eslintrc +1ms
  eslint:config Using /Users/<folder>/.eslintrc +8ms
  eslint:config Loading /Users/<folder>/package.json +0ms
  eslint:config Using /Users/<folder>/package.json +2ms
  eslint:config Merging command line environment settings +11ms
  eslint:cli-engine Load plugin filenames +6ms
  eslint:cli-engine Load plugin one-variable-per-var +0ms

<file>
   2:0   error  Unexpected var, use let or const instead           no-var
   3:0   error  Unexpected var, use let or const instead           no-var
   4:0   error  Unexpected var, use let or const instead           no-var
   5:0   error  Unexpected blank line after variable declarations  newline-after-var
   5:0   error  Unexpected var, use let or const instead           no-var
   8:2   error  Expected indentation of 2 characters               indent
   8:4   error  Assignment to function parameter 'object'          no-param-reassign
   9:2   error  Expected indentation of 2 characters               indent
   9:42  error  Missing function expression name                   func-names
   9:52  error  object is already declared in the upper scope      no-shadow
  10:4   error  Expected indentation of 4 characters               indent
  11:6   error  Expected indentation of 6 characters               indent
  12:4   error  Expected indentation of 4 characters               indent
  13:6   error  Expected indentation of 6 characters               indent
  14:4   error  Expected indentation of 4 characters               indent
  15:4   error  Expected indentation of 4 characters               indent
  16:2   error  Expected indentation of 2 characters               indent
  19:0   error  Unexpected blank line after variable declarations  newline-after-var
  19:0   error  Unexpected var, use let or const instead           no-var
  21:17  error  "file" is not defined                              no-undef
  23:0   error  Unexpected var, use let or const instead           no-var
  37:19  error  "file" is not defined                              no-undef

✖ 22 problems (22 errors, 0 warnings)

FWIW this is using eslint 0.21.1 but it seems like the issue is still relevant to 22.1.

@gyandeeps gyandeeps added bug core and removed triage labels Jun 12, 2015

@gyandeeps

This comment has been minimized.

Copy link
Member

commented Jun 12, 2015

Whats happening is that when we try to manage the extends logic at the time package json is at its original state. At this spot https://github.com/eslint/eslint/blob/master/lib/config.js#L83-L92
After everything happens then we refined the package.json to extract what we need. which happens at this spot https://github.com/eslint/eslint/blob/master/lib/config.js#L223-L230
By that time we are already passed the extend logic so now if we have an extend inside package.json->eslintConfig->extends , we completly miss it.

@nzakas nzakas added the accepted label Jun 12, 2015

gyandeeps added a commit that referenced this issue Jun 12, 2015

gyandeeps added a commit that referenced this issue Jun 12, 2015

gyandeeps added a commit that referenced this issue Jun 12, 2015

gyandeeps added a commit that referenced this issue Jun 13, 2015

@gyandeeps gyandeeps closed this in a96839f Jun 14, 2015

ilyavolodin added a commit that referenced this issue Jun 14, 2015

Merge pull request #2761 from eslint/issue2754
Fix: "extends" within package.json (fixes #2754)

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

@eslint eslint bot added the archived due to age label Feb 7, 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.