Skip to content

noUselessRename (since v1.0.0)

Diagnostic Category: lint/complexity/noUselessRename

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";
complexity/noUselessRename.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 };
complexity/noUselessRename.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;
complexity/noUselessRename.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;