Skip to content

Repository files navigation

pre-commit-java

pre-commitupdate

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-javarev: v0.2.1 # Use the ref you want to point athooks:
- id: pmdexclude: /test/
- id: cpdexclude: /test/
- id: checkstyleexclude: /test/# ...

Available Hooks

Hook nameDescription
pmdRuns the PMD static code analyzer.
cpdRuns the Copy/Paste Detector (CPD).
checkstyleRuns the Checkstyle static code analysis tool.

Notes about the pmd hook

The default ruleset used is ruleset.xml, which runs all the Java rules, except for LoosePackageCoupling.

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

 - id: pmdargs: ["-R=my_ruleset.xml"]

Furthermore, the default language version passed to PMD is java-17, which can be tweaked using the --use-version argument.

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

The arguments must be specified using the --<arg>=<value> (-<arg>=<value>) convention, as opposed to --<arg> <value (-<arg> <value) to avoid parsing errors.

Notes about the cpd hook

The default minimum token length is 100.

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

 - id: cpdargs: ["--minimum-tokens=50"]

Other CLI arguments are also supported.

The arguments must be specified using the --<arg>=<value> (-<arg>=<value>) convention, as opposed to --<arg> <value (-<arg> <value) to avoid parsing errors.

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: checkstyleargs: ["-c", "my_checks.xml"]

Other CLI arguments are also supported.

Other configurations part of the distribution can be used like:

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

Author

GitHub @gherynos

License

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages