Skip to content

Commit

Permalink
chore: 增加husky、lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxudong committed Apr 9, 2021
1 parent d91ac9e commit 087c294
Show file tree
Hide file tree
Showing 11 changed files with 1,352 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/dist
*.html
*.min.js
*.min.ts
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ module.exports = {
],
quotes: ['error', 'single', { allowTemplateLiterals: true }], // 字符串使用单引号/模版字符串
'import/no-absolute-path': [0], // 关闭不能使用绝对路径导入模块 @ 别名
'import/no-unresolved': [0],
'import/no-unresolved': [0], // 关闭不能使用 @ 导入模块
'vue/comment-directive': [0, {
reportUnusedDisableDirectives: false,
}],
'no-restricted-globals': [0], // 关闭不能使用 isNaN 等方法
},
overrides: [
Expand All @@ -33,7 +36,7 @@ module.exports = {
// @路径引入的文件也需要校验
'import/resolver': {
alias: {
map: [['@', './src']],
map: [['@', '/src']],
extensions: ['.ts', '.js', '.jsx', '.json', '.vue'],
},
},
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ dist
dist-ssr
*.local

*.log
package-lock.json
*.log
*.lock
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# npx --no-install commitlint --edit "$1"
yarn commitlint --edit "$1"
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# npm test
yarn lint-staged --allow-empty "$1"
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{js,vue}": ["npm run lint"],
"*.{html,vue,css,scss,sass,less}": ["stylelint --fix"]
}
18 changes: 9 additions & 9 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ module.exports = {
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert'],
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore'],
],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never'],
},
};
// 用 于说明 commit 的'别,只允许使'下面7个标识
// commit 的内容,只允许使用下面7个标识

// feat新功能('eat're)
// fix修补bug
// docs文档(documentation)
// style格式(不影响代码运行的变动)
// refactor重构(即不是新增功能,也不是修改bug的代码变动)
// test增加测试
// chore构建过程或辅助工具的变动
// feat: 新功能
// fix: 修补bug
// docs: 文档(documentation)
// style: 样式/格式(不影响代码运行的变动)
// refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
// test: 增加测试
// chore: 构建过程或辅助工具的变动
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build:beta": "vite build --mode beta",
"build:release": "vite build --mode release",
"serve": "vite preview",
"lint": "eslint . --ext .js,.ts,.vue --ignore-path .gitignore",
"prepare": "husky install"
},
"dependencies": {
Expand All @@ -19,6 +20,8 @@
"vue-router": "4"
},
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@vue/cli-plugin-babel": "^4.5.12",
"@vue/compiler-sfc": "^3.0.5",
"babel-plugin-component": "^1.1.1",
Expand All @@ -30,7 +33,9 @@
"eslint-plugin-vue": "^7.8.0",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"sass": "^1.32.8"
"sass": "^1.32.8",
"stylelint": "^13.12.0",
"stylelint-config-standard": "^21.0.0"
},
"browserslist": [
"> 1%",
Expand Down
10 changes: 10 additions & 0 deletions stylelint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
processors: [],
plugins: [],
extends: 'stylelint-config-standard', // 官方推荐的方式
rules: {
'at-rule-empty-line-before': 'never',
'at-rule-name-case': 'lower',
'block-no-empty': true,
},
};
Loading

0 comments on commit 087c294

Please sign in to comment.