【发布时间】:2022-01-21 05:47:25
【问题描述】:
如何使用mix credo、mix format 等将一个 lint 文件分阶段提交,而不是项目中的所有文件?
在 JavaScript 生态系统中,这是通过 lint-staged 和 husky 完成的。 Elixir 有其名为 git_hooks 的 husky 包版本,但我没有发现任何类似于 lint-staged 的东西。
是否存在一个 elixir 包来实现我在提交 elixir 文件时仅运行 lint 命令的目标?
我在 config/dev.ex 中使用 git_hook 运行的示例配置。
config :git_hooks,
auto_install: true,
verbose: true,
mix_path: "docker exec --tty $(docker-compose ps -q web) mix",
hooks: [
pre_commit: [
tasks: [
{:mix_task, :format, ["--check-formatted"]},
{:mix_task, :credo, ["--strict"]}
]
]
]
【问题讨论】:
-
嗨!我不知道是否有这个包,但你可以使用
git diff --name-only | xargs mix credo来完成它(因为 credo 接受文件列表作为参数)。mix format也可以这样做。希望对您有所帮助! -
@sabiwara
diff --name-only --cached | xargs mix credo需要缺少的 --cached 参数。我会尝试使用它。
标签: elixir githooks phoenix lint-staged