提交前自动检查和格式化代码

discourse 仓库包含了 lefthook 的配置。这将在任何代码提交到 git 之前自动检查代码,并提醒任何问题。要进行设置,只需进入您的 discourse 开发目录并运行

pnpm install
pnpm run lefthook install

文件现在将在提交前自动检查。如果存在任何问题,提交将被取消,并且会向您显示错误列表。


本文档是版本控制的 - 请在 github 上建议更改。

11 个赞

这在工作时非常酷。

目前在WSL2的当前主版本中出现此错误的某个版本。

它破坏了我提交的能力:

robert@blah:~/discourse$ git commit -m "fix test setup"
/home/robert/discourse/node_modules/lefthook-linux-x64/bin/lefthook: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /home/robert/discourse/node_modules/lefthook-linux-x64/bin/lefthook)
/home/robert/discourse/node_modules/lefthook-linux-x64/bin/lefthook: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/robert/discourse/node_modules/lefthook-linux-x64/bin/lefthook)

有什么想法吗?

看起来dependabot在8小时前更新了lefthook。

可能需要将我的package.json回滚一个版本?

好的,我通过将 lefthook 移回 1.6.9 (!) 并执行 yarn 来使其再次正常工作

如果您有更好的方法,将不胜感激,因为我现在与核心不同步了!

看起来像是 Version 1.7.6 fails installation on CI · Issue #783 · evilmartians/lefthook · GitHub

在他们弄清楚之前,我们先回滚更新吧。

1 个赞

大卫,我正在进行本地升级到 Jammy (Dodger)… 我会看看这是否有帮助。

1 个赞

这是关键……我之前安装的 Ubuntu 版本上的最新版本是 GLIBC_2.31。

更新 libc6 包后,版本达到了这个,所以似乎需要进行一次重大的版本升级。

我的 16 核处理完后会很快恢复。

1 个赞

根据他们的 GitHub issue,对共享库的依赖并非有意为之。即使你能让它正常工作,其他人很可能会遇到问题。所以,我们开始了:

Revert "Build(deps-dev): Bump lefthook from 1.7.5 to 1.7.7 (#28068)" … · discourse/discourse@1b7a583 · GitHub :fire:

1 个赞

好的,这解决了问题(使用 1.7.7!):

robert@blah:~/discourse$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

@JammyDodger

:rocket:

robert@blah:~/discourse$ yarn list --pattern lefthook
yarn list v1.22.19
warning Resolution field "unset-value@2.0.1" is incompatible with requested version "unset-value@^1.0.0"
├─ lefthook-darwin-arm64@1.7.7
├─ lefthook-darwin-x64@1.7.7
├─ lefthook-freebsd-arm64@1.7.7
├─ lefthook-freebsd-x64@1.7.7
├─ lefthook-linux-arm64@1.7.7
├─ lefthook-linux-x64@1.7.7
├─ lefthook-windows-arm64@1.7.7
├─ lefthook-windows-x64@1.7.7
└─ lefthook@1.7.7
Done in 0.53s
robert@blah:~/discourse$ git status
On branch test_branch
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   mytestfile

robert@blah:~/discourse$ git commit -m "test file addition"
│  ember-template-lint (skip) no files for inspection
│  yaml-syntax (skip) no files for inspection
│  i18n-lint (skip) no files for inspection
│  rubocop (skip) no files for inspection
│  eslint (skip) no files for inspection
│  prettier (skip) no files for inspection
│  prettier-scss (skip) no files for inspection
│  syntax_tree (skip) no files for inspection

  ────────────────────────────────────
summary: (done in 0.06 seconds)
[test_branch 1cd0bb3839] test file addition
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 mytestfile
2 个赞