Skip to main content

Wrapper for the `ruff` command for (neo)vim's quickfix

Project description

ruff-quickfix

Version Python Versions Poetry

GitHub Actions Workflow Status Codacy grade Codacy coverage

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.

Screenshot

Install

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\]

Source

Clone project: git clone https://github.com/Nealium/ruff-quickfix.git

  • Pipx: pipx install .
  • Pip: pip install .
  • Poetry: poetry install
  • From Wheel:
    • poetry install
    • poetry build
    • pipx 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.

  1. Insert items into home.nix
  2. Replace rev with the most recent commit's hash
  3. Run
  4. Replace placeholder sha256 with actual hash from error message
  5. Re-run
  6. 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=";
      }
    ) { inherit pkgs; };
in
  home.packages = [
    # other packages..

    ruff-quickfix
  ]

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. It also contains a standalone file of ruff-quickfix that doesn't require on click

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ruff_quickfix-0.2.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ruff_quickfix-0.2.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ruff_quickfix-0.2.1.tar.gz.

File metadata

  • Download URL: ruff_quickfix-0.2.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.12.10-76061203-generic

File hashes

Hashes for ruff_quickfix-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b10261a0fc7a5f94eed769a0bc50017596b2eb8b8c9945c0706485d9dc408329
MD5 85b2297678778e4580afdb052c92b631
BLAKE2b-256 c501c557ed0f36d4d9c604d9f22cfd27357cbb154d04097aef480ca713cfcb91

See more details on using hashes here.

File details

Details for the file ruff_quickfix-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ruff_quickfix-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.12.10-76061203-generic

File hashes

Hashes for ruff_quickfix-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec7da4dbb36ce076460fd34cf83e37e53a68fbbe61ba15c56143dfced40ad9ae
MD5 7d37aece3071c8f90cc2e6d44997a510
BLAKE2b-256 3cdf51435313e1f53689557889adf060c976677fa3b093cc1f7d340ef8d8e657

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page