Welcome to Lint!

Search:
Source   Edit  

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

  1. Install lint with nimble:
$ nimble install lint
  1. 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.

  1. 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:

at your option.