Skip to content

Commit 2e12b64

Browse files
committed
KTL-1241 chore: added eslint&prettier, run them on pre-commit
1 parent 5bbd932 commit 2e12b64

File tree

7 files changed

+1213
-61
lines changed

7 files changed

+1213
-61
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
8+
[*]
9+
10+
# Change these settings to your own preference
11+
indent_style = space
12+
indent_size = 2
13+
14+
# We recommend you to keep these unchanged
15+
end_of_line = lf
16+
charset = utf-8
17+
trim_trailing_whitespace = true
18+
insert_final_newline = true
19+
20+
[*.md]
21+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
public

.eslintrc.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
'eslint:recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
'plugin:react/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
overrides: [
13+
{
14+
env: {
15+
node: true,
16+
},
17+
files: ['.eslintrc.{js,cjs}'],
18+
parserOptions: {
19+
sourceType: 'script',
20+
},
21+
},
22+
],
23+
parser: '@typescript-eslint/parser',
24+
parserOptions: {
25+
project: 'tsconfig.json',
26+
ecmaVersion: 'latest',
27+
sourceType: 'module',
28+
},
29+
settings: {
30+
react: {
31+
version: 'detect',
32+
},
33+
},
34+
plugins: ['@typescript-eslint', 'react', 'prettier', 'import', 'react-hooks'],
35+
rules: {
36+
indent: ['warn', 2],
37+
'linebreak-style': ['error', 'unix'],
38+
quotes: ['error', 'single'],
39+
semi: ['error', 'always'],
40+
'react/react-in-jsx-scope': 'off',
41+
'import/order': ['error', { alphabetize: { order: 'asc' } }],
42+
'react-hooks/rules-of-hooks': 'error',
43+
'react-hooks/exhaustive-deps': 'warn',
44+
},
45+
};

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn run lint-staged

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: 'es5',
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 2,
7+
};

package.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@
1010
"start": "gatsby develop --port 8082",
1111
"build": "gatsby build --prefix-paths",
1212
"serve": "gatsby serve",
13-
"clean": "gatsby clean"
13+
"clean": "gatsby clean",
14+
"lint": "eslint --ext src/**/**/*.{ts,tsx}",
15+
"lint:fix": "eslint --fix --ext src/**/**/*.{ts,tsx}",
16+
"prettier": "prettier --write 'src/**/**/*.{ts,tsx,css,scss}'",
17+
"lint-staged": "lint-staged",
18+
"prepare": "husky install"
19+
},
20+
"lint-staged": {
21+
"src/**/**/*.{ts,tsx}": [
22+
"eslint --fix"
23+
],
24+
"src/**/**/*.{ts,tsx,css,scss}": [
25+
"prettier --write"
26+
]
1427
},
1528
"dependencies": {
1629
"@csstools/postcss-global-data": "^1.0.3",
@@ -48,10 +61,17 @@
4861
"@babel/core": "^7.21.3",
4962
"@mdx-js/react": "^2.3.0",
5063
"@types/react-helmet": "^6.1.6",
64+
"@typescript-eslint/eslint-plugin": "^6.12.0",
65+
"@typescript-eslint/parser": "^6.12.0",
5166
"babel-eslint": "^10.1.0",
5267
"babel-preset-gatsby": "^3.7.0",
5368
"core-js": "^3.29.1",
54-
"eslint": "^8.36.0",
69+
"eslint": "^8.54.0",
70+
"eslint-config-prettier": "^9.0.0",
71+
"eslint-plugin-import": "^2.29.0",
72+
"eslint-plugin-prettier": "^5.0.1",
73+
"eslint-plugin-react": "^7.33.2",
74+
"eslint-plugin-react-hooks": "^4.6.0",
5575
"gatsby": "5",
5676
"gatsby-plugin-image": "^3.7.0",
5777
"gatsby-plugin-manifest": "^5.7.0",
@@ -65,7 +85,10 @@
6585
"gatsby-transformer-remark": "^6.7.0",
6686
"gatsby-transformer-sharp": "^5.7.0",
6787
"glob": "^10.2.1",
88+
"husky": "^8.0.3",
89+
"lint-staged": "^15.1.0",
6890
"postcss": "^8.4.21",
91+
"prettier": "^3.1.0",
6992
"prop-types": "^15.7.2",
7093
"typescript": "^4.9.5",
7194
"typescript-plugin-css-modules": "^4.2.3"

0 commit comments

Comments
 (0)