Skip to content

Commit 4b74c8f

Browse files
CatchMe2Mateusz Tkacz
and
Mateusz Tkacz
authored
feat/simplify configs (#26)
* feat: add unicorn plugin for node * feat: add eslint-plugin-unicorn and eslint-config-prettier as dependencies Co-authored-by: Mateusz Tkacz <mateusz.tkacz@mobilereality.pl>
1 parent 76844fd commit 4b74c8f

13 files changed

+173
-90
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ ESLint's configuration of Mobile Reality Team
6363
XXX is a preconfigured eslint config for MR projects. Supported configs with required peerDependencies (which must be installed in project):
6464
- node-javascript
6565
- node-typescript (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0)
66-
- react-javascript (eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
67-
- react-typescript (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
68-
- react-native (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort eslint-plugin-react-native)
66+
- react-javascript (eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
67+
- react-typescript (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
68+
- react-native (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort eslint-plugin-react-native)
6969
7070
## Installation and usage for an existing project
7171

configs/eslint.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
extends: ['eslint:all'],
2+
extends: ['eslint:all', 'prettier'],
33
rules: {
44
'one-var': ['error', 'never'],
55
'no-magic-numbers': 'off',
@@ -27,5 +27,6 @@ module.exports = {
2727
'multiline-comment-style': 'off',
2828
'consistent-return': 'off',
2929
'prefer-named-capture-group': 'off',
30+
'class-methods-use-this': 'off',
3031
},
3132
};

configs/react-native.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ module.exports = {
55
'react-native/no-inline-styles': 'error',
66
'react-native/no-color-literals': 'error',
77
'react-native/no-single-element-style-arrays': 'error',
8-
'@typescript-eslint/no-use-before-define': 'off',
9-
'@typescript-eslint/no-require-imports': 'off',
108
},
119
};

configs/react.js

+1-28
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module.exports = {
33
'plugin:react/recommended',
44
'plugin:react-hooks/recommended',
55
'plugin:jsx-a11y/recommended',
6+
'prettier',
67
],
7-
plugins: ['simple-import-sort'],
88
rules: {
99
'react/boolean-prop-naming': 'error',
1010
'react/button-has-type': 'error',
@@ -31,32 +31,5 @@ module.exports = {
3131
'react/no-typos': 'error',
3232
'react/prop-types': 'off',
3333
'react/self-closing-comp': 'error',
34-
'simple-import-sort/exports': 'error',
35-
'simple-import-sort/imports': [
36-
'error',
37-
{
38-
groups: [
39-
['^\\u0000'],
40-
[
41-
'^react',
42-
'^react-native',
43-
'^next',
44-
'^axios',
45-
'^graphql',
46-
'^urql',
47-
'^styled-components',
48-
'^pages',
49-
'^views',
50-
'^@?\\w',
51-
],
52-
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
53-
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
54-
],
55-
},
56-
],
57-
'@typescript-eslint/no-confusing-void-expression': 'off',
58-
'@typescript-eslint/no-misused-promises': 'off',
59-
'no-underscore-dangle': 'off',
60-
'class-methods-use-this': 'off',
6134
},
6235
};

configs/typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
project: 'tsconfig.json',
44
sourceType: 'module',
55
},
6-
extends: [`plugin:@typescript-eslint/all`],
6+
extends: ['plugin:@typescript-eslint/all', 'prettier'],
77
rules: {
88
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
99
'@typescript-eslint/promise-function-async': 'off',

configs/unicorn.js

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
module.exports = {
2-
extends: ['plugin:unicorn/recommended'],
2+
extends: ['plugin:unicorn/recommended', 'prettier'],
33
rules: {
44
'unicorn/catch-error-name': [
55
'warn',
66
{
7-
name: 'e',
7+
name: 'err',
88
},
99
],
10-
'unicorn/filename-case': 'off',
11-
'unicorn/no-array-callback-reference': 'off',
12-
'unicorn/no-array-reduce': 'off',
13-
'unicorn/no-null': 'off',
14-
'unicorn/no-thenable': 'off',
15-
'unicorn/no-useless-undefined': 'off',
16-
'unicorn/numeric-separators-style': 'off',
17-
'unicorn/prefer-module': 'off',
18-
'unicorn/prefer-node-protocol': 'off',
19-
'unicorn/prefer-regexp-test': 'off',
20-
'unicorn/prefer-set-has': 'off',
21-
'unicorn/prefer-spread': 'off',
2210
'unicorn/prevent-abbreviations': 'off',
23-
'unicorn/template-indent': 'off',
24-
'unicorn/text-encoding-identifier-case': 'off',
11+
'unicorn/no-null': 'off',
12+
'unicorn/no-array-reduce': 'off',
13+
'unicorn/no-array-callback-reference': 'off',
14+
'unicorn/no-array-method-this-argument': 'off',
2515
},
2616
};

node-javascript.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module.exports = {
2-
extends: ['./configs/eslint', 'prettier'],
2+
extends: ['./configs/eslint', './configs/unicorn'],
3+
rules: {
4+
'no-console': 'off',
5+
6+
'unicorn/no-process-exit': 'off',
7+
'unicorn/prefer-module': 'off',
8+
'unicorn/prefer-top-level-await': 'off',
9+
},
310
};

node-typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ['./configs/eslint', './configs/typescript', 'prettier'],
2+
extends: ['./node-javascript', './configs/typescript'],
33
};

package.json

+14-15
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@
3838
"release:beta": "release-it --preRelease=beta --no-git.requireUpstream",
3939
"prepare": "husky install"
4040
},
41+
"lint-staged": {
42+
"*.{md,json,js}": "prettier --write ."
43+
},
44+
"dependencies": {
45+
"eslint-config-prettier": "^8.5.0",
46+
"eslint-plugin-unicorn": "^43.0.2"
47+
},
48+
"devDependencies": {
49+
"@release-it/conventional-changelog": "^5.0.0",
50+
"husky": "^8.0.1",
51+
"lint-staged": "^12.3.7",
52+
"prettier": "^2.7.1",
53+
"release-it": "^15.0.0"
54+
},
4155
"peerDependencies": {
4256
"@typescript-eslint/eslint-plugin": "~5.31.0",
4357
"@typescript-eslint/parser": "~5.31.0",
4458
"eslint": "~8.20.0",
45-
"eslint-config-prettier": "^8.5.0",
4659
"eslint-plugin-jest": "^26.1.5",
4760
"eslint-plugin-jsx-a11y": "^6.5.1",
4861
"eslint-plugin-prettier": "^4.2.0",
4962
"eslint-plugin-react": "^7.29.4",
5063
"eslint-plugin-react-hooks": "^4.4.0",
5164
"eslint-plugin-react-native": "^4.0.0",
5265
"eslint-plugin-simple-import-sort": "^7.0.0",
53-
"eslint-plugin-unicorn": "^42.0.0",
5466
"prettier": "^2.7.0"
5567
},
5668
"peerDependenciesMeta": {
@@ -77,19 +89,6 @@
7789
},
7890
"eslint-plugin-simple-import-sort": {
7991
"optional": true
80-
},
81-
"eslint-plugin-unicorn": {
82-
"optional": true
8392
}
84-
},
85-
"devDependencies": {
86-
"@release-it/conventional-changelog": "^5.0.0",
87-
"husky": "^8.0.1",
88-
"lint-staged": "^12.3.7",
89-
"prettier": "^2.7.1",
90-
"release-it": "^15.0.0"
91-
},
92-
"lint-staged": {
93-
"*.{md,json,js}": "prettier --write ."
9493
}
9594
}

react-javascript.js

+41-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
module.exports = {
2-
extends: [
3-
'./configs/eslint',
4-
'./configs/unicorn',
5-
'./configs/react',
6-
'prettier',
7-
],
2+
plugins: ['simple-import-sort'],
3+
extends: ['./configs/eslint', './configs/unicorn', './configs/react'],
4+
rules: {
5+
'no-underscore-dangle': 'off',
6+
7+
'unicorn/filename-case': 'off',
8+
'unicorn/no-thenable': 'off',
9+
'unicorn/no-useless-undefined': 'off',
10+
'unicorn/numeric-separators-style': 'off',
11+
'unicorn/prefer-module': 'off',
12+
'unicorn/prefer-node-protocol': 'off',
13+
'unicorn/prefer-regexp-test': 'off',
14+
'unicorn/prefer-set-has': 'off',
15+
'unicorn/prefer-spread': 'off',
16+
'unicorn/template-indent': 'off',
17+
'unicorn/text-encoding-identifier-case': 'off',
18+
19+
'simple-import-sort/exports': 'error',
20+
'simple-import-sort/imports': [
21+
'error',
22+
{
23+
groups: [
24+
['^\\u0000'],
25+
[
26+
'^react',
27+
'^react-native',
28+
'^next',
29+
'^axios',
30+
'^graphql',
31+
'^urql',
32+
'^styled-components',
33+
'^pages',
34+
'^views',
35+
'^@?\\w',
36+
],
37+
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
38+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
39+
],
40+
},
41+
],
42+
},
843
};

react-native.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ module.exports = {
22
env: {
33
'react-native/react-native': true,
44
},
5-
extends: [
6-
'./configs/eslint',
7-
'./configs/typescript',
8-
'./configs/unicorn',
9-
'./configs/react',
10-
'./configs/react-native',
11-
'prettier',
12-
],
5+
extends: ['./react-typescript', './configs/react-native'],
6+
rules: {
7+
'@typescript-eslint/no-use-before-define': 'off',
8+
'@typescript-eslint/no-require-imports': 'off',
9+
},
1310
};

react-typescript.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module.exports = {
2-
extends: [
3-
'./configs/eslint',
4-
'./configs/typescript',
5-
'./configs/unicorn',
6-
'./configs/react',
7-
'prettier',
8-
],
2+
extends: ['./react-javascript', './configs/typescript'],
3+
rules: {
4+
'@typescript-eslint/no-confusing-void-expression': 'off',
5+
'@typescript-eslint/no-misused-promises': 'off',
6+
},
97
};

0 commit comments

Comments
 (0)