Skip to content

Commit 40791af

Browse files
mdjermanovickaicataldo
authored andcommittedNov 14, 2019
Docs: clarify ignoreDestructuring option in the camelcase rule (#12553)
1 parent 07d398d commit 40791af

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed
 

‎docs/rules/camelcase.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This rule has an object option:
1313
* `"properties": "always"` (default) enforces camelcase style for property names
1414
* `"properties": "never"` does not check property names
1515
* `"ignoreDestructuring": false` (default) enforces camelcase style for destructured identifiers
16-
* `"ignoreDestructuring": true` does not check destructured identifiers
16+
* `"ignoreDestructuring": true` does not check destructured identifiers (but still checks any use of those identifiers later in the code)
1717
* `"ignoreImports": false` (default) enforces camelcase style for ES2015 imports
1818
* `"ignoreImports": true` does not check ES2015 imports (but still checks any use of the imports later in the code except function arguments)
1919
* `allow` (`string[]`) list of properties to accept. Accept regex.
@@ -154,6 +154,39 @@ var { category_id = 1 } = query;
154154
var { category_id: category_id } = query;
155155
```
156156

157+
Please note that this option applies only to identifiers inside destructuring patterns. It doesn't additionally allow any particular use of the created variables later in the code apart from the use that is already allowed by default or by other options.
158+
159+
Examples of additional **incorrect** code for this rule with the `{ "ignoreDestructuring": true }` option:
160+
161+
```js
162+
/*eslint camelcase: ["error", {ignoreDestructuring: true}]*/
163+
164+
var { some_property } = obj; // allowed by {ignoreDestructuring: true}
165+
var foo = some_property + 1; // error, ignoreDestructuring does not apply to this statement
166+
```
167+
168+
A common use case for this option is to avoid useless renaming when the identifier is not intended to be used later in the code.
169+
170+
Examples of additional **correct** code for this rule with the `{ "ignoreDestructuring": true }` option:
171+
172+
```js
173+
/*eslint camelcase: ["error", {ignoreDestructuring: true}]*/
174+
175+
var { some_property, ...rest } = obj;
176+
// do something with 'rest', nothing with 'some_property'
177+
```
178+
179+
Another common use case for this option is in combination with `{ "properties": "never" }`, when the identifier is intended to be used only as a property shorthand.
180+
181+
Examples of additional **correct** code for this rule with the `{ "properties": "never", "ignoreDestructuring": true }` options:
182+
183+
```js
184+
/*eslint camelcase: ["error", {"properties": "never", ignoreDestructuring: true}]*/
185+
186+
var { some_property } = obj;
187+
doSomething({ some_property });
188+
```
189+
157190
### ignoreImports: false
158191

159192
Examples of **incorrect** code for this rule with the default `{ "ignoreImports": false }` option:

0 commit comments

Comments
 (0)
Please sign in to comment.