no-import-assign
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-import-assign": "error",
},
},
];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' are readonly.
mod_ns = {} // ERROR: 'mod_ns' is readonly.
// Can't extend 'mod_ns'
Object.assign(mod_ns, { foo: "foo" }) // ERROR: The members of 'mod_ns' are readonly.import mod, { named } from "./mod.mjs"
import * as mod_ns from "./mod.mjs"
mod.prop = 1
named.prop = 2
mod_ns.named.prop = 3
// 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.Examples from the ESLint documentation.
no-import-assign
eslint
export default [
{
rules: {
"no-import-assign": "error",
},
},
];no-import-assign
eslint plugin · correctness
{
"rules": {
"no-import-assign": "error"
}
}suspicious/noImportAssign
suspicious · since 1.0.0
{
"linter": {
"rules": {
"suspicious": {
"noImportAssign": "error"
}
}
}
}Enforce for loop update clause moving the counter in the right direction
Disallow duplicate conditions in if-else-if chains
Require super() calls in constructors
Disallow \8 and \9 escape sequences in string literals