Skip to content

A collection of git hooks for Java to be used with the pre-commit framework.

License

Notifications You must be signed in to change notification settings

benediktsatalia/pre-commit-java

 
 

Repository files navigation

pre-commit-java

pre-commit update

A collection of git hooks for Java to be used with the pre-commit framework.

Requirements

pre-commit-java requires the following to run:

Install

  1. create .pre-commit-config.yaml in you git project
  2. pre-commit install
  3. enjoy :)

example .pre-commit-config.yaml:

- repo: https://github.com/gherynos/pre-commit-java
  rev: v0.2.1  # Use the ref you want to point at
  hooks:
    - id: pmd
      exclude: /test/
    - id: cpd
      exclude: /test/
    - id: checkstyle
      exclude: /test/
    # ...

Available Hooks

Hook name Description
pmd Runs the PMD static code analyzer.
cpd Runs the Copy/Paste Detector (CPD).
checkstyle Runs the Checkstyle static code analysis tool.

Notes about the pmd hook

The default ruleset used is ruleset.xml, which runs all the Java rules with the exception of LoosePackageCoupling.

To specify a custom ruleset, simply pass the argument to the hook:

    - id: pmd
      args: ["-R", "my_ruleset.xml"]

Other CLI arguments are also supported, like -cache for incremental analysis.

Notes about the cpd hook

The default minimum token length is 100.

To change it, simply pass the argument to the hook:

    - id: cpd
      args: ["--minimum-tokens", "50"]

Other CLI arguments are also supported.

Notes about the checkstyle hook

The default configuration used is sun_checks.xml.

To specify a custom one, simply pass the argument to the hook:

    - id: checkstyle
      args: ["-c", "my_checks.xml"]

Other CLI arguments are also supported.

Other configurations part of the distribution can be used like:

    - id: checkstyle
      args: ["-c", "/google_checks.xml"]

Author

GitHub @gherynos

License

pre-commit-java is licensed under the GPLv3 license.

About

A collection of git hooks for Java to be used with the pre-commit framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 93.4%
  • Dockerfile 6.6%