Assigning to free variables in the node environment should not trigger no-global-assign errors.
See original GitHub issueTell us about your environment
- ESLint Version: 4.9.0
- Node Version: 6.11.4
- npm Version: 3.10.10
What parser (default, Babel-ESLint, etc.) are you using? Default.
Please show your full configuration:
module.exports = {
env: {
node: true,
},
rules: {
'no-global-assign': ['error'],
},
};
What did you do? Please include the actual source code causing the issue.
require = function () {};
What did you expect to happen? require
is a free variable in Node, it’s not a global variable. (Try evaluating 'require' in global
in a JavaScript file in Node. It evaluates to false
.) Therefore, no error should be reported.
What actually happened? Please include the actual, raw output from ESLint.
ESLint reports the following error:
1:1 error Read-only global 'require' should not be modified no-global-assign
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Using Environment Variables in Node.js for App Configuration ...
Learn why experienced Node.js developers use environment variables for app config and secrets, including how to manage default values and ...
Read more >ESLint - "window" is not defined. How to allow global variables ...
I've tried adding something like this to the package.json file to have eslint allow "window" as a global variable, but I must be...
Read more >Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >How to Throw Exceptions in Node.js - Rollbar
Runtime errors can occur in a variety of ways. One example includes referencing an undefined variable, or passing the wrong type to an...
Read more >Node.js Runtime Environment - App Engine - Google Cloud
Node.js version; Dependencies; Application startup; Environment variables ... release versions, but it will not automatically update the major version.
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
Fair enough, especially considering CommonJS always requires some preprocessing. ESLint can’t possibly anticipate the infinitely many ways in which legitimate JS code could be preprocessed and how that could thus affect the semantics on the code it’s analyzing. CommonJS may be popular, but the “magic” involved doesn’t lend itself well to generic static analysis.
@jacksonrayhamilton I think this might be a case where you should use eslint-disable comments. We can’t cover every corner case and on rare occasions, a rule just might report something that is either contrary to more important requirements in your codebase, or outright incorrect.
I don’t think we can make a change here without having ESLint know too much about CommonJS scoping rules, which we don’t really want to do (for the purpose of trying to keep the library runtime-agnostic).