This is a simple wrapper for the Python linter ruff that allows it to be easily used with (neo)vim's quickfix.
Why? I like Vim's quickfix and find it more useful in some situations over using an LSP. Also this is an excuse to learn publishing.
pipx(recommended)
Note: Normal pip works as well, though you should give pipx a try!
- PyPi:
pipx install ruff-quickfix - GitHub:
pipx install git+https://github.com/Nealium/ruff-quickfix - If you don't already have ruff you include it as an "extra"
pipx install ruff-quickfix[ruff]- if zsh:
pipx install ruff-quickfix\[ruff\]
Clone project: git clone https://github.com/Nealium/ruff-quickfix.git
- Pipx:
pipx install . - Pip:
pip install . - Poetry:
poetry install - From Wheel:
poetry installpoetry buildpipx install dist/*.whl
Home Manager(nix)
Note! This will crash on the first run as the sha256 isn't real. Once it crashes the error message will provide the actual sha256 that is required.
- Insert items into
home.nix - Replace
revwith the most recent commit's hash - Run
- Replace placeholder
sha256with actual hash from error message - Re-run
- Validate:
ruff-quickfix --help
{config,pkgs, ... }:
let# other stuff..ruff-quickfix=import(pkgs.fetchFromGitHub{owner="Nealium";repo="ruff-quickfix";# "commit hash" (can be found on GitHub)rev="{commit-hash}";# placeholder hash (replace after 1st run)sha256="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";}){inheritpkgs;};inhome.packages=[# other packages..ruff-quickfix]- Location:
~/.config/nvim/after/ftplugin/python.lua
vim.opt.makeprg=[[ruff-quickfix %]]vim.opt.errorformat=[[%f:%l:%c:%t:%m]]- Linux:
~/.vim/ftplugin/python.lua - Windows:
~/.vimfiles/ftplugin/python.lua
setlocalmakeprg=ruff-quickfix\ %setlocalerrorformat=%f:%l:%c:%t:%mThe command can be manually called from any Python file by calling the ex
command :make, which will lint your current buffer. I would recommend the
plugin vim-qf for some quickfix niceties.
The main benefit of using the quickfix with a linter is that you can do more wider scope lints, example: the entire project, and have all errors in a single quickfix! This requires making custom user commands
-- Current directory of focused buffer `:Druff`vim.api.nvim_create_user_command("Druff", function()
local_errorformat=vim.opt.errorformatvim.opt.errorformat=[[%f:%l:%c:%t:%m]]vim.g._cexpr=vim.fn.system({ "ruff-quickfix", vim.fn.expand("%:p:h") })
vim.cmd([[:cexpr g:_cexpr]])
vim.opt.errorformat=_errorformatend, {})
-- Current working directory, "project wide" `:Pruff`vim.api.nvim_create_user_command("Pruff", function()
local_errorformat=vim.opt.errorformatvim.opt.errorformat=[[%f:%l:%c:%t:%m]]vim.g._cexpr=vim.fn.system({ "ruff-quickfix", vim.fn.getcwd() })
vim.cmd([[:cexpr g:_cexpr]])
vim.opt.errorformat=_errorformatend, {})" Current Directory of focused buffer `:Druff`function!s:DirRuffMake()
letl:_errorformat= &errorformatseterrorformat=%f:%l:%c:%t:%mcexprsystem( "ruff-quickfix " .. expand("%:p:h") )
let &errorformat=l:_errorformatendfunctioncommand Druff calls:DirRuffMake()
-- Current working directory, "project wide" `:Pruff`
function!s:ProjectRuffMake()
letl:_errorformat= &errorformatseterrorformat=%A%f:%l:%c:%t:\ %m,%A%f:%l:\ %m,%A%f:(%l):\ %m,%-Z%p^%.%#,%-G%.%#
cexprsystem( "pylint --output-format=text --msg-template='{path}:{line}:{column}:{C}: [{symbol}] {msg}' --reports=no " .. expand("%:p:h") )
let &errorformat=l:_errorformatendfunctioncommand Pruff calls:ProjectRuffMake()Inside the extras directory you will find files that allow you to easily toggle between pylint and ruff. It also contains a standalone file of ruff-quickfix that doesn't require on click
