mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 05:08:25 -05:00
[eslint-v2][constructors] disallow unnecessary constructors
This commit is contained in:
committed by
Jordan Harband
parent
5109c84926
commit
1cbc628c49
24
README.md
24
README.md
@@ -883,6 +883,30 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
- [9.5](#9.5) <a name='9.5'></a> Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
class Jedi {
|
||||
constructor() {}
|
||||
|
||||
getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
// good
|
||||
class Rey extends Jedi {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
|
||||
getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ module.exports = {
|
||||
'no-this-before-super': 0,
|
||||
// require let or const instead of var
|
||||
'no-var': 2,
|
||||
// disallow unnecessary constructor
|
||||
// http://eslint.org/docs/rules/no-useless-constructor
|
||||
'no-useless-constructor': 2,
|
||||
// require method and property shorthand syntax for object literals
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md
|
||||
'object-shorthand': [2, 'always'],
|
||||
|
||||
Reference in New Issue
Block a user