Built-in Linters Reference
hk provides 60+ 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.2.0/hk@1.2.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v1.2.0/hk@1.2.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
JavaScript/TypeScript
prettier
- Files:
*.js
,*.jsx
,*.ts
,*.tsx
,*.css
,*.scss
,*.html
,*.json
,*.yaml
,*.md
, and more - Features: Batch processing, list-different optimization
- Commands:
- Check:
prettier --check {{files}}
- Fix:
prettier --write {{files}}
- Check:
eslint
- Files:
*.js
,*.jsx
,*.ts
,*.tsx
- Features: Batch processing for performance
- Commands:
- Check:
eslint {{files}}
- Fix:
eslint --fix {{files}}
- Check:
tsc
- Files: TypeScript projects
- Features: Type checking only (no emit)
- Command:
tsc --noEmit
tsserver
- Files:
*.ts
,*.tsx
,*.js
,*.jsx
- Features: TypeScript language server diagnostics
- Command:
tsserver --format {{files}}
biome
- Files:
*.js
,*.jsx
,*.ts
,*.tsx
,*.json
- Features: Fast formatter and linter
- Commands:
- Check:
biome check {{files}}
- Fix:
biome check --apply {{files}}
- Check:
deno
- Files:
*.ts
,*.tsx
,*.js
,*.jsx
- Features: Deno formatter and linter
- Commands:
- Check:
deno fmt --check {{files}} && deno lint {{files}}
- Fix:
deno fmt {{files}} && deno lint --fix {{files}}
- Check:
deno_check
- Files:
*.ts
,*.tsx
- Features: Deno type checker
- Command:
deno check {{files}}
standard_js
- Files:
*.js
,*.jsx
- Features: JavaScript Standard Style
- Commands:
- Check:
standard {{files}}
- Fix:
standard --fix {{files}}
- Check:
xo
- Files:
*.js
,*.jsx
,*.ts
,*.tsx
- Features: JavaScript/TypeScript linter with great defaults
- Commands:
- Check:
xo {{files}}
- Fix:
xo --fix {{files}}
- Check:
ox_lint
- Files:
*.js
,*.jsx
,*.ts
,*.tsx
- Features: Oxidation compiler linter
- Commands:
- Check:
oxlint {{files}}
- Fix:
oxlint --fix {{files}}
- Check:
Python
black
- Files:
*.py
,*.pyi
- Features: Opinionated Python formatter
- Commands:
- Check:
black --check {{files}}
- Fix:
black {{files}}
- Check:
ruff
- Files:
*.py
,*.pyi
- Features: Fast Python linter and formatter
- Commands:
- Check:
ruff check {{files}} && ruff format --check {{files}}
- Fix:
ruff check --fix {{files}} && ruff format {{files}}
- Check:
isort
- Files:
*.py
- Features: Python import sorter
- Commands:
- Check:
isort --check-only {{files}}
- Fix:
isort {{files}}
- Check:
flake8
- Files:
*.py
- Features: Python style guide enforcement
- Command:
flake8 {{files}}
pylint
- Files:
*.py
- Features: Python code analysis
- Command:
pylint {{files}}
mypy
- Files:
*.py
- Features: Static type checker for Python
- Command:
mypy {{files}}
Rust
cargo_fmt
- Files:
*.rs
- Features: Rust code formatter
- Commands:
- Check:
cargo fmt -- --check
- Fix:
cargo fmt
- Check:
rustfmt
- Files:
*.rs
- Features: Rust code formatter (alias for cargo_fmt)
- Commands:
- Check:
rustfmt --check {{files}}
- Fix:
rustfmt {{files}}
- Check:
cargo_clippy
- Files: Rust projects
- Features: Rust linter
- Commands:
- Check:
cargo clippy
- Fix:
cargo clippy --fix --allow-dirty --allow-staged
- Check:
cargo_check
- Files: Rust projects
- Features: Fast type checking
- Command:
cargo check
Go
go_fmt
- Files:
*.go
- Features: Go formatter
- Commands:
- Check:
gofmt -l {{files}}
- Fix:
gofmt -w {{files}}
- Check:
go_imports
- Files:
*.go
- Features: Go import management
- Commands:
- Check:
goimports -l {{files}}
- Fix:
goimports -w {{files}}
- Check:
golangci_lint
- Files: Go projects
- Features: Go meta-linter
- Commands:
- Check:
golangci-lint run {{files}}
- Fix:
golangci-lint run --fix {{files}}
- Check:
staticcheck
- Files:
*.go
- Features: Go static analysis
- Command:
staticcheck {{files}}
go_vet
- Files: Go packages
- Features: Go code vetting
- Command:
go vet ./...
gomod_tidy
- Files:
go.mod
- Features: Go module maintenance
- Command:
go mod tidy -diff
(with diff support)
revive
- Files:
*.go
- Features: Fast Go linter
- Command:
revive {{files}}
go_lines
- Files:
*.go
- Features: Long line fixer
- Commands:
- Check:
golines --dry-run {{files}}
- Fix:
golines -w {{files}}
- Check:
go_sec
- Files: Go packages
- Features: Security scanner
- Command:
gosec ./...
go_vuln_check
- Files: Go projects
- Features: Vulnerability scanner
- Command:
govulncheck ./...
err_check
- Files: Go packages
- Features: Error handling checker
- Command:
errcheck ./...
Ruby
rubocop
- Files:
*.rb
,*.rake
,Gemfile
,Rakefile
- Features: Ruby style guide
- Commands:
- Check:
rubocop {{files}}
- Fix:
rubocop -a {{files}}
- Check:
standard_rb
- Files:
*.rb
- Features: Ruby Standard Style
- Commands:
- Check:
standardrb {{files}}
- Fix:
standardrb --fix {{files}}
- Check:
sorbet
- Files: Ruby projects
- Features: Type checker for Ruby
- Command:
srb tc
reek
- Files:
*.rb
- Features: Code smell detector
- Command:
reek {{files}}
erb
- Files:
*.erb
- Features: ERB template linter
- Command:
erb -x -T - {{files}} | ruby -c
fasterer
- Files:
*.rb
- Features: Performance suggestions
- Command:
fasterer {{files}}
brakeman
- Files: Rails projects
- Features: Security scanner
- Command:
brakeman
bundle_audit
- Files:
Gemfile.lock
- Features: Dependency security audit
- Commands:
- Check:
bundle-audit check
- Fix:
bundle-audit update
- Check:
Shell
shellcheck
- Files:
*.sh
,*.bash
- Features: Shell script analyzer
- Command:
shellcheck {{files}}
shfmt
- Files:
*.sh
,*.bash
- Features: Shell formatter
- Commands:
- Check:
shfmt -l {{files}}
- Fix:
shfmt -w {{files}}
- Check:
Infrastructure
terraform
- Files:
*.tf
,*.tfvars
- Features: Terraform formatter
- Commands:
- Check:
terraform fmt -check {{files}}
- Fix:
terraform fmt {{files}}
- Check:
tf_lint
- Files:
*.tf
- Features: Terraform linter
- Command:
tflint {{files}}
hadolint
- Files:
Dockerfile*
- Features: Dockerfile linter
- Command:
hadolint {{files}}
actionlint
- Files:
.github/workflows/*.yml
,.github/workflows/*.yaml
- Features: GitHub Actions workflow linter
- Command:
actionlint {{files}}
Nix
nix_fmt
- Files:
*.nix
- Features: Nix formatter
- Commands:
- Check:
nix fmt -- --check {{files}}
- Fix:
nix fmt {{files}}
- Check:
nixpkgs_format
- Files:
*.nix
- Features: Nixpkgs formatter
- Commands:
- Check:
nixpkgs-fmt --check {{files}}
- Fix:
nixpkgs-fmt {{files}}
- Check:
alejandra
- Files:
*.nix
- Features: Alternative Nix formatter
- Commands:
- Check:
alejandra --check {{files}}
- Fix:
alejandra {{files}}
- Check:
Data Formats
jq
- Files:
*.json
- Features: JSON processor
- Commands:
- Check:
jq empty {{files}}
- Fix:
jq . {{files}} | sponge {{files}}
- Check:
yq
- Files:
*.yaml
,*.yml
- Features: YAML processor
- Commands:
- Check:
yq eval '.' {{files}}
- Fix:
yq eval '.' -i {{files}}
- Check:
yamllint
- Files:
*.yaml
,*.yml
- Features: YAML linter
- Command:
yamllint {{files}}
xmllint
- Files:
*.xml
- Features: XML validator and formatter
- Commands:
- Check:
xmllint --noout {{files}}
- Fix:
xmllint --format {{files}} -o {{files}}
- Check:
taplo
- Files:
*.toml
- Features: TOML formatter
- Commands:
- Check:
taplo fmt --check {{files}}
- Fix:
taplo fmt {{files}}
- Check:
sql_fluff
- Files:
*.sql
- Features: SQL linter and formatter
- Commands:
- Check:
sqlfluff lint {{files}}
- Fix:
sqlfluff fix {{files}}
- Check:
Configuration
pkl
- Files:
*.pkl
- Features: Pkl configuration language
- Command:
pkl eval {{files}}
sort_package_json
- Files:
package.json
- Features: Sort package.json keys
- Commands:
- Check:
sort-package-json --check {{files}}
- Fix:
sort-package-json {{files}}
- Check:
Markdown
markdown_lint
- Files:
*.md
- Features: Markdown linter
- Commands:
- Check:
markdownlint {{files}}
- Fix:
markdownlint --fix {{files}}
- Check:
CSS
stylelint
- Files:
*.css
,*.scss
,*.sass
,*.less
- Features: CSS linter
- Commands:
- Check:
stylelint {{files}}
- Fix:
stylelint --fix {{files}}
- Check:
PHP
php_cs
- Files:
*.php
- Features: PHP coding standards fixer
- Commands:
- Check:
php-cs-fixer fix --dry-run {{files}}
- Fix:
php-cs-fixer fix {{files}}
- Check:
Other Languages
ktlint
- Files:
*.kt
,*.kts
- Features: Kotlin linter and formatter
- Commands:
- Check:
ktlint {{files}}
- Fix:
ktlint -F {{files}}
- Check:
swiftlint
- Files:
*.swift
- Features: Swift style and conventions
- Commands:
- Check:
swiftlint lint {{files}}
- Fix:
swiftlint --fix {{files}}
- Check:
clang_format
- Files:
*.c
,*.cpp
,*.h
,*.hpp
,*.cc
,*.cxx
- Features: C/C++ formatter
- Commands:
- Check:
clang-format --dry-run -Werror {{files}}
- Fix:
clang-format -i {{files}}
- Check:
cpp_lint
- Files:
*.c
,*.cpp
,*.h
,*.hpp
,*.cc
,*.cxx
- Features: C++ style checker
- Command:
cpplint {{files}}
luacheck
- Files:
*.lua
- Features: Lua linter
- Command:
luacheck {{files}}
stylua
- Files:
*.lua
- Features: Lua formatter
- Commands:
- Check:
stylua --check {{files}}
- Fix:
stylua {{files}}
- Check:
astro
- Files:
*.astro
- Features: Astro component formatter
- Commands:
- Check:
astro check {{files}}
- Fix:
astro format {{files}}
- Check:
Special Purpose
newlines
- Files: All text files
- Features: Ensure files end with newline
- Commands:
- Check: Shell script to check newlines
- Fix: Shell script to add newlines
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
}