Skip to main content

no-import-assign

NOTE: this rule is part of the recommended rule set.
Enable full set in deno.json:
{
  "lint": {
    "tags": ["recommended"]
  }
}
Enable full set using the Deno CLI:
deno lint --tags=recommended

Disallows reassignment of imported module bindings.

ES module import bindings should be treated as read-only since modifying them during code execution will likely result in runtime errors. It also makes for poor code readability and difficult maintenance.

Invalid:

import defaultMod, { namedMod } from "./mod.js";
import * as modNameSpace from "./mod2.js";

defaultMod = 0;
namedMod = true;
modNameSpace.someExportedMember = "hello";
modNameSpace = {};

Valid:

import defaultMod, { namedMod } from "./mod.js";
import * as modNameSpace from "./mod2.js";

// properties of bound imports may be set
defaultMod.prop = 1;
namedMod.prop = true;
modNameSpace.someExportedMember.prop = "hello";

Did you find what you needed?

Privacy policy