Skip to content

noImportAssign

诊断类别:lint/suspicious/noImportAssign

¥Diagnostic Category: lint/suspicious/noImportAssign

自从:v1.0.0

¥Since: v1.0.0

来源:

¥Sources:

禁止分配给导入的绑定

¥Disallow assigning to imported bindings

¥Examples

¥Invalid

import x from "y";
x = 1;
code-block.js:2:1 lint/suspicious/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;
code-block.js:2:2 lint/suspicious/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);
code-block.js:2:4 lint/suspicious/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The imported variable z is read-only

1 │ import z from “y”;
> 2 │ ({ z } = 1);
^
3 │

The variable is imported here

> 1 │ import z from “y”;
^
2 │ ({ z } = 1);
3 │

Use a local variable instead of reassigning an import.

import a from "y";
[...a] = 1;
code-block.js:2:5 lint/suspicious/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The imported variable a is read-only

1 │ import a from “y”;
> 2 │ […a] = 1;
^
3 │

The variable is imported here

> 1 │ import a from “y”;
^
2 │ […a] = 1;
3 │

Use a local variable instead of reassigning an import.

import b from "y";
({ ...b } = 1);
code-block.js:2:7 lint/suspicious/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) {};
code-block.js:2:6 lint/suspicious/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;
code-block.js:2:1 lint/suspicious/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;
code-block.js:2:1 lint/suspicious/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.

¥Related links