Lint
Lint is a toolkit to write and run linting checks on Nim projects.
Thanks to its modular architecture, Lint allows you to BYOLโbring your own linter:
- you can write a standalone Nim module with your linting checks and ship it as part of your project
- or you can publish it as a Nimble package so that anyone could use in in their projects
Lint ships with an accompanying GitHub action to make it easy to enable linting in your CI process.
Quickstart
- Install lint with nimble:
$ nimble install lint
- Write a linter config (see an example in tests/linter.nim.
import lint import namelinter runLint: #startGlobalConfig sources = ["./src"] ignoredPatterns = ["./src/skip/skipped.nim", "./src/skip2/**/*"] #endGlobalConfig #startStepConfig step "Check naming": ignoredPatterns = ["./src/skip/skipped2.nim"] check varNames: severity = hint settings: minLength = 3 maxLength = 12 check constNames: severity = error settings: prefix = "k" #endStepConfig
Note:
Lint config is a compiled Nim file. This is a bit unorthodox as you usually see configs written in YAML, TOML, or JSON. However, using Nim for configuration allows Lint to employ user-provided linters: the compiled binary has all your checks baked in.
Also, because it's regular Nim, you never get an incorrect config due to a typo and you can enjoy autocompletions while you edit it.
- Compile and run your linter:
$ nim c -d:release linter.nim $ ./linter # lint entire project $ ./linter myfile.nim # or a single file $ ./linter dir # or a directory $ ./linter dir/s*.nim # or a glob pattern
Full docs are at iftech.github.io/nim-lint.
License
Licensed under either of:
- Apache License 2.0 LICENSE-APACHEv2
- MIT license LICENSE-MIT
at your option.