Skip to content

Commit f73c0c7

Browse files
committed
Update JS rules and linter
I believe that most of us agree that airbnb's eslint configuration should be our default linter for JavaScript. I know that, for some projects, we may feel that tweaking it would be better, but I believe that we should agree in a set of rules and follow them. We'll never find something that everyone likes at first. I also think that we need a default configuration because it will remove this conversation out of the way, and let us focus on different things. I also think that we need consistency in our projects, and we need to remove the amount of decisions we make whenever we start a new one. This doesn't mean that this topic is closed forever, we should be open to new ideas, but keep in mind that the benefits of using one styleguide or the other are probably very small. Most times, I believe, it's a matter of taste.
1 parent 494d4c3 commit f73c0c7

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

linters/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ Files to configure the linters we use for each language and technology
1010
* Elixir
1111
* [Credo](/linters/elixir/.credo.exs)
1212
* SVG Files
13-
* * [SVGO](/linters/svg/.svgo.yml)
13+
* [SVGO](/linters/svg/.svgo.yml)
14+
* JavaScript
15+
* [ESLint](/linters/js/README.md)

linters/js/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "airbnb",
3+
"rules": {
4+
"consistent-return": 0,
5+
"react/no-multi-comp": [2, { "ignoreStateless": true }]
6+
}
7+
}

linters/js/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ESLint Setup
2+
============
3+
4+
1. Copy [.eslintrc](.eslintrc) to the root of the project.
5+
2. Install `eslint-config-airbnb`.
6+
7+
8+
npm i --save-dev eslint-config-airbnb
9+
10+
11+
3. Install its peer dependencies following the [instructions in the repo](https://www.npmjs.com/package/eslint-config-airbnb)
12+
13+
14+
Overrides
15+
---------
16+
17+
Airbnb's configuration is great, but some of their rules are too strict for our
18+
team. The following are the rules that we decided not to follow:
19+
20+
1. `consistent-return`
21+
22+
This rule requires that return statements either always or never specify values.
23+
See the following invalid example:
24+
25+
```
26+
const fun = (props) => {
27+
if (!props.value) return;
28+
return props.value * 2;
29+
};
30+
```
31+
32+
To make it valid, we would have to write something like this:
33+
34+
```
35+
const fun = (props) => {
36+
if (!props.value) return undefined;
37+
return props.value * 2;
38+
};
39+
```
40+
41+
2. `react/no-multi-comp`
42+
43+
This rule prevents multiple component definition per file. This is a good
44+
thing, but, for stateless components, it's a strict and painful rule to
45+
follow.

style/js/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Guides for programing JavaScript in style
66
General
77
---
88
* Use [ESLint](http://eslint.org/).
9-
* Always use `use strict`.
9+
* Always use ES6.
1010

1111
Parens and Braces
1212
---
@@ -157,14 +157,3 @@ if (!foo) {
157157
// foo is false
158158
}
159159
```
160-
161-
CoffeeScript
162-
------------
163-
164-
* Initialize arrays using `[]`.
165-
* Initialize empty objects and hashes using `{}`.
166-
* Use `CamelCase` for classes, `lowerCamelCase` for variables and functions,
167-
`SCREAMING_SNAKE_CASE` for constants, `_single_leading_underscore` for
168-
private variables and functions.
169-
* Prefer `== ` or `===` to `is`.
170-
* Prefer `||` and `&&` to `or` and `and`.

0 commit comments

Comments
 (0)