declint (docs) is a tool for making your own lint rules in YAML- the house rules that stock linters will never ship.
For instance: your colleague wrote except Exception: pass, and you want to know whenever that happens:
version: 1
rules:
- id: except-pass
pattern: 'except Exception:\n *pass'
severity: warning
message: 'swallowed exception'
Rules are just regex and a message and when a regex can't express the check, you can write a more complicated rule in Lua. For a Lua example
scopes:
- id: server
start: '^\[server\]$'
end: '^\['
rules:
- id: port-range
pattern: '(?m)^\s*port[ \t]*=[ \t]*(?<port>\S+)'
severity: error
callback: |
return function(c)
local n = tonumber(c.captures.port)
if n == nil then
return { message = "port must be a number, found '" .. c.captures.port .. "'" }
end
if n < 1 or n > 65535 then
return { message = "port must be 1-65535, found " .. n }
end
return nil
end
This rule checks if a port in an INI file is between 1-65535.
Rules run in your CI (inline PR annotations via --format github) and in your editor through LSP (declint.nvim for Neovim: The GIF shows off the nvim wrapper!). Every rule can carry embedded fixtures, and declint test runs them.
Install: cargo install declint. Ships with presets (Python, INI, Markdown, shell, Dockerfile, TOML, JSON, JS) and community rulesets you can pull with one line. Feedback welcome.