New rule: no-implicit-module
See original GitHub issuePlease describe what the rule should do:
Disallow module scope variable declaration (variable that are not declared in function or Object).
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [X] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
This should warn:
abc.js
var a = 0;
function test () {
return a + 1;
}
While this should be OK:
efg.js
function test(a) {
return a + 1;
}
Why should this rule be included in ESLint (instead of a plugin)?
Like no-implicit-globals
disallow global variable and function declaration, it could be a good practice to disallow global variable inside a module scope (global variable are often a bad practice, not only in JS)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:6 (3 by maintainers)
Top Results From Across the Web
no-implicit-globals - ESLint - Pluggable JavaScript Linter
This rule is mostly useful for browser scripts. Top-level declarations in ES modules and CommonJS modules create module-scoped variables. ES modules also have ......
Read more >Eslint Typescript "No Implicit Any" rule
I have the problem with the "noImplicitAny" rule, which I use in tsconfig.json , but I am unable check for this in eslint....
Read more >no-implicit-dependencies - Rule
Rule : no-implicit-dependencies Disallows importing transient dependencies and modules installed above your package's root directory.
Read more >Support wildcard whitelisting for no-implicit-dependencies ...
Would be nice to be able to whitelist the dependencies that shouldn't be checked by the rule using wildcards: @module/* .
Read more >no-implicit-any-catch - TypeScript ESLint
no -implicit-any-catch ... Disallow usage of the implicit any type in catch clauses. ... Some problems reported by this rule are automatically fixable...
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
I see – so if I’m understanding correctly, the goal would be to avoid global mutable state in modules.
I have a few thoughts on the proposal:
The rule would report code like this, where mutable state is used as an implementation detail (e.g. for caching) without being exposed as part of the module’s API.
I agree that it’s almost always a bad idea to expose global mutable state. I don’t think it’s necessarily a problem to have global mutable state, provided that the state is an implementation detail and the module’s API acts as if it were immutable. The proposed rule would report the latter, even if the goal is to prevent the former.
It’s worth noting that module-scoped variables are not the only way to accidentally expose mutable state. For example, a user could modify a property of a module-scoped variable, and it wouldn’t be caught by this rule.
Bikeshed: I’m not a fan of the name
no-implicit-module
. I assumeno-implicit-module
was a modification of the existingno-implicit-global
rule, but I don’t think that wording makes sense (there isn’t anything implicit going on, and the module itself isn’t the problem.) Maybe something likeno-mutable-module-bindings
would be better.Ok, I understand, thank you for explanation!