Skip to content

Commit

Permalink
[eslint config] [breaking] Add no-dupe-class-members rule + section.
Browse files Browse the repository at this point in the history
Closes #785.
  • Loading branch information
ljharb committed Apr 3, 2016
1 parent 5b9f081 commit 76e1e4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Other Style Guides
1. [Strings](#strings)
1. [Functions](#functions)
1. [Arrow Functions](#arrow-functions)
1. [Constructors](#constructors)
1. [Classes & Constructors](#constructors)
1. [Modules](#modules)
1. [Iterators and Generators](#iterators-and-generators)
1. [Properties](#properties)
Expand Down Expand Up @@ -894,7 +894,7 @@ Other Style Guides
**[⬆ back to top](#table-of-contents)**
## Constructors
## Classes & Constructors
<a name="constructors--use-class"></a><a name="9.1"></a>
- [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly.
Expand Down Expand Up @@ -1008,7 +1008,7 @@ Other Style Guides
```
<a name="constructors--no-useless"></a><a name="9.5"></a>
- [9.5](#constructors--no-useless) 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. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor)
- [9.5](#constructors--no-useless) 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. eslint: [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor)

```javascript
// bad
Expand Down Expand Up @@ -1036,6 +1036,30 @@ Other Style Guides
}
```

<a name="classes--no-duplicate-members"></a>
- [9.6](#classes--no-duplicate-members) Avoid duplicate class members. eslint: [`no-dupe-class-members`](http://eslint.org/docs/rules/no-dupe-class-members)

> Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug.

```javascript
// bad
class Foo {
bar() { return 1; }
bar() { return 2; }
}
// good
class Foo {
bar() { return 1; }
}
// good
class Foo {
bar() { return 2; }
}
```


**[⬆ back to top](#table-of-contents)**


Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config-airbnb/rules/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = {
}],
// disallow modifying variables that are declared using const
'no-const-assign': 2,
// disallow duplicate class members
// http://eslint.org/docs/rules/no-dupe-class-members
'no-dupe-class-members': 2,
// disallow importing from the same path more than once
// http://eslint.org/docs/rules/no-duplicate-imports
'no-duplicate-imports': 2,
Expand Down

0 comments on commit 76e1e4c

Please sign in to comment.