Skip to content

Commit

Permalink
chore: add eslint rule (#400)
Browse files Browse the repository at this point in the history
* chore: add eslint prettier stylelint rule

* fix: fix vars.css
  • Loading branch information
fennghuang authored Sep 15, 2023
1 parent 02ff882 commit dea9047
Show file tree
Hide file tree
Showing 13 changed files with 1,289 additions and 142 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
env: {
node: true,
browser: true,
es6: true,
},
extends: ['eslint:recommended', 'prettier'],
plugins: ['html', 'prettier'],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
},
};
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

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
4 changes: 4 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx czg --hook || true
37 changes: 37 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
// 一行最多 120 字符
printWidth: 120,
// 使用 2 个空格缩进
tabWidth: 2,
// 不使用缩进符,而使用空格
useTabs: false,
// 行尾需要有分号
semi: true,
// 使用单引号
singleQuote: true,
// 对象的 key 仅在必要时用引号
quoteProps: 'as-needed',
// jsx 不使用单引号,而使用双引号
jsxSingleQuote: false,
// 末尾需要有逗号
trailingComma: 'all',
// 大括号内的首尾需要空格
bracketSpacing: true,
// 箭头函数,只有一个参数的时候,也需要括号
arrowParens: 'always',
// 每个文件格式化的范围是文件的全部内容
rangeStart: 0,
rangeEnd: Infinity,
// 不需要写文件开头的 @prettier
requirePragma: false,
// 不需要自动在文件开头插入 @prettier
insertPragma: false,
// 使用默认的折行标准
proseWrap: 'preserve',
// 根据显示样式决定 html 要不要折行
htmlWhitespaceSensitivity: 'css',
// vue 文件中的 script 和 style 内不用缩进
vueIndentScriptAndStyle: false,
// 换行符使用 lf
endOfLine: 'lf',
};
8 changes: 8 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: ['stylelint-config-standard', 'stylelint-config-standard-less'],
rules: {
'number-leading-zero': 'never',
'color-function-notation': 'legacy',
'alpha-value-notation': 'number',
},
};
37 changes: 35 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,43 @@
"dev:theme-generator": "pnpm run --filter 'tdesign-theme-generator' dev",
"build:components": "pnpm run --filter 'tdesign-site-components' build && pnpm run --filter 'tdesign-site-components' postbuild",
"site": "npm run build:components && cd site && npm run build",
"site:intranet": "npm run build:components && cd site && vite build --mode intranet"
"site:intranet": "npm run build:components && cd site && vite build --mode intranet",
"prepare": "husky install"
},
"license": "MIT",
"dependencies": {
"prismjs": "^1.29.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"cz-conventional-changelog": "^3.0.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-recommended": "^4.1.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.0",
"lint-staged": "8.1.5",
"prettier": "^3.0.3",
"stylelint": "^15.10.3",
"stylelint-config-standard": "^34.0.0",
"stylelint-config-standard-less": "^2.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"lint-staged": {
"*.{vue,js,html}": [
"eslint --fix",
"prettier --write",
"git add"
],
"*.{less,css}": [
"stylelint --fix",
"git add"
]
}
}
}
14 changes: 14 additions & 0 deletions packages/components/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');

module.exports = {
root: true,
extends: ['./../../.eslintrc.js'],
parserOptions: {
sourceType: 'module',
parser: '@babel/eslint-parser',
babelOptions: {
configFile: path.resolve(__dirname, './babelrc'),
},
},
rules: {},
};
13 changes: 13 additions & 0 deletions packages/theme-generator/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path');

module.exports = {
root: true,
extends: ['plugin:vue/essential', './../../.eslintrc.js'],
parserOptions: {
parser: '@babel/eslint-parser',
babelOptions: {
configFile: path.resolve(__dirname, './babel.config.js'),
},
},
rules: {},
};
15 changes: 0 additions & 15 deletions packages/theme-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"less": "^4.1.2",
"less-loader": "^10.2.0",
Expand All @@ -47,20 +46,6 @@
"vue-svg-loader": "^0.17.0-beta.2",
"vue-template-compiler": "2.7.14"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
Expand Down
Loading

0 comments on commit dea9047

Please sign in to comment.