2 title: no-useless-rename
11 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:
14 import { foo as bar } from "baz";
15 export { foo as bar };
16 let { foo: bar } = baz;
19 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. For example, this:
22 import { foo as foo } from "bar";
23 export { foo as foo };
24 let { foo: foo } = bar;
30 import { foo } from "bar";
37 This rule disallows the renaming of import, export, and destructured assignments to the same name.
41 This rule allows for more fine-grained control with the following options:
43 * `ignoreImport`: When set to `true`, this rule does not check imports
44 * `ignoreExport`: When set to `true`, this rule does not check exports
45 * `ignoreDestructuring`: When set to `true`, this rule does not check destructuring assignments
47 By default, all options are set to `false`:
50 "no-useless-rename": ["error", {
51 "ignoreDestructuring": false,
52 "ignoreImport": false,
57 Examples of **incorrect** code for this rule by default:
62 /*eslint no-useless-rename: "error"*/
64 import { foo as foo } from "bar";
65 import { "foo" as foo } from "bar";
66 export { foo as foo };
67 export { foo as "foo" };
68 export { foo as foo } from "bar";
69 export { "foo" as "foo" } from "bar";
70 let { foo: foo } = bar;
71 let { 'foo': foo } = bar;
72 function foo({ bar: bar }) {}
78 Examples of **correct** code for this rule by default:
83 /*eslint no-useless-rename: "error"*/
85 import * as foo from "foo";
86 import { foo } from "bar";
87 import { foo as bar } from "baz";
88 import { "foo" as bar } from "baz";
91 export { foo as bar };
92 export { foo as "bar" };
93 export { foo as bar } from "foo";
94 export { "foo" as "bar" } from "foo";
97 let { foo: bar } = baz;
98 let { [foo]: foo } = bar;
100 function foo({ bar }) {}
101 function foo({ bar: baz }) {}
109 Examples of **correct** code for this rule with `{ ignoreImport: true }`:
114 /*eslint no-useless-rename: ["error", { ignoreImport: true }]*/
116 import { foo as foo } from "bar";
121 Examples of **correct** code for this rule with `{ ignoreExport: true }`:
126 /*eslint no-useless-rename: ["error", { ignoreExport: true }]*/
128 export { foo as foo };
129 export { foo as foo } from "bar";
134 Examples of **correct** code for this rule with `{ ignoreDestructuring: true }`:
139 /*eslint no-useless-rename: ["error", { ignoreDestructuring: true }]*/
141 let { foo: foo } = bar;
142 function foo({ bar: bar }) {}
148 ## When Not To Use It
150 You can safely disable this rule if you do not care about redundantly renaming import, export, and destructuring assignments.
154 * **JSCS**: [disallowIdenticalDestructuringNames](https://jscs-dev.github.io/rule/disallowIdenticalDestructuringNames)