After correctly setting up clj-kondo
, you might want to leverage its powers during the test / build phase your project.
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.
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 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:
A number of GitHub Actions that use clj-kondo
are available:
- clojure-lint-action
- lint-clojure
- Mega-Linter: 100% open-source linters aggregator
- setup-clj-kondo
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: Setup clj-kondo
uses: DeLaGuardo/setup-clj-kondo@822352b8aa37d5c94135e67f7b4e2f46c08008a8
with:
version: '2020.04.05'
- 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.