-
Notifications
You must be signed in to change notification settings - Fork 18
Add rules for prohibiting unused vars/expressions #78
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,21 @@ var length = items.length; | |
var name = 'foo'; | ||
```` | ||
|
||
## Don't have unused variables/expressions | ||
```javascript | ||
// Bad: Many of these variables/expressions are useless | ||
{} // object - not used | ||
var newArray = []; // newArray - not used | ||
['1', '2', '3', '4'].forEach(function(num, index) { // index - not used | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about when something you need is in the second argument? Say we wanted index but not num - a functional programming common practice is to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jansepar There are options to eslint we can use to ignore unused arguments to functions. That seems like it'd be a pragmatic compromise here.
Reference: https://github.com/eslint/eslint/blob/master/docs/rules/no-unused-vars.md Interestingly, I have no idea what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeremywiebe The http://eslint.org/docs/user-guide/configuring#configuring-rules |
||
return num++; | ||
}); | ||
|
||
// Good: Delete things you no longer need | ||
['1', '2', '3', '4'].forEach(function(num) { | ||
return num++; | ||
}); | ||
``` | ||
|
||
##Use semi-colons | ||
|
||
There are many more ways that things can break *without* semi-colons than *with* semi-colons. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to allow the use of short circuits and ternary conditionals, since I see those a lot.
"no-unused-expressions": [2, { allowShortCircuit: true, allowTernary: true }]