Skip to content

Commit 9b2fad6

Browse files
committed
Initial Guide
0 parents  commit 9b2fad6

File tree

3 files changed

+336
-0
lines changed

3 files changed

+336
-0
lines changed

README.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# Traitify's Javascript Style Guide
2+
3+
**Note**: This guide just outlines the differences from [Airbnb's Guide](https://github.com/airbnb/javascript)
4+
5+
## Rules
6+
7+
- [arrow-parens](https://eslint.org/docs/rules/arrow-parens)
8+
9+
`"arrow-parens": ["error", "always"]`
10+
11+
> Consistency
12+
13+
- [babel/object-curly-spacing](https://github.com/babel/eslint-plugin-babel)
14+
15+
`"babel/object-curly-spacing": "error"`
16+
17+
> Replace non-babel version
18+
19+
- [class-methods-use-this](https://eslint.org/docs/rules/class-methods-use-this)
20+
21+
`"class-methods-use-this": "off"`
22+
23+
> Allows methods to be overridden
24+
25+
- [comma-dangle](https://eslint.org/docs/rules/comma-dangle)
26+
27+
`"comma-dangle": ["error", "never"]`
28+
29+
> Unnecessary
30+
31+
- [consistent-return](https://eslint.org/docs/rules/consistent-return)
32+
33+
`"consistent-return": "off"`
34+
35+
> Makes it hard to return early for conditionals
36+
37+
- [func-names](https://eslint.org/docs/rules/func-names)
38+
39+
`"func-names": "off"`
40+
41+
> Unnecessary and unused with arrow functions
42+
43+
- [jsx-a11y/label-has-for](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md)
44+
45+
> Deprecated
46+
47+
```
48+
"jsx-a11y/label-has-for": ["error", {
49+
components: [],
50+
required: {
51+
some: ["nesting", "id"],
52+
},
53+
allowChildren: false,
54+
}]
55+
```
56+
57+
> Unnecessary to have nesting for both
58+
59+
- [keyword-spacing](https://eslint.org/docs/rules/keyword-spacing)
60+
61+
```
62+
"keyword-spacing": ["error", {
63+
before: false,
64+
after: false,
65+
overrides: {
66+
as: {before: true, after: true},
67+
case: {before: true, after: true},
68+
catch: {before: true},
69+
const: {before: true, after: true},
70+
default: {before: true, after: true},
71+
else: {before: true, after: true},
72+
export: {before: true, after: true},
73+
from: {before: true, after: true},
74+
import: {before: true, after: true},
75+
let: {before: true, after: true},
76+
return: {before: true, after: true},
77+
this: {before: true, after: true},
78+
try: {before: true, after: true}
79+
}
80+
}]
81+
82+
```
83+
84+
> Whitespace - Preference
85+
86+
- [lines-between-class-members](https://eslint.org/docs/rules/lines-between-class-members)
87+
88+
`"lines-between-class-members": ["error", "never"]`
89+
90+
> Whitespace - Preference
91+
92+
- [no-else-return](https://eslint.org/docs/rules/no-else-return)
93+
94+
`"no-else-return": "off"`
95+
96+
> Allows more functional styles
97+
98+
- [no-multiple-empty-lines](https://eslint.org/docs/rules/no-multiple-empty-lines)
99+
100+
`"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}]`
101+
102+
> Little stricter
103+
104+
- [no-underscore-dangle](https://eslint.org/docs/rules/no-underscore-dangle)
105+
106+
`"no-underscore-dangle": "off"`
107+
108+
> Doesn't allow `const key = _key.toLowerCase()`
109+
110+
- [no-unused-expressions](https://eslint.org/docs/rules/no-unused-expressions)
111+
112+
`"no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}]`
113+
114+
> Short circuits and ternaries are efficient
115+
116+
- [object-curly-newline](https://eslint.org/docs/rules/object-curly-newline)
117+
118+
`"object-curly-newline": ["error", {multiline: true, consistent: true}]`
119+
120+
> Too strict
121+
122+
- [object-curly-spacing](https://eslint.org/docs/rules/object-curly-spacing)
123+
124+
`"object-curly-spacing": "off"`
125+
126+
> Incompatible with babel/object-curly-spacing
127+
128+
- [prefer-destructuring](https://eslint.org/docs/rules/prefer-destructuring)
129+
130+
```
131+
"prefer-destructuring": ["error", {
132+
VariableDeclarator: {
133+
array: false,
134+
object: true,
135+
},
136+
AssignmentExpression: {
137+
array: false,
138+
object: false,
139+
},
140+
}, {
141+
enforceForRenamedProperties: false,
142+
}]
143+
```
144+
145+
> Assignment expression looks funky with parens
146+
147+
- [quote-props](https://eslint.org/docs/rules/quote-props)
148+
149+
`"quote-props": ["error", "consistent-as-needed", {keywords: false}]`
150+
151+
> Consistency
152+
153+
- [quotes](https://eslint.org/docs/rules/quotes)
154+
155+
`"quotes": ["error", "double", {allowTemplateLiterals: true}]`
156+
157+
> Double quotes are life
158+
159+
- [react/destructuring-assignment](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md)
160+
161+
`"react/destructuring-assignment": "off"`
162+
163+
> Overactive and solved by prefer-destructuring
164+
165+
- [react/jsx-boolean-value](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
166+
167+
`"react/jsx-boolean-value": ["error", "always"]`
168+
169+
> Prefer explicit
170+
171+
- [react/jsx-filename-extension](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md)
172+
173+
`"react/jsx-filename-extension": "off"`
174+
175+
> Unnecessary
176+
177+
- [react/jsx-one-expression-per-line](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-one-expression-per-line.md)
178+
179+
`"react/jsx-one-expression-per-line": "off"`
180+
181+
> Creates unnecessary white space issues
182+
183+
- [react/no-did-update-set-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md)
184+
185+
`"react/no-did-update-set-state": "off"`
186+
187+
> Makes hacks needed for prop change triggers
188+
189+
- [react/prefer-stateless-function](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
190+
191+
`"react/prefer-stateless-function": "off"`
192+
193+
> Prefer React
194+
195+
- [react/react-in-jsx-scope](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md)
196+
197+
`"react/react-in-jsx-scope": "off"`
198+
199+
> Global React
200+
201+
- [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren)
202+
203+
`"space-before-function-paren": ["error", "never"]`
204+
205+
> Whitespace - Preference
206+
207+
## TODO
208+
209+
These rules are turned off temporarily
210+
211+
- [react/no-unused-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unused-state.md)
212+
213+
`"react/no-unused-state": "off"`
214+
215+
> Remove when rule is fixed for setState function
216+
217+
- [react/sort-comp](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md)
218+
219+
`"react/sort-comp": "off"`
220+
221+
> Remove when airbnb includes componentDidCatch

index.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: false
6+
},
7+
extends: ["airbnb"],
8+
parser: "babel-eslint",
9+
plugins: ["babel"],
10+
rules: {
11+
"arrow-parens": ["error", "always"], // Consistency
12+
"babel/object-curly-spacing": "error", // Replace non-babel version
13+
"class-methods-use-this": "off", // Allows methods to be overridden
14+
"comma-dangle": ["error", "never"], // Unnecessary
15+
"consistent-return": "off", // Makes it hard to return early for conditionals
16+
"func-names": "off", // Unnecessary and unused with arrow functions
17+
"jsx-a11y/label-has-for": ["error", {
18+
components: [],
19+
required: {
20+
some: ["nesting", "id"],
21+
},
22+
allowChildren: false,
23+
}], // Unnecessary to have nesting for both
24+
"keyword-spacing": ["error", {
25+
before: false,
26+
after: false,
27+
overrides: {
28+
as: {before: true, after: true},
29+
case: {before: true, after: true},
30+
catch: {before: true},
31+
const: {before: true, after: true},
32+
default: {before: true, after: true},
33+
else: {before: true, after: true},
34+
export: {before: true, after: true},
35+
from: {before: true, after: true},
36+
import: {before: true, after: true},
37+
let: {before: true, after: true},
38+
return: {before: true, after: true},
39+
this: {before: true, after: true},
40+
try: {before: true, after: true}
41+
}
42+
}], // Whitespace - Preference
43+
"lines-between-class-members": ["error", "never"],
44+
"no-else-return": "off", // Allows more functional styles
45+
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}], // Little stricter
46+
"no-underscore-dangle": "off", // Doesn't allow `const key = _key.toLowerCase()`
47+
"no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}],
48+
"object-curly-newline": ["error", {multiline: true, consistent: true}],
49+
"object-curly-spacing": "off", // Incompatible with babel/object-curly-spacing
50+
"prefer-destructuring": ["error", {
51+
VariableDeclarator: {
52+
array: false,
53+
object: true,
54+
},
55+
AssignmentExpression: {
56+
array: false,
57+
object: false,
58+
},
59+
}, {
60+
enforceForRenamedProperties: false,
61+
}], // Assignment expression looks funky with parens
62+
"quote-props": ["error", "consistent-as-needed", {keywords: false}],
63+
"quotes": ["error", "double", {allowTemplateLiterals: true}],
64+
"react/destructuring-assignment": "off", // Overactive and solved by prefer-destructuring
65+
"react/jsx-boolean-value": ["error", "always"], // Prefer explicit
66+
"react/jsx-filename-extension": "off", // Unnecessary
67+
"react/jsx-one-expression-per-line": "off", // Creates unnecessary white space issues
68+
"react/no-did-update-set-state": "off", // Makes hacks needed for prop change triggers
69+
"react/no-unused-state": "off", // TODO: Remove when rule is fixed for setState function
70+
"react/prefer-stateless-function": "off", // Prefer React
71+
"react/react-in-jsx-scope": "off", // Global React
72+
"react/sort-comp": "off", // TODO: Remove when airbnb includes componentDidCatch
73+
"space-before-function-paren": ["error", "never"] // Whitespace - Preference
74+
},
75+
settings: {
76+
"import/resolver": "webpack",
77+
react: {version: "detect"}
78+
}
79+
};

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "eslint-config-traitify",
3+
"version": "0.0.0",
4+
"description": "Traitify's base ESLint config",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/traitify/eslint-config-traitify.git"
12+
},
13+
"keywords": [
14+
"config",
15+
"eslint",
16+
"eslintconfig",
17+
"javascript",
18+
"styleguide",
19+
"traitify"
20+
],
21+
"author": "Tom Prats <[email protected]> (https://www.tomify.me)",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/traitify/eslint-config-traitify/issues"
25+
},
26+
"homepage": "https://github.com/traitify/eslint-config-traitify#readme",
27+
"dependencies": {
28+
"babel-eslint": "10.x",
29+
"eslint-config-airbnb": "17.x",
30+
"eslint-import-resolver-webpack": "0.x"
31+
},
32+
"peerDependencies": {
33+
"eslint": "5.x",
34+
"eslint-plugin-babel": "5.x"
35+
}
36+
}

0 commit comments

Comments
 (0)