Skip to content

Commit d59e67a

Browse files
committed
feat: access import/order
1 parent 8ac35cc commit d59e67a

15 files changed

Lines changed: 296 additions & 136 deletions

File tree

.eslintrc.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module.exports = {
2+
plugins: ['import'],
3+
// parserOptions: {
4+
// sourceType: module,
5+
// ecmaVersion: 6,
6+
// },
7+
rules: {
8+
'prefer-arrow-callback': [0, { allowNamedFunctions: 0 }],
9+
'react/display-name': 0,
10+
'no-console': 0,
11+
'import/no-unresolved': 'error',
12+
'import/order': [
13+
'error',
14+
{
15+
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'unknown'],
16+
pathGroups: [
17+
{
18+
pattern: 'react',
19+
group: 'builtin',
20+
},
21+
{
22+
pattern: 'antd',
23+
group: 'external',
24+
},
25+
{
26+
pattern: 'lodash',
27+
group: 'external',
28+
position: 'before',
29+
},
30+
{
31+
pattern: '@/components/**',
32+
group: 'internal',
33+
position: 'before',
34+
},
35+
{
36+
pattern: '@/utils/**',
37+
group: 'internal',
38+
position: 'before',
39+
},
40+
{
41+
pattern: '@/hooks/**',
42+
group: 'internal',
43+
position: 'before',
44+
},
45+
{
46+
pattern: '@/api/**',
47+
group: 'internal',
48+
position: 'before',
49+
},
50+
{
51+
pattern: '@/constants/**',
52+
group: 'internal',
53+
position: 'after',
54+
},
55+
],
56+
},
57+
],
58+
},
59+
settings: {
60+
'import/parsers': {
61+
'@typescript-eslint/parser': ['.ts', '.tsx'],
62+
},
63+
'import/resolver': {
64+
typescript: {
65+
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
66+
},
67+
},
68+
},
69+
extends: [
70+
'eslint-config-ali/typescript/react',
71+
'prettier',
72+
// 'prettier/@typescript-eslint',
73+
// 'prettier/react',
74+
],
75+
};

.vscode/extensions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"recommendations": [
33
"dbaeumer.vscode-eslint",
4-
"editorconfig.editorconfig",
4+
"stylelint.vscode-stylelint",
55
"esbenp.prettier-vscode",
6-
"stylelint.vscode-stylelint"
6+
"editorconfig.editorconfig"
77
]
88
}

.vscode/settings.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
2-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
3-
"stylelint.validate": ["css", "scss", "less"],
2+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
3+
"stylelint.validate": ["css", "scss", "less", "acss"],
44
"editor.codeActionsOnSave": {
55
"source.fixAll.eslint": "explicit",
6-
"source.fixAll.stylelint": "explicit",
7-
"source.organizeImports": "explicit"
6+
"source.fixAll.stylelint": "explicit"
7+
// TODO:
8+
// "source.organizeImports": "explicit"
89
},
9-
"editor.rulers": [100],
1010
"editor.defaultFormatter": "esbenp.prettier-vscode",
11-
"editor.formatOnSave": true,
1211
"[javascript]": {
1312
"editor.defaultFormatter": "esbenp.prettier-vscode"
1413
},
@@ -41,5 +40,7 @@
4140
},
4241
"[jsonc]": {
4342
"editor.defaultFormatter": "esbenp.prettier-vscode"
44-
}
43+
},
44+
"editor.formatOnSave": true,
45+
"editor.rulers": [100]
4546
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## less 配置
66

7-
yarn add less-loader style-loader css-loader -D
7+
pnpm add less-loader style-loader css-loader -D
88

99
## TODO
1010

config/webpack.config.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
英文官网:https://webpack.js.org/
44
其他中文网:https://webpack.docschina.org/
55
*/
6+
const path = require('path');
67
const webpack = require('webpack');
78
// html-webpack-plugin:https://www.webpackjs.com/plugins/html-webpack-plugin/
89
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -22,8 +23,6 @@ const tsImportPluginFactory = require('ts-import-plugin');
2223
// 生成包含构建hash的json文件:SPA会定期把初始 hash 和远程的 hash 相比较,并在不匹配的时候重新加载。
2324
const BuildHashPlugin = require('build-hash-webpack-plugin');
2425

25-
const path = require('path');
26-
2726
const prodMode = process.env.NODE_ENV === 'production';
2827
const resolvePath = (dir) => path.join(__dirname, '..', dir);
2928
// https://cdn.baomitu.com
@@ -246,12 +245,12 @@ module.exports = {
246245
// 路径别名
247246
alias: {
248247
'@': resolvePath('src'),
249-
'@constant': resolvePath('src/constant'),
250-
'@components': resolvePath('src/components'),
251-
'@api': resolvePath('src/api'),
252-
'@utils': resolvePath('src/utils'),
253-
'@css': resolvePath('src/assets/css'),
254-
'@img': resolvePath('src/assets/img'),
248+
'@/constant': resolvePath('src/constant'),
249+
'@/components': resolvePath('src/components'),
250+
'@/api': resolvePath('src/api'),
251+
'@/utils': resolvePath('src/utils'),
252+
'@/css': resolvePath('src/assets/css'),
253+
'@/img': resolvePath('src/assets/img'),
255254
},
256255
},
257256
optimization: {

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"eslint": "^8.57.1",
7373
"eslint-config-ali": "^15.1.0",
7474
"eslint-config-prettier": "^9.1.0",
75+
"eslint-import-resolver-typescript": "^3.7.0",
76+
"eslint-plugin-import": "^2.31.0",
7577
"eslint-plugin-prettier": "^5.2.1",
7678
"extract-text-webpack-plugin": "^3.0.2",
7779
"file-loader": "^6.2.0",
@@ -108,6 +110,18 @@
108110
"webpack-parallel-uglify-plugin": "^2.0.0",
109111
"webpackbar": "^6.0.1"
110112
},
113+
"engines": {
114+
"node": ">=16.0.0"
115+
},
116+
"cnpm": {
117+
"mode": "pnpm"
118+
},
119+
"npm": {
120+
"mode": "pnpm"
121+
},
122+
"yarn": {
123+
"mode": "pnpm"
124+
},
111125
"commitlint": {
112126
"extends": [
113127
"ali"
@@ -142,8 +156,5 @@
142156
"stylelint-config-ali",
143157
"stylelint-prettier/recommended"
144158
]
145-
},
146-
"engines": {
147-
"node": ">=16.0.0"
148159
}
149160
}

0 commit comments

Comments
 (0)