├── .gitignore ├── .pre-commit-channel ├── detekt.json ├── google-java-format-jdk11.json ├── google-java-format-jdk8.json ├── ktlint.json └── pmd.json ├── .pre-commit-config.yaml ├── .pre-commit-hooks.yaml ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | -------------------------------------------------------------------------------- /.pre-commit-channel/detekt.json: -------------------------------------------------------------------------------- 1 | { 2 | "mainClass" : "io.gitlab.arturbosch.detekt.cli.Main", 3 | "repositories": [ 4 | "central" 5 | ], 6 | "dependencies": [ 7 | "io.gitlab.arturbosch.detekt:detekt-cli:1.23.1" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.pre-commit-channel/google-java-format-jdk11.json: -------------------------------------------------------------------------------- 1 | { 2 | "repositories": [ 3 | "central" 4 | ], 5 | "dependencies": [ 6 | "com.google.googlejavaformat:google-java-format:1.17.0" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.pre-commit-channel/google-java-format-jdk8.json: -------------------------------------------------------------------------------- 1 | { 2 | "repositories": [ 3 | "central" 4 | ], 5 | "dependencies": [ 6 | "com.google.googlejavaformat:google-java-format:1.7" 7 | ] 8 | } -------------------------------------------------------------------------------- /.pre-commit-channel/ktlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "mainClass": "com.pinterest.ktlint.Main", 3 | "launcherType": "assembly", 4 | "repositories": [ 5 | "central" 6 | ], 7 | "dependencies": [ 8 | "com.pinterest:ktlint:0.50.0" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.pre-commit-channel/pmd.json: -------------------------------------------------------------------------------- 1 | { 2 | "mainClass": "net.sourceforge.pmd.PMD", 3 | "repositories": [ 4 | "central" 5 | ], 6 | "dependencies": [ 7 | "net.sourceforge.pmd:pmd-java:6.55.0" 8 | ] 9 | } -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | repos: 3 | - repo: git://github.com/pre-commit/pre-commit-hooks 4 | rev: v3.3.0 5 | hooks: 6 | - id: check-yaml 7 | - id: end-of-file-fixer 8 | - id: trailing-whitespace 9 | - id: check-case-conflict 10 | - id: check-merge-conflict 11 | - repo: https://github.com/pryorda/dockerfilelint-precommit-hooks 12 | rev: v0.1.0 13 | hooks: 14 | - id: dockerfilelint 15 | -------------------------------------------------------------------------------- /.pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - id: detekt 3 | name: Detekt 4 | description: "Runs the Detekt static code analyzer on Kotlin source files." 5 | language: coursier 6 | entry: detekt 7 | pass_filenames: false 8 | files: \.kt$ 9 | require_serial: true 10 | - id: google-java-formatter-jdk8 11 | name: Google Java Formatter 12 | description: "Runs the Google Java Formatter on Java source files. Minimum supported runtime version is JDK 8." 13 | language: coursier 14 | entry: google-java-format-jdk8 15 | files: \.java$ 16 | require_serial: true 17 | - id: google-java-formatter-jdk11 18 | name: Google Java Formatter 19 | description: "Runs the Google Java Formatter on Java source files. Minimum supported runtime version is JDK 11." 20 | language: coursier 21 | entry: google-java-format-jdk11 -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 22 | files: \.java$ 23 | require_serial: true 24 | - id: ktlint 25 | name: ktlint 26 | description: "Runs the ktlint linter and formatter on Kotlin source files." 27 | language: coursier 28 | entry: ktlint -J--add-opens=java.base/java.lang=ALL-UNNAMED 29 | files: \.kt$ 30 | require_serial: true 31 | - id: pmd 32 | name: PMD 33 | description: "Runs the PMD static code analyzer on Java source files." 34 | language: coursier 35 | entry: pmd 36 | pass_filenames: false 37 | files: \.java$ 38 | require_serial: true 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2020 Dustin Shimono 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/dustinsand/pre-commit-jvm) 2 | 3 | pre-commit-jvm 4 | =============== 5 | 6 | A collection of git hooks for the JVM to be used with the [pre-commit framework](http://pre-commit.com). 7 | 8 | ## Requirements 9 | 10 | pre-commit-jvm requires the following to run: 11 | 12 | * [pre-commit(2.8+)](http://pre-commit.com) 13 | * [Coursier](https://get-coursier.io/) 14 | 15 | ## Install 16 | 17 | 1. create `.pre-commit-config.yaml` in your git project 18 | 2. pre-commit install 19 | 20 | example `.pre-commit-config.yaml`: 21 | 22 | ```yaml 23 | - repo: https://github.com/dustinsand/pre-commit-jvm 24 | rev: vX.X.X 25 | hooks: 26 | - id: detekt 27 | args: [--config, detekt-config.yml] 28 | - id: google-java-formatter-jdk11 29 | args: [--replace, --set-exit-if-changed] 30 | - id: ktlint 31 | args: [--format] 32 | - id: pmd 33 | args: [ -rulesets, pmd-ruleset.xml, -language, java, -cache, .pmd/cache, -dir, src/main/java, -f, textcolor ] 34 | ``` 35 | 36 | ## Available Hooks 37 | 38 | | Hook name | Description | 39 | | --------------- | -------------------------------------------------------------------------------------------------- | 40 | | `detekt` | Runs [Detekt](https://detekt.github.io/detekt/) static code analyzer on Kotlin source files. | 41 | | `google-java-formatter-jdk8` | Runs [Google Java Formatter](https://github.com/google/google-java-format) to reformat Java source code to comply with [Google Java Style](https://google.github.io/styleguide/javaguide.html). Minimum supported runtime version is JDK 8. | 42 | | `google-java-formatter-jdk11` | Runs [Google Java Formatter](https://github.com/google/google-java-format) to reformat Java source code to comply with [Google Java Style](https://google.github.io/styleguide/javaguide.html). Minimum supported runtime version is JDK 11. | 43 | | `ktlint` | Runs [Ktlint](https://ktlint.github.io/) to lint and reformat Kotlin source code. | 44 | | `pmd` | Runs [PMD](https://pmd.github.io/) static code analyzer on Java source files. | 45 | 46 | ### Notes about the `detekt` hook 47 | 48 | To specify a custom detekt configuration, simply pass the argument to the hook: 49 | 50 | ```yaml 51 | - id: detekt 52 | args: [--config, detekt-config.yml] 53 | ``` 54 | 55 | Other [CLI](https://arturbosch.github.io/detekt/cli.html) arguments are also supported. 56 | 57 | ### Notes about the `google-java-formatter-jdk[version]` hook 58 | 59 | Minimum required arguments for the hook: 60 | 61 | ```yaml 62 | - id: google-java-formatter-jdk[version] 63 | args: [--replace, --set-exit-if-changed] 64 | ``` 65 | 66 | Other [CLI](https://github.com/google/google-java-format) arguments are also supported. 67 | 68 | You can also use Coursier to get the list of options. 69 | ``` 70 | [JDK 8] 71 | cs launch com.google.googlejavaformat:google-java-format:1.7 -- --help 72 | 73 | [JDK 11+] 74 | cs launch com.google.googlejavaformat:google-java-format:1.9 -- --help 75 | ``` 76 | 77 | ### Notes about the `ktlint` hook 78 | 79 | Minimum required arguments for the hook: 80 | 81 | ```yaml 82 | - id: ktlint 83 | args: [--format] 84 | ``` 85 | 86 | Other [CLI](https://ktlint.github.io/#getting-started) arguments are also supported. 87 | 88 | You can also use Coursier to get the list of options. 89 | ``` 90 | cs launch com.pinterest:ktlint:0.39.0 -M com.pinterest.ktlint.Main -- --help 91 | ``` 92 | 93 | ### Notes about the `pmd` hook 94 | 95 | Required arguments for the hook: 96 | 97 | | Argument | Description | 98 | | -------- | -------------------------------------------- | 99 | | dir | Root directory for sources. | 100 | | rulesets | Comma separated list of ruleset names to use.| 101 | 102 | ```yaml 103 | - id: pmd 104 | args: [ -dir, src/main/java, -rulesets, pmd-ruleset.xml ] 105 | ``` 106 | 107 | Other [CLI](https://pmd.github.io/latest/pmd_userdocs_installation.html) arguments are also supported. 108 | --------------------------------------------------------------------------------