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

Warning: Object.keys called on non-object #1760

Closed
bierik opened this issue Feb 3, 2015 · 12 comments
Closed

Warning: Object.keys called on non-object #1760

bierik opened this issue Feb 3, 2015 · 12 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint

Comments

@bierik
Copy link

bierik commented Feb 3, 2015

Hi there.

I got the following error when i was trying to lint with the grunt-eslint plugin.

TypeError: Object.keys called on non-object
    at Function.keys (native)
    at mergeConfigs (/Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/util.js:35:12)
    at /Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/util.js:60:25
    at Array.forEach (native)
    at mergeConfigs (/Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/util.js:35:25)
    at /Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/util.js:60:25
    at Array.forEach (native)
    at Object.mergeConfigs (/Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/util.js:35:25)
    at Config.getConfig (/Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/config.js:282:19)
    at processFile (/Users/kbieri/bricoler/simplelayout/node_modules/grunt-eslint/node_modules/eslint/lib/cli-engine.js:131:31)

According to sindresorhus/grunt-eslint#47 it's not an issue in the plugin.

Thanks for help.

@nzakas nzakas added the triage An ESLint team member will look at this issue soon label Feb 3, 2015
@nzakas
Copy link
Member

nzakas commented Feb 3, 2015

Can you share your ESLint configuration?

@bierik
Copy link
Author

bierik commented Feb 4, 2015

Sorry guys I used a rule in a wrong way for escaping quotes.

@bierik bierik closed this as completed Feb 4, 2015
@nzakas
Copy link
Member

nzakas commented Feb 4, 2015

That's okay, can you share which rule? Even if you misconfigure, ESLint shouldn't throw an error.

@ot-brett-jones
Copy link

I got this error because of invalid json. I forgot to provide a value for the last line "no-mixed-spaces-and-tabs". Here is what I had in my .eslintrc.

{
  "env": {
    "browser": true,
    "node": true
  },
  "globals": {
    "angular": true
  },
  "rules": {
      "no-use-before-define": "nofunc",
      "strict": false,
      "eol-last": false,
      "no-underscore-dangle": false,
      "quotes": [1, 'double'],
      "no-space-before-semi": [1],
      "no-dangle-comma": [0],
      "indent": 4,
      "no-mixed-spaces-and-tabs"
  }
}

@nzakas
Copy link
Member

nzakas commented Feb 27, 2015

Oh very interesting! We should at least be able to tell you that's the problem when it happens.

@nzakas nzakas reopened this Feb 27, 2015
@nzakas nzakas added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Feb 27, 2015
@glenjamin
Copy link
Contributor

picking this up

glenjamin added a commit to glenjamin/eslint that referenced this issue Mar 1, 2015
@glenjamin
Copy link
Contributor

This occurred because the file shown above is valid YAML, and the value of that rule key becomes null.

yaml.safeLoad(require('fs').readFileSync('bust.json','utf8'))
{ env: { browser: true, node: true },
  globals: { angular: true },
  rules:
   { 'no-use-before-define': 'nofunc',
     strict: false,
     'eol-last': false,
     'no-underscore-dangle': false,
     quotes: [ 1, 'double' ],
     'no-space-before-semi': [ 1 ],
     'no-dangle-comma': [ 0 ],
     indent: 4,
     'no-mixed-spaces-and-tabs': null } }

@glenjamin
Copy link
Contributor

I've pushed a PR that treats a null value as if the key wasn't there.

I could probably make it error on null, but that would likely be a larger change as currently there isn't any schema checking of config files before merging them together - and knowing this is an error relies on knowing valid values for this particular key.

@nzakas
Copy link
Member

nzakas commented Mar 2, 2015

I don't think we should quietly fail in this case because the error might never be found. I'd just throw an error saying "Invalid configuration for rule-name". That at least warns that there's a problem to fix.

@glenjamin
Copy link
Contributor

@michaelficarra At the moment there's no validation on rules at all, there's already #967 which dicusses why this is quite an involved change.

@nzakas would the better fix to add some basic config validation on each config file, that runs before merging, and that disallows null as a rule config value?

@nzakas
Copy link
Member

nzakas commented Mar 2, 2015

That's a much larger effort, which is why it hasn't been done yet (see #967). The easiest path forward here is to throw an error.

glenjamin pushed a commit to glenjamin/eslint that referenced this issue Mar 2, 2015
@glenjamin
Copy link
Contributor

Have pushed another draft - the logic has to live in config.js rather than mergeConfig in util.js as there isn't enough context to detect the error otherwise. Unless we say that null is never a valid value in a config file anywhere.

@nzakas nzakas closed this as completed in 412c9c7 Mar 6, 2015
nzakas added a commit that referenced this issue Mar 6, 2015
Fix: don't crash when given null as rule config (fixes #1760)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@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 Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

No branches or pull requests

4 participants