[eslint-v2][constructors] disallow unnecessary constructors

This commit is contained in:
Harrison Shoff
2016-02-13 13:57:38 -08:00
committed by Jordan Harband
parent 5109c84926
commit 1cbc628c49
2 changed files with 27 additions and 0 deletions

View File

@@ -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)**

View File

@@ -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'],