Rule Proposal: disallow the updates of imported bindings
See original GitHub issuePlease describe what the rule should do:
Disallows the updates of imported bindings with ES Modules because such an update will cause runtime errors.
What category of rule is this? (place an “X” next to just one item)
[X] Warns about a potential error (problem)
Provide 2-3 code examples that this rule will warn about:
import mod, { named } from "./mod.mjs"
import * as mod_ns from "./mod.mjs"
mod = 1 // ERROR: 'mod' is readonly.
named = 2 // ERROR: 'named' is readonly.
mod_ns.named = 3 // ERROR: the members of 'mod_ns' is readonly.
mod_ns = {} // ERROR: 'mod_ns' is readonly.
mod++ // ERROR: 'mod' is readonly.
named++ // ERROR: 'named' is readonly.
mod_ns.named++ // ERROR: the members of 'mod_ns' is readonly.
mod_ns++ // ERROR: 'mod_ns' is readonly.
// Known limitation
function test(obj) {
obj.named = 4 // Not errored because 'obj' is not namespace objects.
}
test(mod_ns) // Not errored because it doesn't know that 'test' updates the member of the argument.
Why should this rule be included in ESLint (instead of a plugin)?
Because this is an essential of the language feature. This rule is very similar to core rules no-const-assign
that catches runtime errors.
The rule name may be no-import-assign
.
Are you willing to submit a pull request to implement this rule?
Yes.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Requirements for Electronic Ruling Requests
Under the newly enhanced eRulings program, the importing community may submit an electronic request for a binding ruling by accessing the ...
Read more >Importing Rules with Binding Changes - SAP Community
When I import the entire project, there are no errors during import, but the rules with binding changes are not updated.
Read more >European Commission proposes ban on goods made with ...
As drafted, the new rules would apply to both imported goods and goods made in the European Union. The proposal is expected to...
Read more >Magnuson-Stevens Fishery Conservation and Management Act
Response: As described in the preamble to the proposed rule, this regulation addresses only the collection of information on imported fish and ...
Read more >Know the import and export laws and regulations
Exporting and importing rules · Get updates on U.S. and foreign regulations ... No customs duties or taxes will be assessed at the...
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
New rules can be semver-minor. The only thing that must be semver-major is adding the rule to
eslint:recommended
.In my feeling, as I enumerated in https://github.com/eslint/eslint/issues/12237#issuecomment-529297666,
no-param-reassign
is the only exception of similar rules. So I feel there is special reason for the word selection. And overload handling is the one for parameters but not for the others. Therefore, I feelno-param-reassign
has chosen thereassign
word for overload handling. But it’s not right.