Bro*_*ind 4 pipeline pre-commit-hook githooks gitlab-ci linter
我希望google-java-formatter在我的几个项目中进行安装。
但是,在提交代码时,我希望CI管道首先检查格式是否已完成。
我知道我可以使用.gitlab-ci.yml根目录中的文件来完成此操作,但是我非常不确定如何实现检查所有文件格式是否正确的目标,任何人都可以帮助我解决如何执行此操作的google-java-formatter问题gitlab。
google-java-formatter用于代码格式化自从google-java-formatter对代码进行了修改(格式化),因此它会更改要提交的代码。
根据google-java-format源代码:
\n\n\n\n
google-java-format是一个重新格式化 Java 源代码以符合Google Java 风格的程序的程序。
所以,你需要一个pre-commit钩子。
例如,您可以使用预提交- 用于管理和维护多语言预提交挂钩的框架。
\n您可以在此处查看示例文件
\n.pre-commit-hooks.yaml:
\n\n- id: eclipse-formatter\n name: Eclipse Java Formatter\n description: This hook formats Java code with the Eclipse formatter.\n entry: eclipse-formatter\n language: python\n types:\n - java\n- id: google-java-formatter\n name: Google Java Formatter\n description: This hook formats Java code with Google Java Formatter.\n entry: google-java-formatter\n language: python\n types:\n - java\nRun Code Online (Sandbox Code Playgroud)\n如果您确实想将 git hooks 与 集成GitLab,请尝试创建自定义GitLab Server hook
如你所说:
\n\n\n当提交代码时,我希望 CI 管道首先检查格式是否已完成。
\n
你在问什么 -checkstyle linting不是formatting n所以,要检查格式化是否已经完成,你可以使用一些 linter。
即来自这个答案:
\ncheckstyle短绒的使用有很多关于这方面的指南,例如:GitLab CI/CD Pipeline for Maven-Based applications \xe2\x80\x93 Ivan Krizsan 的博客
\n此外,还有250 多个带有 `checkstyle.js 的示例.gitlab-ci.yml。
\n- id: eclipse-formatter\n name: Eclipse Java Formatter\n description: This hook formats Java code with the Eclipse formatter.\n entry: eclipse-formatter\n language: python\n types:\n - java\n- id: google-java-formatter\n name: Google Java Formatter\n description: This hook formats Java code with Google Java Formatter.\n entry: google-java-formatter\n language: python\n types:\n - java\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
18779 次 |
| 最近记录: |