Skip to content

Commit 57c2d19

Browse files
committed
feat: update config
1 parent 19688ce commit 57c2d19

File tree

4 files changed

+72
-40
lines changed

4 files changed

+72
-40
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules
2-
dist
2+
lib
33
!.prettierrc.js
44
!.eslintrc.js
55
!.stylelintrc.js

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"prettier"
3030
],
3131
"dependencies": {
32+
"@babel/core": "^7.14.0",
33+
"@babel/eslint-parser": "^7.13.14",
3234
"@typescript-eslint/eslint-plugin": "^4.22.0",
3335
"@typescript-eslint/parser": "^4.22.0",
3436
"eslint": "^7.25.0",

src/eslint.ts

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,69 @@
1-
module.exports = {
2-
env: {
3-
node: true,
4-
browser: true,
5-
es6: true,
6-
},
7-
parser: '@typescript-eslint/parser',
8-
extends: [
1+
import fs from 'fs'
2+
import path from 'path'
3+
4+
const IS_TS_PROJECT = fs.existsSync(
5+
path.join(process.cwd() || '.', './tsconfig.json')
6+
)
7+
8+
const parser = IS_TS_PROJECT
9+
? '@typescript-eslint/parser'
10+
: '@babel/eslint-parser'
11+
12+
const _extends = (() => {
13+
return [
914
'eslint:recommended',
15+
IS_TS_PROJECT ? 'plugin:@typescript-eslint/recommended' : null,
1016
'plugin:import/errors',
1117
'plugin:import/warnings',
1218
'plugin:import/typescript',
13-
'plugin:@typescript-eslint/recommended',
1419
'plugin:jsx-a11y/recommended',
1520
'plugin:react/recommended',
1621
'plugin:react-hooks/recommended',
1722
'plugin:prettier/recommended',
23+
].filter(el => el && typeof el === 'string')
24+
})()
25+
26+
const rules = {
27+
'simple-import-sort/imports': 1,
28+
'simple-import-sort/exports': 1,
29+
'sort-imports': 0,
30+
'import/order': 0,
31+
'react/jsx-sort-props': [
32+
2,
33+
{
34+
callbacksLast: true,
35+
shorthandFirst: true,
36+
shorthandLast: false,
37+
ignoreCase: false,
38+
noSortAlphabetically: false,
39+
reservedFirst: true,
40+
},
1841
],
19-
plugins: ['simple-import-sort'],
20-
rules: {
21-
'simple-import-sort/imports': 1,
22-
'simple-import-sort/exports': 1,
23-
'sort-imports': 0,
24-
'import/order': 0,
25-
'@typescript-eslint/no-var-requires': 0,
26-
'@typescript-eslint/no-non-null-assertion': 0,
27-
'@typescript-eslint/no-use-before-define': 2,
28-
'@typescript-eslint/explicit-module-boundary-types': 0,
29-
'@typescript-eslint/consistent-type-imports': [
30-
2,
31-
{
32-
prefer: 'type-imports',
33-
disallowTypeAnnotations: true,
34-
},
35-
],
36-
'react/jsx-sort-props': [
37-
2,
38-
{
39-
callbacksLast: true,
40-
shorthandFirst: true,
41-
shorthandLast: false,
42-
ignoreCase: false,
43-
noSortAlphabetically: false,
44-
reservedFirst: true,
45-
},
46-
],
42+
...(IS_TS_PROJECT
43+
? {
44+
'@typescript-eslint/no-var-requires': 0,
45+
'@typescript-eslint/no-non-null-assertion': 0,
46+
'@typescript-eslint/no-use-before-define': 2,
47+
'@typescript-eslint/explicit-module-boundary-types': 0,
48+
'@typescript-eslint/consistent-type-imports': [
49+
2,
50+
{
51+
prefer: 'type-imports',
52+
disallowTypeAnnotations: true,
53+
},
54+
],
55+
}
56+
: {}),
57+
}
58+
59+
module.exports = {
60+
env: {
61+
node: true,
62+
browser: true,
63+
es6: true,
4764
},
65+
parser,
66+
extends: _extends,
67+
plugins: ['simple-import-sort'],
68+
rules,
4869
}

yarn.lock

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
resolved "https://registry.nlark.com/@babel/compat-data/download/@babel/compat-data-7.14.0.tgz?cache=0&sync_timestamp=1619727645372&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fcompat-data%2Fdownload%2F%40babel%2Fcompat-data-7.14.0.tgz#a901128bce2ad02565df95e6ecbf195cf9465919"
2222
integrity sha1-qQESi84q0CVl35Xm7L8ZXPlGWRk=
2323

24-
"@babel/core@>=7.2.2", "@babel/core@>=7.9.0":
24+
"@babel/core@>=7.2.2", "@babel/core@>=7.9.0", "@babel/core@^7.14.0":
2525
version "7.14.0"
2626
resolved "https://registry.nlark.com/@babel/core/download/@babel/core-7.14.0.tgz?cache=0&sync_timestamp=1619727432493&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fcore%2Fdownload%2F%40babel%2Fcore-7.14.0.tgz#47299ff3ec8d111b493f1a9d04bf88c04e728d88"
2727
integrity sha1-Rymf8+yNERtJPxqdBL+IwE5yjYg=
@@ -42,6 +42,15 @@
4242
semver "^6.3.0"
4343
source-map "^0.5.0"
4444

45+
"@babel/eslint-parser@^7.13.14":
46+
version "7.13.14"
47+
resolved "https://registry.npm.taobao.org/@babel/eslint-parser/download/@babel/eslint-parser-7.13.14.tgz?cache=0&sync_timestamp=1617027605652&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Feslint-parser%2Fdownload%2F%40babel%2Feslint-parser-7.13.14.tgz#f80fd23bdd839537221914cb5d17720a5ea6ba3a"
48+
integrity sha1-+A/SO92DlTciGRTLXRdyCl6mujo=
49+
dependencies:
50+
eslint-scope "^5.1.0"
51+
eslint-visitor-keys "^1.3.0"
52+
semver "^6.3.0"
53+
4554
"@babel/generator@^7.14.0":
4655
version "7.14.0"
4756
resolved "https://registry.nlark.com/@babel/generator/download/@babel/generator-7.14.0.tgz?cache=0&sync_timestamp=1619727181234&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fgenerator%2Fdownload%2F%40babel%2Fgenerator-7.14.0.tgz#0f35d663506c43e4f10898fbda0d752ec75494be"
@@ -1281,7 +1290,7 @@ eslint-plugin-simple-import-sort@^7.0.0:
12811290
resolved "https://registry.npm.taobao.org/eslint-plugin-simple-import-sort/download/eslint-plugin-simple-import-sort-7.0.0.tgz#a1dad262f46d2184a90095a60c66fef74727f0f8"
12821291
integrity sha1-odrSYvRtIYSpAJWmDGb+90cn8Pg=
12831292

1284-
eslint-scope@^5.0.0, eslint-scope@^5.1.1:
1293+
eslint-scope@^5.0.0, eslint-scope@^5.1.0, eslint-scope@^5.1.1:
12851294
version "5.1.1"
12861295
resolved "https://registry.npm.taobao.org/eslint-scope/download/eslint-scope-5.1.1.tgz?cache=0&sync_timestamp=1599933651660&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Feslint-scope%2Fdownload%2Feslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
12871296
integrity sha1-54blmmbLkrP2wfsNUIqrF0hI9Iw=

0 commit comments

Comments
 (0)