Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

维护:增加Prettier和Git Hooks #107

Merged
merged 10 commits into from
Nov 30, 2023
Merged

维护:增加Prettier和Git Hooks #107

merged 10 commits into from
Nov 30, 2023

Conversation

northword
Copy link
Member

@northword northword commented Nov 28, 2023

请大家看下是否可行,有无必要~

变更细节

  1. 增加 prettier 来格式化 Markdown,使用 2.8.8,该版本是最后一版支持在中英文之间加入空格的版本。
    配套的,禁用了 markdownlint 中与 prettier 重叠的规则。

    .vscode/settings.json 中增加 vscode-prettier 插件的推荐,并将其设置为 VS Code 的默认格式化器。

    这意味着,如果贡献者使用 VS Code 且正确安装了插件,则所有的格式都将被自动调整。

  2. markdownlint 里启用专有名词大小写的修复,包括 ZoteroGitHub 等 —— 正常情况下,在保存时会自动修复。

    wiki/.markdownlint.json

    Lines 2 to 17 in 46a90f8

    "MD044": {
    "code_blocks": false,
    "html_elements": false,
    "names": [
    "Zotero",
    "JavaScript",
    "GitHub",
    "WebDAV",
    "Android",
    "iOS",
    "macOS",
    "WPS",
    "Word",
    "ZotFile",
    "Zotero Chinese"
    ]

  3. 增加了 lint-stagepre-commit hook —— 也许不应该加?
    提交时,将自动修正暂存区的 md 文件,绝大部分的格式问题都应被自动修复;存在不能被自动修复的将中断提交 —— 这种错误通常也会导致构建失败?
    —— 没有错误还好,如果有错误,会影响一小部分同学提交(如果这位同学处理不了)
    或许也可以考虑取消这个 git hook?

维护者需要注意的

如果这个 PR 不合并,啥也不用动。

如果这个 PR 合并,维护者需要重新安装一次依赖项:

npm install

(或是 pnpm/yarn

image

同时在 VS Code 里安装 Prettier 插件

image

Copy link

netlify bot commented Nov 28, 2023

Deploy Preview for zotero-zh ready!

Name Link
🔨 Latest commit d28f264
🔍 Latest deploy log https://app.netlify.com/sites/zotero-zh/deploys/6568275f4dd0cb0008f9d36c
😎 Deploy Preview https://deploy-preview-107--zotero-zh.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@northword northword requested a review from a team November 28, 2023 02:53
@windingwind
Copy link
Contributor

不懂但是看起来挺高级的

@northword
Copy link
Member Author

不懂但是看起来挺高级的

笑死,lint-stage 都还是从你仓库抄的代码

@volatile-static
Copy link

这个hook不会用的话可能导致git出问题,会增加写文档的门槛,建议暂时别加

@northword
Copy link
Member Author

northword commented Nov 28, 2023

另一种方案就是在 lint-stage 里只对 markdown 运行 prettier,其他的都不执行,包括 markdownlint (prettier 的规则比 markdownlint 更宽松)

wiki/package.json

Lines 30 to 35 in 3e7a3a8

"lint-staged": {
"*md": [
"prettier --write",
"markdownlint-cli2-fix"
]
}

因为 prettier --write 在修复 markdown 时似乎并不会以非零状态退出,即使内容实际上并没有符合规范,这样就可以极大避免因为 lint 的问题导致 Git 提交不了。

也可以看下是完全去掉 hook,还是用这种?

@volatile-static
Copy link

另一种方案就是在 lint-stage 里只对 markdown 运行 prettier,其他的都不执行,包括 markdownlint

wiki/package.json

Lines 30 to 35 in 3e7a3a8

"lint-staged": {
"*md": [
"prettier --write",
"markdownlint-cli2-fix"
]
}

因为 prettier --write 在修复 markdown 时似乎并不会以非零状态退出,即使内容实际上并没有符合规范,这样就可以极大避免因为 lint 的问题导致 Git 提交不了。

也可以看下是完全去掉 hook,还是用这种?

我认为只要不破坏git流程,怎么搞都无所谓

@northword northword merged commit ea27ee1 into main Nov 30, 2023
7 checks passed
@northword northword deleted the add-prettier branch November 30, 2023 06:12
northword added a commit that referenced this pull request Jan 16, 2024
* 添加prettier和git hook

* Fix lint

* Disable KaTeX

* Fix typo

* Add comment to markdownlint config
[skip ci]
[skip netlify]

* 从lint-stage移除markdownlint

* 修复大小写错误

* reorder settings

* 仅在本仓库触发部署,fork仓库跳过
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants