跳转到内容

noUselessRename

Diagnostic Category: lint/complexity/noUselessRename

Since: v1.0.0

Sources:

Disallow renaming import, export, and destructured assignments to the same name.

ES2015 allows for the renaming of references in import and export statements as well as destructuring assignments. This gives programmers a concise syntax for performing these operations while renaming these references:

import { foo as bar } from "baz";
export { foo as bar };
let { foo: bar } = baz;

With this syntax, it is possible to rename a reference to the same name. This is a completely redundant operation, as this is the same as not renaming at all.

import { foo as foo } from "bar";
code-block.js:1:10 lint/complexity/noUselessRename  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Useless rename.

> 1 │ import { foo as foo } from “bar”;
^^^^^^^^^^
2 │

Safe fix: Remove the renaming.

1 │ import·{·foo·as·foo·}·from·“bar”;
-------
export { foo as foo };
code-block.js:1:10 lint/complexity/noUselessRename  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Useless rename.

> 1 │ export { foo as foo };
^^^^^^^^^^
2 │

Safe fix: Remove the renaming.

1 │ export·{·foo·as·foo·};
-------
let { foo: foo } = bar;
code-block.js:1:7 lint/complexity/noUselessRename  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Useless rename.

> 1 │ let { foo: foo } = bar;
^^^^^^^^
2 │

Safe fix: Remove the renaming.

1 │ let·{·foo:·foo·}·=·bar;
-----
import { foo as bar } from "baz";
export { foo as bar };
let { foo: bar } = baz;