Wrapper for the `ruff` command for (neo)vim's quickfix
Project description
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.
Config
Neovim
- Location:
~/.config/nvim/after/ftplugin/python.lua
vim.opt.makeprg = [[ruff-quickfix %]]
vim.opt.errorformat = [[%f:%l:%c:%t:%m]]
Vim
- Linux:
~/.vim/ftplugin/python.lua
- Windows:
~/.vimfiles/ftplugin/python.lua
setlocal makeprg=ruff-quickfix\ %
setlocal errorformat=%f:%l:%c:%t:%m
Usage
The 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.
Advanced Usage
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
Neovim
-- Current directory of focused buffer `:Druff`
vim.api.nvim_create_user_command("Druff", function()
local _errorformat = vim.opt.errorformat
vim.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 = _errorformat
end, {})
-- Current working directory, "project wide" `:Pruff`
vim.api.nvim_create_user_command("Pruff", function()
local _errorformat = vim.opt.errorformat
vim.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 = _errorformat
end, {})
Vim
" Current Directory of focused buffer `:Druff`
function! s:DirRuffMake()
let l:_errorformat = &errorformat
set errorformat=%f:%l:%c:%t:%m
cexpr system( "ruff-quickfix " .. expand("%:p:h") )
let &errorformat = l:_errorformat
endfunction
command Druff call s:DirRuffMake()
-- Current working directory, "project wide" `:Pruff`
function! s:ProjectRuffMake()
let l:_errorformat = &errorformat
set errorformat=%A%f:%l:%c:%t:\ %m,%A%f:%l:\ %m,%A%f:(%l):\ %m,%-Z%p^%.%#,%-G%.%#
cexpr system( "pylint --output-format=text --msg-template='{path}:{line}:{column}:{C}: [{symbol}] {msg}' --reports=no " .. expand("%:p:h") )
let &errorformat = l:_errorformat
endfunction
command Pruff call s:ProjectRuffMake()
Extras
Inside the extras directory you will find files that allow you to easily toggle between pylint and ruff, as well as a standalone file of ruff-quickfix.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ruff_quickfix-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ed06a6516a6d56c9672ecf94567a7b65a0d3e6f21d73993d38b0cc6b26d98c0 |
|
MD5 | 3d094271eb5917c57227dfa197af0193 |
|
BLAKE2b-256 | bd5e6eedf98f629281e60d5f1e3427334e78d31d06080b26d2a17b3fe6ef7d72 |