Skip to content

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

License

Notifications You must be signed in to change notification settings

dustinsand/pre-commit-jvm

Repository files navigation

pre-commit

pre-commit-jvm

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

Requirements

pre-commit-jvm requires the following to run:

Install

  1. create .pre-commit-config.yaml in your git project
  2. pre-commit install

example .pre-commit-config.yaml:

- repo: https://github.com/dustinsand/pre-commit-jvm
  rev: vX.X.X
  hooks:
    - id: detekt
      args: [--config, detekt-config.yml]
    - id: google-java-formatter-jdk11
      args: [--replace, --set-exit-if-changed]
    - id: ktlint
      args: [--format]
    - id: pmd
      args: [ -rulesets, pmd-ruleset.xml, -language, java, -cache, .pmd/cache, -dir, src/main/java, -f, textcolor ]

Available Hooks

Hook name Description
detekt Runs Detekt static code analyzer on Kotlin source files.
google-java-formatter-jdk8 Runs Google Java Formatter to reformat Java source code to comply with Google Java Style. Minimum supported runtime version is JDK 8.
google-java-formatter-jdk11 Runs Google Java Formatter to reformat Java source code to comply with Google Java Style. Minimum supported runtime version is JDK 11.
ktlint Runs Ktlint to lint and reformat Kotlin source code.
pmd Runs PMD static code analyzer on Java source files.

Notes about the detekt hook

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

    - id: detekt
      args: [--config, detekt-config.yml]

Other CLI arguments are also supported.

Notes about the google-java-formatter-jdk[version] hook

Minimum required arguments for the hook:

    - id: google-java-formatter-jdk[version]
      args: [--replace, --set-exit-if-changed]

Other CLI arguments are also supported.

You can also use Coursier to get the list of options.

[JDK 8]
cs launch com.google.googlejavaformat:google-java-format:1.7 -- --help

[JDK 11+]
cs launch com.google.googlejavaformat:google-java-format:1.9 -- --help

Notes about the ktlint hook

Minimum required arguments for the hook:

    - id: ktlint
      args: [--format]

Other CLI arguments are also supported.

You can also use Coursier to get the list of options.

cs launch com.pinterest:ktlint:0.39.0 -M com.pinterest.ktlint.Main -- --help

Notes about the pmd hook

Required arguments for the hook:

Argument Description
dir Root directory for sources.
rulesets Comma separated list of ruleset names to use.
    - id: pmd
      args: [ -dir, src/main/java, -rulesets, pmd-ruleset.xml ]

Other CLI arguments are also supported.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published