]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-useless-rename.md
73a5c79c073e603a36f65e91fd4244955ac12c54
[pve-eslint.git] / eslint / docs / src / rules / no-useless-rename.md
1 ---
2 title: no-useless-rename
3 layout: doc
4 rule_type: suggestion
5 related_rules:
6 - object-shorthand
7 ---
8
9
10
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:
12
13 ```js
14 import { foo as bar } from "baz";
15 export { foo as bar };
16 let { foo: bar } = baz;
17 ```
18
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:
20
21 ```js
22 import { foo as foo } from "bar";
23 export { foo as foo };
24 let { foo: foo } = bar;
25 ```
26
27 is the same as:
28
29 ```js
30 import { foo } from "bar";
31 export { foo };
32 let { foo } = bar;
33 ```
34
35 ## Rule Details
36
37 This rule disallows the renaming of import, export, and destructured assignments to the same name.
38
39 ## Options
40
41 This rule allows for more fine-grained control with the following options:
42
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
46
47 By default, all options are set to `false`:
48
49 ```json
50 "no-useless-rename": ["error", {
51 "ignoreDestructuring": false,
52 "ignoreImport": false,
53 "ignoreExport": false
54 }]
55 ```
56
57 Examples of **incorrect** code for this rule by default:
58
59 ::: incorrect
60
61 ```js
62 /*eslint no-useless-rename: "error"*/
63
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 }) {}
73 ({ foo: foo }) => {}
74 ```
75
76 :::
77
78 Examples of **correct** code for this rule by default:
79
80 ::: correct
81
82 ```js
83 /*eslint no-useless-rename: "error"*/
84
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";
89
90 export { foo };
91 export { foo as bar };
92 export { foo as "bar" };
93 export { foo as bar } from "foo";
94 export { "foo" as "bar" } from "foo";
95
96 let { foo } = bar;
97 let { foo: bar } = baz;
98 let { [foo]: foo } = bar;
99
100 function foo({ bar }) {}
101 function foo({ bar: baz }) {}
102
103 ({ foo }) => {}
104 ({ foo: bar }) => {}
105 ```
106
107 :::
108
109 Examples of **correct** code for this rule with `{ ignoreImport: true }`:
110
111 ::: correct
112
113 ```js
114 /*eslint no-useless-rename: ["error", { ignoreImport: true }]*/
115
116 import { foo as foo } from "bar";
117 ```
118
119 :::
120
121 Examples of **correct** code for this rule with `{ ignoreExport: true }`:
122
123 ::: correct
124
125 ```js
126 /*eslint no-useless-rename: ["error", { ignoreExport: true }]*/
127
128 export { foo as foo };
129 export { foo as foo } from "bar";
130 ```
131
132 :::
133
134 Examples of **correct** code for this rule with `{ ignoreDestructuring: true }`:
135
136 ::: correct
137
138 ```js
139 /*eslint no-useless-rename: ["error", { ignoreDestructuring: true }]*/
140
141 let { foo: foo } = bar;
142 function foo({ bar: bar }) {}
143 ({ foo: foo }) => {}
144 ```
145
146 :::
147
148 ## When Not To Use It
149
150 You can safely disable this rule if you do not care about redundantly renaming import, export, and destructuring assignments.
151
152 ## Compatibility
153
154 * **JSCS**: [disallowIdenticalDestructuringNames](https://jscs-dev.github.io/rule/disallowIdenticalDestructuringNames)