Skip to content

Commit 16c924a

Browse files
author
公众号:Rong姐姐好可爱
authored
fix(lint): 修复提交自动格式化,改良lint-staged配置 (#96)
1 parent 8f9a0c6 commit 16c924a

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

.lintstagedrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// 参考: https://www.npmjs.com/package/lint-staged#configuration
2+
// 对add的内容格式化后再commit
23
module.exports = {
3-
"*.*": "./scripts/lint"
4+
"*.{js,ts,md}":[
5+
"./scripts/lint --fix",
6+
"git add"
7+
]
48
}

artalk.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
## 接入Artalk评论系统
1+
# 接入Artalk评论系统
32

43
```bash
54

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.2-alpha.8",
55
"authorInfo": {
66
"name": "微信公众号:储凡",
7-
"email": "fairy_408@2925.com",
7+
"email": "fairy_vip@2925.com",
88
"url": "https://github.com/142vip",
99
"homePage": "https://code.142vip.cn"
1010
},
@@ -15,7 +15,7 @@
1515
},
1616
"scripts": {
1717
"preinstall": "chmod +x ./scripts/*",
18-
"prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"npx lint-staged && git add .\" && chmod +x .husky/pre-commit",
18+
"prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"npx lint-staged\" && chmod +x .husky/pre-commit",
1919
"dev": "vuepress dev docs",
2020
"build": "vuepress build docs",
2121
"build:proxy": "./scripts/bundle build_proxy",

scripts/bundle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function getGitInfo(){
4141
// 输出最近一次提交的信息
4242
return {
4343
gitHash: commitHash,
44-
gitMessage: commitMessage.join('')
44+
gitMessage: commitMessage.join(' ')
4545
}
4646
}
4747

scripts/lint

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
## - 代码
66
## - markdown文档
77
## 使用:
8-
# - ./scripts/lint
8+
# - ./scripts/lint 校验
9+
# - ./scripts/lint --fix 格式化
910
## 参考链接:
1011
## - https://eslint.org/docs/latest/use/getting-started
1112
## - https://github.com/igorshubovych/markdownlint-cli
@@ -14,9 +15,14 @@
1415
# 设置 PATH 环境变量,避免command not found问题
1516
export PATH="$(pnpm bin):$PATH"
1617

18+
# 是否fix
19+
fixed=${1}
20+
1721
# ESLint格式化代码
18-
eslint --fix --ext .js,.ts,.vue --ignore-path .gitignore .
22+
echo "step1: eslint $fixed --ext .js,.ts,.vue --ignore-path .gitignore ."
23+
eslint $fixed --ext .js,.ts,.vue --ignore-path .gitignore .
1924

2025
# markdown-cli格式化markdown 文档
21-
markdownlint '**/*.md' -c .markdownlint.js -p .markdownlintignore --fix
26+
echo "step2: markdownlint '**/*.md' -c .markdownlint.js -p .markdownlintignore $fixed"
27+
markdownlint '**/*.md' -c .markdownlint.js -p .markdownlintignore $fixed
2228

0 commit comments

Comments
 (0)