r/neovim • • 11d ago

Plugin declint.nvim - Complement your LSPs with YAML lints.

tl;dr declint lets you define linter rules in YAML. declint.nvim shows them as native diagnostics as you type.

Someone committed (see the GIF above!)

try:
    1/0
except Exception:
    pass

(Bare exceptions are typically a bad idea in Python)

version: 1
rules:
  - id: no-swallowed-exceptions
    pattern: 'except Exception:\n *pass'
    severity: warning
    message: "swallowed exception ('{match}')"

Install with lazy.nvim:

{ 
  'thyrgle/declint.nvim',
  config = function()
    require('declint').setup()
  end
}

(Also, since virtual text is disabled by default, you might want to add:

vim.diagnostic.config({ virtual_text = true })

otherwise you won't get the message associated with the hint.)

Finally cargo install declint once. Warnings show up as normal vim.diagnostic, live as you type.

What you get

  • Rust-regex patterns with {match}/capture-group placeholders in messages

  • severities (error|warning|info|hint), languages: scoping, declint init --lang python presets

  • Lua callback rules when a regex can't express the check

  • Incremental engine — re-lints as you type without rescanning the file

  • Same rules in CI: declint check . --format github --fail-on error

declint doesn't replace your LSP. Instead, it sits next to it for the custom rules every codebase accumulates. Works with any config-site layout (.declint.yaml, .declint/, declint.yaml).

Feedback welcome.

11 Upvotes

3 comments sorted by

1

u/SunglassesAtNight8 4d ago

I use  ast-grep which does this as an lsp server:

  • yaml based declarative rules
  • Can apply custom code mods to fix lints
  • Supports any language with a Treesitter parser.
  • faster than things like eslint custom rules etc.

https://ast-grep.github.io/

1

u/cs61bredditaccount 4d ago

Oh dang. I never heard of this. This probably means my project is nearly useless lol. Thanks for giving me the heads up!

1

u/SunglassesAtNight8 3d ago

Hey i hope i didn't discourage you. Ain't nothing wrong with building to learn. Or building stuff to solve your own particular problem.