noUselessRename
Diagnostic Category: lint/complexity/noUselessRename
Since: v1.0.0
Sources:
- Same as:
no-useless-rename
Description
Section titled DescriptionDisallow 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.
Examples
Section titled ExamplesInvalid
Section titled Invalidimport { 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;
│ -----
Valid
Section titled Validimport { foo as bar } from "baz";
export { foo as bar };
let { foo: bar } = baz;
How to configure
Section titled How to configure{ "linter": { "rules": { "complexity": { "noUselessRename": "error" } } }}