Skip to content

Commit 74fb34f

Browse files
committed
Add no-unused-vars to README
This documents the enforced but currently undocumented `no-unused-vars` rule with a brief description, examples, and noting the `"ignoreRestSiblings": true` option.
1 parent 5e26092 commit 74fb34f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,45 @@ Other Style Guides
17431743
const foo = 'superLongLongLongLongLongLongLongLongString';
17441744
```
17451745
1746+
- [13.8](#variables--no-unused-vars) Disallow unused variables. eslint: [`no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars)
1747+
1748+
> Why? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.
1749+
1750+
```javascript
1751+
// bad
1752+
1753+
var some_unused_var = 42;
1754+
1755+
// Write-only variables are not considered as used.
1756+
var y = 10;
1757+
y = 5;
1758+
1759+
// A read for a modification of itself is not considered as used.
1760+
var z = 0;
1761+
z = z + 1;
1762+
1763+
// Unused function arguments.
1764+
function getX(x, y) {
1765+
return x;
1766+
}
1767+
1768+
// good
1769+
1770+
function getXPlusY(x, y) {
1771+
return x + y;
1772+
}
1773+
1774+
var x = 1;
1775+
var y = a + 2;
1776+
1777+
alert(getXPlusY(x, y));
1778+
1779+
// 'type' is ignored even if unused because it has a rest property sibling.
1780+
// This is a form of extracting an object that omits the specified keys.
1781+
var { type, ...coords } = data;
1782+
// 'coords' is now the 'data' object without its 'type' property.
1783+
```
1784+
17461785
**[⬆ back to top](#table-of-contents)**
17471786
17481787
## Hoisting

0 commit comments

Comments
 (0)