Skip to content

Commit dea9047

Browse files
authored
chore: add eslint rule (#400)
* chore: add eslint prettier stylelint rule * fix: fix vars.css
1 parent 02ff882 commit dea9047

13 files changed

+1289
-142
lines changed

.commitlintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

.eslintrc.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
browser: true,
6+
es6: true,
7+
},
8+
extends: ['eslint:recommended', 'prettier'],
9+
plugins: ['html', 'prettier'],
10+
rules: {
11+
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
12+
},
13+
};

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit "$1"

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged && log_emails=$(git config user.email) && if [[ ${log_emails} =~ '@tencent.com' ]];then echo 本地提交邮箱 $log_emails 校验非法,需要本地更改重新提交 && exit 2;else echo 邮箱 $log_emails 校验通过;fi

.husky/prepare-commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx czg --hook || true

.prettierrc.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
// 一行最多 120 字符
3+
printWidth: 120,
4+
// 使用 2 个空格缩进
5+
tabWidth: 2,
6+
// 不使用缩进符,而使用空格
7+
useTabs: false,
8+
// 行尾需要有分号
9+
semi: true,
10+
// 使用单引号
11+
singleQuote: true,
12+
// 对象的 key 仅在必要时用引号
13+
quoteProps: 'as-needed',
14+
// jsx 不使用单引号,而使用双引号
15+
jsxSingleQuote: false,
16+
// 末尾需要有逗号
17+
trailingComma: 'all',
18+
// 大括号内的首尾需要空格
19+
bracketSpacing: true,
20+
// 箭头函数,只有一个参数的时候,也需要括号
21+
arrowParens: 'always',
22+
// 每个文件格式化的范围是文件的全部内容
23+
rangeStart: 0,
24+
rangeEnd: Infinity,
25+
// 不需要写文件开头的 @prettier
26+
requirePragma: false,
27+
// 不需要自动在文件开头插入 @prettier
28+
insertPragma: false,
29+
// 使用默认的折行标准
30+
proseWrap: 'preserve',
31+
// 根据显示样式决定 html 要不要折行
32+
htmlWhitespaceSensitivity: 'css',
33+
// vue 文件中的 script 和 style 内不用缩进
34+
vueIndentScriptAndStyle: false,
35+
// 换行符使用 lf
36+
endOfLine: 'lf',
37+
};

.stylelintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: ['stylelint-config-standard', 'stylelint-config-standard-less'],
3+
rules: {
4+
'number-leading-zero': 'never',
5+
'color-function-notation': 'legacy',
6+
'alpha-value-notation': 'number',
7+
},
8+
};

package.json

+35-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,43 @@
77
"dev:theme-generator": "pnpm run --filter 'tdesign-theme-generator' dev",
88
"build:components": "pnpm run --filter 'tdesign-site-components' build && pnpm run --filter 'tdesign-site-components' postbuild",
99
"site": "npm run build:components && cd site && npm run build",
10-
"site:intranet": "npm run build:components && cd site && vite build --mode intranet"
10+
"site:intranet": "npm run build:components && cd site && vite build --mode intranet",
11+
"prepare": "husky install"
1112
},
1213
"license": "MIT",
1314
"dependencies": {
1415
"prismjs": "^1.29.0"
16+
},
17+
"devDependencies": {
18+
"@commitlint/cli": "^8.2.0",
19+
"@commitlint/config-conventional": "^8.2.0",
20+
"cz-conventional-changelog": "^3.0.2",
21+
"eslint": "^7.32.0",
22+
"eslint-config-prettier": "^9.0.0",
23+
"eslint-config-recommended": "^4.1.0",
24+
"eslint-plugin-html": "^7.1.0",
25+
"eslint-plugin-prettier": "^5.0.0",
26+
"husky": "^8.0.0",
27+
"lint-staged": "8.1.5",
28+
"prettier": "^3.0.3",
29+
"stylelint": "^15.10.3",
30+
"stylelint-config-standard": "^34.0.0",
31+
"stylelint-config-standard-less": "^2.0.0"
32+
},
33+
"config": {
34+
"commitizen": {
35+
"path": "./node_modules/cz-conventional-changelog"
36+
}
37+
},
38+
"lint-staged": {
39+
"*.{vue,js,html}": [
40+
"eslint --fix",
41+
"prettier --write",
42+
"git add"
43+
],
44+
"*.{less,css}": [
45+
"stylelint --fix",
46+
"git add"
47+
]
1548
}
16-
}
49+
}

packages/components/.eslintrc.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
root: true,
5+
extends: ['./../../.eslintrc.js'],
6+
parserOptions: {
7+
sourceType: 'module',
8+
parser: '@babel/eslint-parser',
9+
babelOptions: {
10+
configFile: path.resolve(__dirname, './babelrc'),
11+
},
12+
},
13+
rules: {},
14+
};

packages/theme-generator/.eslintrc.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
root: true,
5+
extends: ['plugin:vue/essential', './../../.eslintrc.js'],
6+
parserOptions: {
7+
parser: '@babel/eslint-parser',
8+
babelOptions: {
9+
configFile: path.resolve(__dirname, './babel.config.js'),
10+
},
11+
},
12+
rules: {},
13+
};

packages/theme-generator/package.json

-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@vue/cli-plugin-babel": "~5.0.0",
3939
"@vue/cli-plugin-eslint": "~5.0.0",
4040
"@vue/cli-service": "~5.0.0",
41-
"eslint": "^7.32.0",
4241
"eslint-plugin-vue": "^8.0.3",
4342
"less": "^4.1.2",
4443
"less-loader": "^10.2.0",
@@ -47,20 +46,6 @@
4746
"vue-svg-loader": "^0.17.0-beta.2",
4847
"vue-template-compiler": "2.7.14"
4948
},
50-
"eslintConfig": {
51-
"root": true,
52-
"env": {
53-
"node": true
54-
},
55-
"extends": [
56-
"plugin:vue/essential",
57-
"eslint:recommended"
58-
],
59-
"parserOptions": {
60-
"parser": "@babel/eslint-parser"
61-
},
62-
"rules": {}
63-
},
6449
"browserslist": [
6550
"> 1%",
6651
"last 2 versions",

0 commit comments

Comments
 (0)