-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Closed
Labels
acceptedThere is consensus among the team that this change meets the criteria for inclusionThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionThis issue has been archived; please open a new issue for any further discussionfeatureThis change adds a new feature to ESLintThis change adds a new feature to ESLintruleRelates to ESLint's core rulesRelates to ESLint's core rules
Description
Please 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.
mdjermanovic, ilyavolodin, g-plane, platinumazure and ljharb
Metadata
Metadata
Assignees
Labels
acceptedThere is consensus among the team that this change meets the criteria for inclusionThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionThis issue has been archived; please open a new issue for any further discussionfeatureThis change adds a new feature to ESLintThis change adds a new feature to ESLintruleRelates to ESLint's core rulesRelates to ESLint's core rules