no-undef fails with node.js global object
See original GitHub issueTell us about your environment
- ESLint Version: 5.12.1
- Node Version: 10.15.1
- npm Version: 6.4.1
What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:
Configuration
{
"env": {
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018
}
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
global.my_value = 5;
if (my_value < 3) {
// ...
}
eslint . --ext .js
What did you expect to happen? No error would occur as the nodejs environment is set.
What actually happened? Please include the actual, raw output from ESLint.
/path/to/my/index.js
3:5 error 'my_value' is not defined no-undef
Are you willing to submit a pull request to fix this bug? No, I lack the experience with eslint internal code to reliably do so.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (13 by maintainers)
Top Results From Across the Web
ESLint doesn't recognize node.js's 'global' object
The global object is part of Node.js. It is not specific to Jest and therefore it's not included in the jest environment.
Read more >no-undef - ESLint - Pluggable JavaScript Linter
This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for ...
Read more >Global objects | Node.js v19.3.0 Documentation
These objects are available in all modules. The following variables may appear to be global but are not. They exist only in the...
Read more >LLVM Language Reference Manual
Global values are represented by a pointer to a memory location (in this case, a pointer to an array of char, and a...
Read more >Expose Global Variables, Methods, and Modules in JavaScript
Expose Global Variables, Methods, and Modules in JavaScript. ... the function is not defined: error 'setJavaPresent' is not defined no-undef.
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 Free
Top 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
Personally I don’t think this change would be worth the complexity, because:
global
represents the global object in Node. Thenode
env just enables some specific globals such asmodule
,global
, andexports
(and also some unrelated parser options), but there isn’t any concept of “assignments to this value will create a property on the global object”.global.global
to something other than the global object.TypeScript now also detects variables added on
globalThis
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis