question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-undefined doesn't allow undefined as an object property

See original GitHub issue

Tell us about your environment

  • ESLint Version: v3.14.0
  • Node Version: v6.9.4
  • npm Version: 3.10.10

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

{
  "parserOptions": {
    "ecmaVersion": 6
  },
  "env": {
    "browser": true
  },
  "globals": {
    "jQuery": false
  },
  "rules": {
    "quote-props": ["error", "consistent-as-needed"],
    "no-undefined": "error"
  }
}

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

'use strict';

var foo = {
  undefined: 'bar',
};

What did you expect to happen? undefined should be permitted as an unquoted object property.

What actually happened? Please include the actual, raw output from ESLint. no-undefined produces an error. Quoting undefined (which would otherwise be a workaround) produces an error from quote-props.

Given that undefined is a permissable object property name, I believe no-undefined should be modified to permit this behaviour.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Jan 23, 2017

They might only be valid in strict mode, with an ecmaVersion > 5 or 6 - but I think there’s other rules that can handle that.

var { undefined: bar } = foo; should be valid because it’s extracting a property named “undefined” and putting it into a variable named “bar” - but I don’t think var { bar: undefined } = foo; should be valid since it’s creating a variable named “undefined” from foo.bar.

1reaction
platinumazurecommented, Jan 23, 2017

Okay. I assume that assigning to undefined should probably be invalid in each case, then, since it’s still trying to use undefined as an identifier rather than it coming up as an object key. I’ll write a PR with that assumption, let me know either here or in the PR if that’s wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting an undefined object property - Stack Overflow
The usual way to check if the value of a property is the special value undefined , is: if(o.myProperty === undefined) { alert("myProperty...
Read more >
no-undefined - ESLint - Pluggable JavaScript Linter
The undefined variable in JavaScript is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite...
Read more >
ReferenceError: reference to undefined property "x" - JavaScript
The JavaScript warning "reference to undefined property" occurs when a script attempted to access an object property which doesn't exist.
Read more >
Rule no-undefined - ESLint中文
This represents a problem for undefined that doesn't exist for null , which is a keyword and primitive value that can neither be...
Read more >
`undefined` vs. `null` revisited - 2ality
Many programming languages have one “non-value” called null. It indicates that a variable does not currently point to an object – for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found