Back to Detekt

Run detekt using Command Line Interface

website/versioned_docs/version-2.0.0-alpha.1/gettingstarted/cli.mdx

1.23.81.7 KB
Original Source

import CliOptions from "./_cli-options.md"; import CliGeneratorOptions from "./_cli-generator-options.md";

Install the cli

There are different ways to install the Command Line Interface (CLI):

MacOS, with Homebrew:

sh
brew install detekt
detekt [options]

Windows, with Scoop:

powershell
scoop install detekt
detekt [options]

Unix-like OS, with SDKMAN!:

sh
sdk install detekt

Any OS:

sh
curl -sSLO https://github.com/detekt/detekt/releases/download/v[detekt_version]/detekt-cli-[detekt_version].zip
unzip detekt-cli-[detekt_version].zip
./detekt-cli-[detekt_version]/bin/detekt-cli --help

NixOS:

As a prerequisite, you have to add the unstable channel via nix-channel and then execute the following command.

sh
nix-shell -I nixpkgs=channel:nixpkgs-unstable -p detekt

Use the cli

detekt will exit with one of the following exit codes:

Exit codeDescription
0detekt ran normally and no issues1 were found.
1An unexpected error occurred.
2At least one issue1 was found.
3Invalid detekt configuration file detected.

The following parameters are shown when --help is entered.

<CliOptions />

Use the cli to generate configuration for custom rules

<CliGeneratorOptions />
sh
java -jar detekt-generator-[detekt_version]-all.jar -gcrc -i /path/to/rule1, /path/to/rule2

Footnotes

  1. All found issues that have a severity of or above the --fail-on-severity argument are considered. 2