Skip to content

Commit a220414

Browse files
committed
增加eslint校验
1 parent 3e12a7a commit a220414

35 files changed

+1890
-1324
lines changed

.eslintrc.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = {
2+
parser: 'vue-eslint-parser',
3+
parserOptions: {
4+
parser: '@typescript-eslint/parser',
5+
sourceType: 'module',
6+
ecmaFeatures: {
7+
jsx: true,
8+
tsx: true
9+
}
10+
},
11+
env: {
12+
browser: true,
13+
node: true
14+
},
15+
plugins: ['@typescript-eslint'],
16+
extends: ['plugin:@typescript-eslint/recommended', 'plugin:vue/vue3-recommended'],
17+
rules: {
18+
'@typescript-eslint/ban-ts-ignore': 'off',
19+
'@typescript-eslint/explicit-function-return-type': 'off',
20+
'@typescript-eslint/no-explicit-any': 'off',
21+
'@typescript-eslint/no-var-requires': 'off',
22+
'@typescript-eslint/no-empty-function': 'off',
23+
'vue/custom-event-name-casing': 'off',
24+
'no-use-before-define': 'off',
25+
'@typescript-eslint/no-use-before-define': 'off',
26+
'@typescript-eslint/ban-ts-comment': 'off',
27+
'@typescript-eslint/ban-types': 'off',
28+
'@typescript-eslint/no-non-null-assertion': 'off',
29+
'@typescript-eslint/explicit-module-boundary-types': 'off',
30+
'vue/html-indent': ['error', 4],
31+
indent: ['error', 4], // 4行缩进
32+
'vue/script-indent': ['error', 4],
33+
quotes: ['error', 'single'], // 单引号
34+
'vue/html-quotes': ['error', 'single'],
35+
semi: ['error', 'never'], // 禁止使用分号
36+
'space-infix-ops': ['error', { int32Hint: false }], // 要求操作符周围有空格
37+
'no-multi-spaces': 'error', // 禁止多个空格
38+
'no-whitespace-before-property': 'error', // 禁止在属性前使用空格
39+
'space-before-blocks': 'error', // 在块之前强制保持一致的间距
40+
'space-before-function-paren': ['error', 'never'], // 在“ function”定义打开括号之前强制不加空格
41+
'space-in-parens': ['error', 'never'], // 强制括号左右的不加空格
42+
'space-infix-ops': 'error', // 运算符之间留有间距
43+
'spaced-comment': ['error', 'always'], // 注释间隔
44+
'template-tag-spacing': ['error', 'always'], // 在模板标签及其文字之间需要空格
45+
'no-var': 'error',
46+
'prefer-destructuring': [
47+
'error',
48+
{
49+
// 优先使用数组和对象解构
50+
array: true,
51+
object: true
52+
},
53+
{
54+
enforceForRenamedProperties: false
55+
}
56+
],
57+
'comma-dangle': ['error', 'never'], // 最后一个属性不允许有逗号
58+
'arrow-spacing': 'error', // 箭头函数空格
59+
'prefer-template': 'error',
60+
'template-curly-spacing': 'error',
61+
'quote-props': ['error', 'as-needed'], // 对象字面量属性名称使用引号
62+
'object-curly-spacing': ['error', 'always'], // 强制在花括号中使用一致的空格
63+
'no-unneeded-ternary': 'error', // 禁止可以表达为更简单结构的三元操作符
64+
'no-restricted-syntax': ['error', 'WithStatement', 'BinaryExpression[operator="in"]'], // 禁止with/in语句
65+
'no-lonely-if': 'error', // 禁止 if 语句作为唯一语句出现在 else 语句块中
66+
'newline-per-chained-call': ['error', { ignoreChainWithDepth: 2 }], // 要求方法链中每个调用都有一个换行符
67+
// 路径别名设置
68+
'no-submodule-imports': ['off', '/@'],
69+
'no-implicit-dependencies': ['off', ['/@']],
70+
'@typescript-eslint/no-explicit-any': 'off' // 类型可以使用any
71+
}
72+
}

babel.config.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* @LastEditTime: 2021-02-05 10:37:28
77
*/
88
module.exports = {
9-
presets: ['@vue/cli-plugin-babel/preset'],
10-
// plugins: [
11-
// [
12-
// 'component',
13-
// {
14-
// libraryName: 'element-plus',
15-
// styleLibraryName: 'theme-chalk',
16-
// },
17-
// ],
18-
// ],
19-
};
9+
presets: ['@vue/cli-plugin-babel/preset']
10+
// plugins: [
11+
// [
12+
// 'component',
13+
// {
14+
// libraryName: 'element-plus',
15+
// styleLibraryName: 'theme-chalk',
16+
// },
17+
// ],
18+
// ],
19+
}

client.d.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88

99
// CSS
1010
declare module '*.css' {
11-
const css: string;
12-
export default css;
11+
const css: string
12+
export default css
1313
}
1414
declare module '*.scss' {
15-
const css: string;
16-
export default css;
15+
const css: string
16+
export default css
1717
}
1818
declare module '*.sass' {
19-
const css: string;
20-
export default css;
19+
const css: string
20+
export default css
2121
}
2222
declare module '*.less' {
23-
const css: string;
24-
export default css;
23+
const css: string
24+
export default css
2525
}
2626
declare module '*.styl' {
27-
const css: string;
28-
export default css;
27+
const css: string
28+
export default css
2929
}
3030
declare module '*.stylus' {
31-
const css: string;
32-
export default css;
31+
const css: string
32+
export default css
3333
}

package.json

+48-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
11
{
2-
"name": "vue3_pc_elementplus_tailwind",
3-
"version": "0.1.0",
4-
"private": true,
5-
"homepage": "https://xiukun.github.io/vue3-pc-elementPlus-tailwind/",
6-
"scripts": {
7-
"serve": "vue-cli-service serve",
8-
"build": "vue-cli-service build",
9-
"stylelint": "npx stylelint **/*.{css,vue} --fix",
10-
"deploy": "bash deploy.sh"
11-
},
12-
"dependencies": {
13-
"axios": "^0.21.1",
14-
"core-js": "^3.6.5",
15-
"element-plus": "^1.0.2-beta.31",
16-
"lodash-es": "^4.17.20",
17-
"nprogress": "^0.2.0",
18-
"vue": "3.0.5",
19-
"vue-router": "4.0.3",
20-
"vuex": "4.0.0-rc.2"
21-
},
22-
"devDependencies": {
23-
"@types/lodash-es": "^4.17.4",
24-
"@types/mockjs": "^1.0.3",
25-
"@types/nprogress": "^0.2.0",
26-
"@vue/cli-plugin-babel": "~4.5.0",
27-
"@vue/cli-plugin-router": "~4.5.0",
28-
"@vue/cli-plugin-typescript": "~4.5.0",
29-
"@vue/cli-plugin-vuex": "~4.5.0",
30-
"@vue/cli-service": "~4.5.0",
31-
"@vue/compiler-sfc": "^3.0.0",
32-
"autoprefixer": "^9",
33-
"babel-plugin-component": "^1.1.1",
34-
"mockjs": "^1.1.0",
35-
"postcss": "^8.2.5",
36-
"sass": "^1.32.8",
37-
"sass-loader": "10.x",
38-
"tailwindcss": "^2.0.3",
39-
"typescript": "~3.9.3"
40-
}
2+
"name": "vue3_pc_elementplus_tailwind",
3+
"version": "0.1.0",
4+
"private": true,
5+
"homepage": "https://xiukun.github.io/vue3-pc-elementPlus-tailwind/",
6+
"scripts": {
7+
"serve": "vue-cli-service serve",
8+
"build": "vue-cli-service build",
9+
"stylelint": "npx stylelint **/*.{css,vue} --fix",
10+
"eslint": "npx eslint . --ext .js,.jsx,.ts,.tsx --fix",
11+
"deploy": "bash deploy.sh"
12+
},
13+
"dependencies": {
14+
"axios": "^0.21.1",
15+
"core-js": "^3.6.5",
16+
"element-plus": "^1.0.2-beta.31",
17+
"lodash-es": "^4.17.20",
18+
"nprogress": "^0.2.0",
19+
"vue": "3.0.5",
20+
"vue-router": "4.0.3",
21+
"vuex": "4.0.0-rc.2"
22+
},
23+
"devDependencies": {
24+
"@types/lodash-es": "^4.17.4",
25+
"@types/mockjs": "^1.0.3",
26+
"@types/nprogress": "^0.2.0",
27+
"@typescript-eslint/eslint-plugin": "^4.9.1",
28+
"@typescript-eslint/parser": "^4.9.1",
29+
"@vue/cli-plugin-babel": "~4.5.0",
30+
"@vue/cli-plugin-router": "~4.5.0",
31+
"@vue/cli-plugin-typescript": "~4.5.0",
32+
"@vue/cli-plugin-vuex": "~4.5.0",
33+
"@vue/cli-service": "~4.5.0",
34+
"@vue/compiler-sfc": "^3.0.0",
35+
"autoprefixer": "^9",
36+
"babel-plugin-component": "^1.1.1",
37+
"eslint": "^7.15.0",
38+
"eslint-plugin-vue": "^7.2.0",
39+
"mockjs": "^1.1.0",
40+
"postcss": "^8.2.5",
41+
"sass": "^1.32.8",
42+
"sass-loader": "10.x",
43+
"tailwindcss": "^2.0.3",
44+
"typescript": "~3.9.3"
45+
},
46+
"eslintIgnore": [
47+
"node_modules",
48+
"dist"
49+
]
4150
}

postcss.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
plugins: [require('tailwindcss')(), require('autoprefixer')()],
3-
};
2+
plugins: [require('tailwindcss')(), require('autoprefixer')()]
3+
}

prettier.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
printWidth: 100,
3+
tabWidth: 4,
4+
useTabs: false,
5+
semi: true, // 未尾逗号
6+
vueIndentAndStyle: true,
7+
singleQuote: true, // 单引号
8+
quoteProps: 'as-needed',
9+
bracketSpacing: true,
10+
trailingComma: 'none', // 未尾分号
11+
jsxBracketSameLine: false,
12+
jsxSingleQuote: false,
13+
arrowParens: 'always',
14+
insertPragma: false,
15+
requirePragma: false,
16+
proseWrap: 'never',
17+
htmlWhitespaceSensitivity: 'strict',
18+
endOfLine: 'lf'
19+
}

src/api/components/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
* @LastEditors: xiukun@herry
66
* @LastEditTime: 2021-02-07 17:45:44
77
*/
8-
import { http } from '@/core/ajax';
9-
import { AxiosPromise } from 'axios';
8+
import { http } from '@/core/ajax'
9+
import { AxiosPromise } from 'axios'
1010
const api = {
11-
getTableList: '/getTableList',
12-
};
11+
getTableList: '/getTableList'
12+
}
1313
export type ITag = '所有' | '家' | '公司' | '学校' | '超市';
1414
export interface ITableList {
1515
page: number;
1616
size: number;
1717
tag: ITag;
1818
}
1919
export function getTableList(tableList: ITableList): AxiosPromise {
20-
return http({
21-
url: api.getTableList,
22-
method: 'get',
23-
data: tableList,
24-
});
20+
return http({
21+
url: api.getTableList,
22+
method: 'get',
23+
data: tableList
24+
})
2525
}

src/api/layout/index.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55
* @LastEditors: xiukun@herry
66
* @LastEditTime: 2021-02-08 16:20:51
77
*/
8-
import { http } from '@/core/ajax';
9-
import { AxiosPromise } from 'axios';
10-
import { store } from '@/store/index';
8+
import { http } from '@/core/ajax'
9+
import { AxiosPromise } from 'axios'
10+
import { store } from '@/store/index'
1111
const api = {
12-
login: '/login',
13-
getUser: '/getUser',
14-
getRouterList: '/getRoute',
15-
};
12+
login: '/login',
13+
getUser: '/getUser',
14+
getRouterList: '/getRoute'
15+
}
1616

1717
export interface loginParam {
1818
username: string;
1919
password: string;
2020
}
2121
export function login(param: loginParam): AxiosPromise {
22-
return http({
23-
url: api.login,
24-
method: 'post',
25-
data: param,
26-
});
22+
return http({
23+
url: api.login,
24+
method: 'post',
25+
data: param
26+
})
2727
}
2828
export function getUser(): AxiosPromise {
29-
return http({
30-
url: api.getUser,
31-
method: 'get',
32-
data: { token: store.state.layout.token },
33-
});
29+
return http({
30+
url: api.getUser,
31+
method: 'get',
32+
data: { token: store.state.layout.token }
33+
})
3434
}
3535
export function getRouterList(): AxiosPromise {
36-
return http({
37-
url: api.getRouterList,
38-
method: 'get',
39-
data: { token: store.state.layout.token },
40-
});
36+
return http({
37+
url: api.getRouterList,
38+
method: 'get',
39+
data: { token: store.state.layout.token }
40+
})
4141
}

src/components/login/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
* @LastEditors: xiukun@herry
66
* @LastEditTime: 2021-02-03 17:07:04
77
*/
8-
import LoginForm from './LoginForm.vue';
9-
import RegisterForm from './RegisterForm.vue';
10-
export { LoginForm, RegisterForm };
8+
import LoginForm from './LoginForm.vue'
9+
import RegisterForm from './RegisterForm.vue'
10+
export { LoginForm, RegisterForm }

0 commit comments

Comments
 (0)