Lint Rules

noImportAssign (since v0.9.0)

This rule is recommended by Rome.

Disallow assigning to imported bindings

Examples

Invalid

import x from "y";
x = 1;
correctness/noImportAssign.js:2:1 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable x is read-only
  
    1 │ import x from "y";
  > 2 │ x = 1;
   ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import x from "y";
          ^
    2 │ x = 1;
    3 │ 
  
   Use a local variable instead of reassigning an import.
  
import y from "y";
[y] = 1;
correctness/noImportAssign.js:2:2 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable y is read-only
  
    1 │ import y from "y";
  > 2 │ [y] = 1;
    ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import y from "y";
          ^
    2 │ [y] = 1;
    3 │ 
  
   Use a local variable instead of reassigning an import.
  
import z from "y";
({ z } = 1); /// ```
```js,expect_diagnostic
import a from "y";
[...a] = 1;
correctness/noImportAssign.js:3:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   unterminated template literal
  
    1 │ import z from "y";
    2 │ ({ z } = 1); /// ```
  > 3 │ ```js,expect_diagnostic
      ^^^^^^^^^^^^^^^^^^^^
  > 4 │ import a from "y";
  > 5 │ [...a] = 1;
  > 6 │ 
   
  
import b from "y";
({ ...b } = 1);
correctness/noImportAssign.js:2:7 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable b is read-only
  
    1 │ import b from "y";
  > 2 │ ({ ...b } = 1);
         ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import b from "y";
          ^
    2 │ ({ ...b } = 1);
    3 │ 
  
   Use a local variable instead of reassigning an import.
  
import c from "y";
for (c in y) {};
correctness/noImportAssign.js:2:6 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable c is read-only
  
    1 │ import c from "y";
  > 2 │ for (c in y) {};
        ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import c from "y";
          ^
    2 │ for (c in y) {};
    3 │ 
  
   Use a local variable instead of reassigning an import.
  
import d from "y";
d += 1;
correctness/noImportAssign.js:2:1 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable d is read-only
  
    1 │ import d from "y";
  > 2 │ d += 1;
   ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import d from "y";
          ^
    2 │ d += 1;
    3 │ 
  
   Use a local variable instead of reassigning an import.
  
import * as e from "y";
e = 1;
correctness/noImportAssign.js:2:1 lint/correctness/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The imported variable e is read-only
  
    1 │ import * as e from "y";
  > 2 │ e = 1;
   ^
    3 │ 
  
   The variable is imported here
  
  > 1 │ import * as e from "y";
               ^
    2 │ e = 1;
    3 │ 
  
   Use a local variable instead of reassigning an import.