Skip to content

Commit da1b2ca

Browse files
committed
style: eslint + husky + commitlint
1 parent 507f4ae commit da1b2ca

File tree

3 files changed

+166
-1
lines changed

3 files changed

+166
-1
lines changed

.eslint

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"extends": "airbnb-base",
3+
"parserOptions": {
4+
"sourceType": "script"
5+
},
6+
7+
"rules": {
8+
// === Configure rules for our style ===
9+
// imports must be resolvable
10+
"import/no-unresolved": "error",
11+
// use single quotes,
12+
// unless a different style allows avoiding escapes
13+
"quotes": ["error", "single", {
14+
"avoidEscape": true,
15+
"allowTemplateLiterals": true
16+
}],
17+
// allow else-if return
18+
"no-else-return": [ "error", { "allowElseIf": true } ],
19+
// expressions split over multiple lines
20+
// should break after the operator
21+
"operator-linebreak": [ "error", "after" ],
22+
// require arrow parens only when needed
23+
// and whenever the body is a block
24+
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
25+
// what variables are errors in callbacks
26+
"handle-callback-err": [ "error","^(e$|(e|(.*(_e|E)))rr)" ],
27+
// allow dangling commas in functions
28+
// require them everywhere else
29+
"comma-dangle": ["error", {
30+
"arrays": "always-multiline",
31+
"objects": "always-multiline",
32+
"imports": "always-multiline",
33+
"exports": "always-multiline",
34+
"functions": "only-multiline"
35+
}],
36+
// we actually encourage `return await`
37+
"no-return-await": "off",
38+
// allow `while (true)`
39+
"no-constant-condition": ["error", { "checkLoops": false }],
40+
// allow ignoring an error with `catch`
41+
"no-empty": ["error", { "allowEmptyCatch": true }],
42+
// allow `3 + 5 - 1`, but not `3 * 5 - 1`
43+
"no-mixed-operators": ["error", { "allowSamePrecedence": true }],
44+
// require `'use strict';`
45+
"strict": ["error", "global"],
46+
// we actually use tabs for indentation
47+
"indent": ["error", "tab", { "SwitchCase": 1 }],
48+
"no-tabs": "off",
49+
// we want `== null` to also handle undefined
50+
"no-eq-null": "off",
51+
// allow `for (..; i++)`
52+
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
53+
// allow using functions defined later
54+
"no-use-before-define": ["error", "nofunc"],
55+
// require consistent newlines before and after braces
56+
// if contents are multiline
57+
"object-curly-newline": ["error", { "consistent": true, "multiline": true }],
58+
// require consistent linebreaks inline function parenthesis (arguments or params)
59+
"function-paren-newline": ["error", "consistent"],
60+
// only require const if all parts of destructuring can be const
61+
"prefer-const": ["error", { "destructuring": "all" }],
62+
// don't require destructuring for arrays or assignment
63+
"prefer-destructuring": ["error", {
64+
"VariableDeclarator": { "array": false, "object": true },
65+
"AssignmentExpression": { "array": false, "object": false }
66+
}],
67+
// identical to airbnb rule, except for allowing for..of, because we want to use it
68+
"no-restricted-syntax": [
69+
"error",
70+
{
71+
"selector": "ForInStatement",
72+
"message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array."
73+
},
74+
{
75+
"selector": "LabeledStatement",
76+
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
77+
},
78+
{
79+
"selector": "WithStatement",
80+
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
81+
}
82+
],
83+
// allow lines of up to 120 characters
84+
"max-len": ["error", { "code": 120, "tabWidth": 2, "ignoreUrls": true, "ignoreStrings": true, "ignoreTemplateLiterals": true, "ignoreRegExpLiterals": true }],
85+
86+
// === Disable rules ===
87+
// more liberal naming
88+
"camelcase": "off",
89+
"no-underscore-dangle": "off",
90+
// don't require anonymous function names
91+
"func-names": "off",
92+
// allow console
93+
"no-console": "off",
94+
// allow new for side effects
95+
// allow new with non-capitalized
96+
"no-new": "off",
97+
"new-cap": "off",
98+
// allow shadowing variables (usually callbacks)
99+
"no-shadow": "off",
100+
// allow multiple empty lines in a row
101+
"no-multiple-empty-lines": "off",
102+
// allow not using object shorthand
103+
"object-shorthand": "off",
104+
105+
// TODO
106+
"consistent-return": "off",
107+
"no-restricted-globals": "off",
108+
"no-prototype-builtins": "off",
109+
"import/no-extraneous-dependencies": "off",
110+
"import/no-dynamic-require": "off",
111+
"global-require": "off",
112+
"no-param-reassign": "off",
113+
"default-case": "off"
114+
}
115+
}

commitlint.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
module.exports = {
4+
extends: ['@commitlint/config-angular'],
5+
rules: {
6+
'header-max-length': [1, 'always', 72],
7+
'type-enum': [
8+
2,
9+
'always',
10+
[
11+
'breaking',
12+
'build',
13+
'chore',
14+
'ci',
15+
'docs',
16+
'feat',
17+
'fix',
18+
'perf',
19+
'refactor',
20+
'revert',
21+
'style',
22+
'test',
23+
],
24+
],
25+
},
26+
};

package.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,29 @@
44
"description": "Enter a description here",
55
"main": "theme.less",
66
"keywords": [],
7-
"license": "MIT"
7+
"license": "MIT",
8+
"husky": {
9+
"hooks": {
10+
"pre-commit": "npx lint-staged",
11+
"commit-msg": "npx commitlint -E HUSKY_GIT_PARAMS"
12+
}
13+
},
14+
"lint-staged": {
15+
"*.js": [
16+
"eslint --fix",
17+
"git add"
18+
]
19+
},
20+
"dependencies": {
21+
"bent": "^7.3.12"
22+
},
23+
"devDependencies": {
24+
"@commitlint/cli": "11.0.0",
25+
"@commitlint/config-angular": "11.0.0",
26+
"eslint": "7.18.0",
27+
"eslint-config-airbnb-base": "14.2.1",
28+
"eslint-plugin-import": "2.22.1",
29+
"husky": "5.0.9",
30+
"lint-staged": "10.5.4"
31+
}
832
}

0 commit comments

Comments
 (0)