Skip to content

Built-in Linters Reference

hk provides 90+ pre-configured linters and formatters through the Builtins module. These are production-ready configurations that work out of the box.

Usage

Import and use builtins in your hk.pkl:

pkl
amends "package://github.com/jdx/hk/releases/download/v1.27.0/hk@1.27.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v1.27.0/hk@1.27.0#/Builtins.pkl"

hooks {
  ["pre-commit"] {
    steps {
      ["prettier"] = Builtins.prettier
      ["eslint"] = Builtins.eslint
    }
  }
}

You can also customize builtins:

pkl
["prettier"] = (Builtins.prettier) {
  batch = false  // Override the default batch setting
  glob = List("*.js", "*.ts")  // Override file patterns
}

Available Builtins

CSS

stylelint

CSS linter

  • Glob: **/*.css, **/*.scss, **/*.sass, **/*.less
  • Check: stylelint {{ files }}
  • Fix: stylelint --fix {{ files }}

Configuration

pkl

Pkl configuration language

  • Glob: **/*.pkl
  • Check: pkl eval {{files}} >/dev/null

pkl-format

Pkl formatter

  • Glob: **/*.pkl
  • Check (list-files): pkl format --diff-name-only {{ files }}
  • Fix: pkl format --write {{ files }} code=$? if [ $code -eq 11 ]; then exit 0 else exit $code fi

sort-package-json

Sort package.json keys

  • Glob: **/package.json
  • Check: sort-package-json --check {{ files }}
  • Fix: sort-package-json {{ files }}

Data Formats

jq

JSON processor

  • Glob: **/*.json
  • Check: jq . {{ files }}
  • Fix: jq -S . {{ files }}

sql-fluff

SQL linter and formatter

  • Glob: **/*.sql
  • Check: sqlfluff lint {{ files }}
  • Fix: sqlfluff fix {{ files }}

taplo

TOML linter

  • Glob: **/*.toml
  • Check: taplo lint {{ files }}

taplo-format

TOML formatter

  • Glob: **/*.toml
  • Check: taplo format --check {{ files }}
  • Fix: taplo format {{ files }}

tombi

TOML linter

  • Glob: **/*.toml
  • Check: tombi lint {{ files }}

tombi-format

TOML formatter

  • Glob: **/*.toml
  • Check (diff): tombi format --check --diff {{ files }}
  • Fix: tombi format {{ files }}

xmllint

XML validator

  • Glob: **/*.xml
  • Check: xmllint --noout {{ files }}

yamlfmt

YAML formatter

  • Glob: **/*.yml, **/*.yaml
  • Check (diff): yamlfmt -lint {{ files }}
  • Fix: yamlfmt {{ files }}

yamllint

YAML linter

  • Glob: **/*.yml, **/*.yaml
  • Check: yamllint {{ files }}

yq

YAML processor

  • Glob: **/*.yaml
  • Check: yq {{ files }}
  • Fix: yq -iP {{ files }}

Elixir

mix-compile

Compile Elixir with Mix

  • Glob: **/*.ex
  • Check: mix compile --warnings-as-errors --strict-errors {{files}}

mix-fmt

Format Elixir with Mix

  • Glob: **/*.ex, **/*.exs
  • Check: mix format --check-formatted {{files}}
  • Fix: mix format {{files}}

mix-test

Test Elixir with Mix

  • Glob: **/*.ex, **/*.exs
  • Check: mix test --warnings-as-errors {{files}}

Go

err-check

Error handling checker

  • Glob: **/*.go
  • Check: errcheck {{ files }}

go-fmt

Go formatter

  • Glob: **/*.go
  • Check (list-files): FILES=$(gofmt -s -l {{files}}) if [ -n "$FILES" ]; then echo "$FILES" exit 1 fi
  • Fix: gofmt -s -w {{files}}

go-fumpt

Strict Go formatter

  • Glob: **/*.go
  • Check: gofumpt -l {{ files }}
  • Fix: gofumpt -w {{ files }}

go-imports

Go import management

  • Glob: **/*.go
  • Check: goimports -l {{ files }}
  • Fix: goimports -w {{ files }}

go-lines

Long line fixer

  • Glob: **/*.go
  • Check: golines --dry-run {{ files }}
  • Fix: golines -w {{ files }}

go-sec

Security scanner

  • Glob: **/*.go
  • Check: gosec {{ files }}

go-vet

Go code vetting

  • Glob: **/*.go
  • Check: go vet {{ files }}

go-vuln-check

Vulnerability scanner

  • Glob: **/*.go
  • Check: govulncheck {{ files }}

golangci-lint

Go meta-linter

  • Glob: **/*.go
  • Check: golangci-lint run --fix=false {{ files }}
  • Fix: golangci-lint run --fix {{ files }}

gomod-tidy

Go module maintenance

  • Glob: **/go.mod
  • Check (diff): go mod tidy -diff
  • Fix: go mod tidy

revive

Fast Go linter

  • Glob: **/*.go
  • Check: revive {{ files }}

staticcheck

Go static analysis

  • Glob: **/*.go
  • Check: staticcheck {{ files }}

Infrastructure

actionlint

GitHub Actions workflow linter

  • Glob: .github/workflows/*.yml, .github/workflows/*.yaml
  • Check: actionlint {{ files }}

hadolint

Dockerfile linter

  • Glob: **/Dockerfile*
  • Check: hadolint {{ files }}

mise

mise-en-place's built-in formatter and linter

  • Glob: mise.toml, mise.*.toml, .mise.toml, .mise.*.toml, mise/config.toml, mise/config.*.toml, .mise/config.toml, .mise/config.*.toml, .config/mise.toml, .config/mise.*.toml, .config/mise/config.toml, .config/mise/config.*.toml, .config/mise/mise.toml, .config/mise/mise.*.toml, .config/mise/conf.d/*.toml
  • Check: mise fmt --check
  • Fix: mise fmt

terraform

Terraform formatter

  • Glob: **/*.tf, **/*.tfvars, **/*.tftest.hcl
  • Check (list-files): terraform fmt -check {{ files }}
  • Fix: terraform fmt {{ files }}

tf-lint

Terraform linter

  • Glob: **/*.tf
  • Check: tflint
  • Fix: tflint --fix

tofu

OpenTofu formatter

  • Glob: **/*.tf, **/*.tfvars, **/*.tftest.hcl
  • Check (list-files): tofu fmt -check {{ files }}
  • Fix: tofu fmt {{ files }}

JavaScript/TypeScript

biome

Fast formatter and linter

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx, **/*.json
  • Check: biome check {{ files }}
  • Fix: biome check --write {{ files }}

deno

Deno formatter

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: deno fmt --check {{ files }}
  • Fix: deno fmt {{ files }}

deno-check

Deno type checker

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: deno check {{ files }}

eslint

Pluggable JavaScript linter

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: eslint {{ files }}
  • Fix: eslint --fix {{ files }}

ox-lint

Oxidation compiler linter

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: oxlint {{ files }}
  • Fix: oxlint --fix {{ files }}

prettier

Opinionated code formatter

  • Glob: **/*.js, **/*.jsx, **/*.mjs, **/*.cjs, **/*.ts, **/*.tsx, **/*.mts, **/*.cts, **/*.css, **/*.scss, **/*.less, **/*.html, **/*.json, **/*.json5, **/*.jsonc, **/*.yaml, **/*.yml, **/*.markdown, **/*.markdown.mdx, **/*.md, **/*.graphql, **/*.handlebars, **/*.svelte, **/*.astro, **/*.htmlangular, **/*.vue
  • Check: prettier --check {{ files }}
  • Fix: prettier --write {{ files }}

standard-js

JavaScript Standard Style

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: standard {{ files }}
  • Fix: standard --fix {{ files }}

tsc

TypeScript type checker

  • Glob: **/*.ts, **/*.tsx
  • Check: tsc --noEmit -p {{workspace_indicator}}

tsserver

TypeScript language server diagnostics

  • Glob: **/*.ts, **/*.tsx
  • Check: tsc-files --noEmit {{ files }}

xo

JavaScript/TypeScript linter with great defaults

  • Glob: **/*.js, **/*.jsx, **/*.ts, **/*.tsx
  • Check: xo {{ files }}
  • Fix: xo --fix {{ files }}

Markdown

markdown-lint

Markdown linter

  • Glob: **/*.md, **/*.markdown
  • Check: markdownlint {{ files }}
  • Fix: markdownlint --fix {{ files }}

Nix

alejandra

Alternative Nix formatter

  • Glob: **/*.nix
  • Check: alejandra --check {{ files }}
  • Fix: alejandra {{ files }}

nix-fmt

Nix formatter

  • Glob: **/*.nix
  • Check: nixfmt --check {{ files }}
  • Fix: nixfmt {{ files }}

nixpkgs-format

Nixpkgs formatter

  • Glob: **/*.nix
  • Check: nixpkgs-fmt --check {{ files }}
  • Fix: nixpkgs-fmt {{ files }}

Other Languages

astro

Astro component checker

  • Glob: **/*.astro
  • Check: astro check {{ files }}

clang-format

C/C++ formatter

  • Glob: **/*.c, **/*.h, **/*.cpp, **/*.hpp, **/*.cc, **/*.hh, **/*.cxx, **/*.hxx
  • Check: clang-format --dry-run -Werror {{ files }}
  • Fix: clang-format -i {{ files }}

cpp-lint

C++ style checker

  • Glob: **/*.c, **/*.h, **/*.cpp, **/*.hpp, **/*.cc, **/*.hh, **/*.cxx, **/*.hxx
  • Check: cpplint {{ files }}

dprint

Pluggable code formatter

  • Glob: **/*
  • Check: dprint check --allow-no-files {{ files }}
  • Fix: dprint fmt --allow-no-files {{ files }}

ktlint

Kotlin linter and formatter

  • Glob: **/*.kt
  • Check: ktlint {{ files }}
  • Fix: ktlint -F {{ files }}

luacheck

Lua linter

  • Glob: **/*.lua
  • Check: luacheck {{ files }}

stylua

Lua formatter

  • Glob: **/*.lua
  • Check: stylua --check {{ files }}
  • Fix: stylua {{ files }}

swiftlint

Swift style and conventions

  • Glob: **/*.swift
  • Check: swiftlint lint {{ files }}
  • Fix: swiftlint --fix {{ files }}

vacuum

Fast OpenAPI linter

  • Glob: **/*openapi*.yaml, **/*openapi*.yml, **/*openapi*.json, **/*swagger*.yaml, **/*swagger*.yml, **/*swagger*.json
  • Check: vacuum lint {{files}}
  • Fix: vacuum lint --fix {{files}}

PHP

php-cs

PHP coding standards

  • Glob: **/*.php
  • Check: phpcs {{ files }}
  • Fix: phpcbf {{ files }}

Python

black

Opinionated Python formatter

  • Glob: **/*.py
  • Check: black --check {{ files }}
  • Fix: black {{ files }}

flake8

Python style guide enforcement

  • Glob: **/*.py
  • Check: flake8 {{ files }}

isort

Python import sorter

  • Glob: **/*.py
  • Check: isort --check-only {{ files }}
  • Fix: isort {{ files }}

mypy

Static type checker for Python

  • Glob: **/*.py, **/*.pyi
  • Check: mypy {{ files }}

pylint

Python code analysis

  • Glob: **/*.py
  • Check: pylint {{ files }}

python-check-ast

Validate Python syntax by parsing the AST

  • Glob: **/*.py
  • Check: hk util python-check-ast {{files}}

python-debug-statements

Detect debug statements in Python code

  • Glob: **/*.py
  • Check: hk util python-debug-statements {{files}}

ruff

Fast Python linter

  • Glob: **/*.py, **/*.pyi
  • Check: ruff check --force-exclude {{ files }}
  • Fix: ruff check --force-exclude --fix {{ files }}

ruff-format

Fast Python formatter (part of ruff)

  • Glob: **/*.py, **/*.pyi
  • Check: ruff format --force-exclude --check {{ files }}
  • Fix: ruff format --force-exclude {{ files }}

Ruby

brakeman

Security scanner for Rails

  • Glob: **/*.rb
  • Check: brakeman -q -w2 {{ files }}

bundle-audit

Dependency security audit

  • Glob: **/Gemfile.lock
  • Check: bundle-audit check {{ files }}
  • Fix: bundle-audit update

erb

ERB template linter

  • Glob: **/*.erb
  • Check: erb -P -x -T - {{ files }} | ruby -c

fasterer

Performance suggestions

  • Glob: **/*.rb
  • Check: fasterer {{ files }}

reek

Code smell detector

  • Glob: **/*.rb
  • Check: reek {{ files }}

rubocop

Ruby style guide

  • Glob: **/*.rb
  • Check: rubocop {{ files }}
  • Fix: rubocop --fix {{ files }}

sorbet

Type checker for Ruby

  • Glob: **/*.rb
  • Check: srb tc {{ files }}

standard-rb

Ruby Standard Style

  • Glob: **/*.rb
  • Check: standardrb {{ files }}
  • Fix: standardrb --fix {{ files }}

Rust

cargo-check

Fast Rust type checking

  • Glob: **/*.rs
  • Check: cargo check -q

cargo-clippy

Rust linter

  • Glob: **/*.rs
  • Check: cargo clippy --manifest-path {{workspace_indicator}} --quiet
  • Fix: cargo clippy --manifest-path {{workspace_indicator}} --fix --allow-dirty --allow-staged --quiet

cargo-fmt

Rust code formatter

  • Glob: **/*.rs
  • Check: cargo fmt --check --manifest-path {{workspace_indicator}}
  • Fix: cargo fmt --manifest-path {{workspace_indicator}}

rustfmt

Rust code formatter (standalone)

  • Glob: **/*.rs
  • Check: rustfmt --check --edition 2024 {{ files }}
  • Fix: rustfmt --edition 2024 {{ files }}

Shell

shellcheck

Shell script analyzer

  • Glob: **/*.sh, **/*.bash
  • Check: shellcheck {{ files }}

shfmt

Shell formatter

  • Glob: **/*.sh, **/*.bash, **/*.mksh, **/*.bats, **/*.zsh
  • Check (diff): shfmt -d {{ files }}
  • Fix: shfmt -w {{ files }}

Special Purpose

check-added-large-files

Prevent committing large files

  • Glob: **/*
  • Check: hk util check-added-large-files {{files}}

check-byte-order-marker

Detect UTF-8 BOM

  • Glob: **/*
  • Check: hk util check-byte-order-marker {{files}}

check-case-conflict

Detect case-insensitive filename conflicts

  • Glob: **/*
  • Check: hk util check-case-conflict {{files}}

check-conventional-commit

Verify commit message matches conventional commits formatting

  • Check: hk util check-conventional-commit {{commit_msg_file}}

check-executables-have-shebangs

Verify executable files have shebang lines

  • Glob: **/*
  • Check: hk util check-executables-have-shebangs {{files}}

check-merge-conflict

Detect merge conflict markers

  • Glob: **/*
  • Check: hk util check-merge-conflict --assume-in-merge {{files}}

Detect broken symlinks

  • Glob: **/*
  • Check: hk util check-symlinks {{files}}

detect-private-key

Detect accidentally committed private keys

  • Glob: **/*
  • Check: hk util detect-private-key {{files}}

fix-byte-order-marker

Remove UTF-8 BOM

  • Glob: **/*
  • Fix: hk util fix-byte-order-marker {{files}}

fix-smart-quotes

Replace smart quotes with regular quotes

  • Glob: **/*
  • Fix: hk util fix-smart-quotes {{files}}

lychee

Fast, async, stream-based link checker

  • Check: lychee --no-progress {{ files }}

mixed-line-ending

Detect and fix mixed line endings

  • Glob: **/*
  • Check: hk util mixed-line-ending {{files}}
  • Fix: hk util mixed-line-ending --fix {{files}}

newlines

Ensure files end with newline

  • Glob: **/*
  • Check (list-files): hk util end-of-file-fixer {{files}}
  • Fix: hk util end-of-file-fixer --fix {{files}}

no-commit-to-branch

Prevent direct commits to protected branches

  • Check: hk util no-commit-to-branch

trailing-whitespace

Detect and remove trailing whitespace

  • Glob: **/*
  • Check (list-files): hk util trailing-whitespace {{files}}
  • Fix: hk util trailing-whitespace --fix {{files}}

typos

Source code spell checker

  • Glob: **/*
  • Check (diff): output=$(typos --diff {{files}}) [ -z "$output" ] && exit 0 printf "%s" "$output" exit 1
  • Fix: typos --write-changes {{ files }}

Customizing Builtins

Override Properties

pkl
["prettier"] = (Builtins.prettier) {
  // Override glob patterns
  glob = List("src/**/*.js", "src/**/*.ts")

  // Disable batch processing
  batch = false

  // Add environment variables
  env {
    ["PRETTIER_CONFIG"] = ".prettierrc.json"
  }
}

Add Dependencies

pkl
["eslint"] = (Builtins.eslint) {
  // Run after prettier
  depends = "prettier"
}

Workspace-Specific Configuration

pkl
["cargo_clippy"] = (Builtins.cargo_clippy) {
  // Only run in directories with Cargo.toml
  workspace_indicator = "Cargo.toml"

  // Custom command using workspace
  check = "cargo clippy --manifest-path {{workspace}}/Cargo.toml"
}

Profile-Based Configuration

pkl
["mypy"] = (Builtins.mypy) {
  // Only run with "python" profile
  profiles = List("python")
}

Creating Custom Steps

If a builtin doesn't exist for your tool:

pkl
["custom-tool"] {
  glob = List("*.custom")
  check = "custom-tool --check {{files}}"
  fix = "custom-tool --fix {{files}}"
  batch = true  // Enable parallel processing
}

See Also

Licensed under the MIT License. Maintained by @jdx and friends.