Liking cljdoc? Tell your friends :D

CI integration

After correctly setting up clj-kondo, you might want to leverage its powers during the test / build phase your project.

Using CI-specific configuration

Since clj-kondo merges configuration files and gives precedence to config files provided explicitly, a useful thing to do when integrating it with your CI workflow is to specify a custom configuration file, such as .clj-kondo/ci-config.edn with CI-specific overrides.

Then put in your pipeline the execution of the tool as

clj-kondo --lint src --config .clj-kondo/ci-config.edn

In this way, you can keep your configuration in the standard config.edn file and that will continue to work during development, with the overrides only be used during CI.

Pre-commit hook

You can use this pre-commit hook to run clj-kondo over files you changed before committing them. Save it into .git/hooks/pre-commit.

#!/bin/sh

# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=$(git hash-object -t tree /dev/null)
fi

if !(git diff --cached --name-only --diff-filter=AM $against | grep -E '.clj[cs]?$' | xargs -r clj-kondo --lint)
then
    echo
    echo "Error: new clj-kondo errors found. Please fix them and retry the commit."
    exit 1
fi

exec git diff-index --check --cached $against --

Also check out these resources:

pre-commit framework

clj-kondo is supported by the pre-commit framework for managing git commit hooks. To enable, add to your .pre-commit-config.yaml:

- repo: https://github.com/clj-kondo/clj-kondo
    rev: v2022.04.25
    hooks:
      - id: clj-kondo

To run the clj-kondo hook via Docker add the following instead:

- repo: https://github.com/clj-kondo/clj-kondo
    rev: v2022.04.25
    hooks:
      - id: clj-kondo-docker

Check out pre-commit for additional resources.

GitHub

A number of GitHub Actions that use clj-kondo are available:

Linter Output Integration

Github Actions can integrate with clj-kondo output using a custom output pattern. To enable this, set clj-kondo's config to:

{:output {:pattern "::{{level}} file={{filename}},line={{row}},col={{col}}::{{message}}"}}

Example configuration with action setup-clj-kondo:

on: push
name: Push / PR Builder
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - name: Install clj-kondo
      uses: DeLaGuardo/setup-clj-kondo@afc83dbbf4e7e32e04649e29dbf30668d30e9e3e
      with:
        version: '2022.01.15'

    - uses: actions/checkout@v2

    - name: Lint
      run: clj-kondo --lint src --config '{:output {:pattern "::{{level}} file={{filename}},line={{row}},col={{col}}::{{message}}"}}'

For more information on Github Action Commands, see Workflow Commands for Github Actions.

Also see this blog article by Raymond Huang.

Other resources

Can you improve this documentation? These fine people already did:
Davide Taviani, Michiel Borkent, Nicolas Vuillamy, Martin Kavalar, allie-jo, Joel Hess, Daniel Compton & Raymond Huang
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close