no-undefined doesn't allow undefined as an object property
See original GitHub issueTell 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:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thinkvar { bar: undefined } = foo;
should be valid since it’s creating a variable named “undefined” fromfoo.bar
.Okay. I assume that assigning to
undefined
should probably be invalid in each case, then, since it’s still trying to useundefined
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.