ruff-quickfix


Nameruff-quickfix JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/Nealium/ruff-quickfix
SummaryWrapper for the `ruff` command for (neo)vim's quickfix
upload_time2024-09-14 19:20:15
maintainerNone
docs_urlNone
authorNeal Joslin
requires_python<4.0,>=3.8
licenseLICENSE
keywords ruff cli vim neovim nvim quickfix
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- markdownlint-disable MD033 MD041 MD024 -->
<div align="center">

# ruff-quickfix

[![Version](https://img.shields.io/pypi/v/ruff-quickfix?style=for-the-badge)](https://pypi.org/project/ruff-quickfix/)
![Python Versions](https://img.shields.io/pypi/pyversions/ruff-quickfix?style=for-the-badge&logo=python&logoColor=white)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=for-the-badge)](https://python-poetry.org/)

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Nealium/ruff-quickfix/tox.yml?style=for-the-badge)
![Codacy grade](https://img.shields.io/codacy/grade/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)
![Codacy coverage](https://img.shields.io/codacy/coverage/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)

</div>

This is a simple wrapper for the Python linter [ruff](https://github.com/astral-sh/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](screenshot.png)

## Install

### [pipx](https://github.com/pypa/pipx) *(recommended)*

**Note:** Normal pip works as well, though you should give pipx a try!

* [PyPi](https://pypi.org/project/ruff-quickfix/): `pipx install ruff-quickfix`
* [GitHub](https://github.com/Nealium/ruff-quickfix): `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](https://github.com/nix-community/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`

```nix
{ 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`

``` 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`

```vim
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](https://github.com/romainl/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

```lua
-- 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

```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](https://click.palletsprojects.com)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Nealium/ruff-quickfix",
    "name": "ruff-quickfix",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "ruff, cli, vim, neovim, nvim, quickfix",
    "author": "Neal Joslin",
    "author_email": "neal@joslin.io",
    "download_url": "https://files.pythonhosted.org/packages/73/61/3a2cc1d15cb7f904960503b6967809a53a6246f78f5be55a60ad31df5fd4/ruff_quickfix-0.2.0.tar.gz",
    "platform": null,
    "description": "<!-- markdownlint-disable MD033 MD041 MD024 -->\n<div align=\"center\">\n\n# ruff-quickfix\n\n[![Version](https://img.shields.io/pypi/v/ruff-quickfix?style=for-the-badge)](https://pypi.org/project/ruff-quickfix/)\n![Python Versions](https://img.shields.io/pypi/pyversions/ruff-quickfix?style=for-the-badge&logo=python&logoColor=white)\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=for-the-badge)](https://python-poetry.org/)\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Nealium/ruff-quickfix/tox.yml?style=for-the-badge)\n![Codacy grade](https://img.shields.io/codacy/grade/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)\n![Codacy coverage](https://img.shields.io/codacy/coverage/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)\n\n</div>\n\nThis is a simple wrapper for the Python linter [ruff](https://github.com/astral-sh/ruff)\nthat allows it to be easily used with (neo)vim's quickfix.\n\n**Why?** I like Vim's quickfix and find it more useful in some situations over\nusing an LSP. Also this is an excuse to learn publishing.\n\n![Screenshot](screenshot.png)\n\n## Install\n\n### [pipx](https://github.com/pypa/pipx) *(recommended)*\n\n**Note:** Normal pip works as well, though you should give pipx a try!\n\n* [PyPi](https://pypi.org/project/ruff-quickfix/): `pipx install ruff-quickfix`\n* [GitHub](https://github.com/Nealium/ruff-quickfix): `pipx install git+https://github.com/Nealium/ruff-quickfix`\n* If you don't already have ruff you include it as an \"extra\"\n  * `pipx install ruff-quickfix[ruff]`\n  * if zsh: `pipx install ruff-quickfix\\[ruff\\]`\n\n### Source\n\nClone project: `git clone https://github.com/Nealium/ruff-quickfix.git`\n\n* Pipx: `pipx install .`\n* Pip: `pip install .`\n* Poetry: `poetry install`\n* From Wheel:\n  * `poetry install`\n  * `poetry build`\n  * `pipx install dist/*.whl`\n\n### [Home Manager](https://github.com/nix-community/home-manager) *(nix)*\n\n**Note!** This **will** crash on the first run as the sha256 isn't *real*. Once\nit crashes the error message will provide the *actual* sha256 that is required.\n\n1. Insert items into `home.nix`\n2. Replace `rev` with the most recent commit's hash\n3. Run\n4. Replace placeholder `sha256` with actual hash from error message\n5. Re-run\n6. Validate: `ruff-quickfix --help`\n\n```nix\n{ config, pkgs, ... }:\nlet\n  # other stuff..\n\n  ruff-quickfix = import\n    (pkgs.fetchFromGitHub\n      {\n        owner = \"Nealium\";\n        repo = \"ruff-quickfix\";\n\n        # \"commit hash\" (can be found on GitHub)\n        rev = \"{commit-hash}\";\n\n        # placeholder hash (replace after 1st run)\n        sha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\";\n      }\n    ) { inherit pkgs; };\nin\n  home.packages = [\n    # other packages..\n\n    ruff-quickfix\n  ]\n```\n\n## Config\n\n### Neovim\n\n* **Location:** `~/.config/nvim/after/ftplugin/python.lua`\n\n``` lua\nvim.opt.makeprg = [[ruff-quickfix %]]\nvim.opt.errorformat = [[%f:%l:%c:%t:%m]]\n```\n\n### Vim\n\n* Linux: `~/.vim/ftplugin/python.lua`\n* Windows: `~/.vimfiles/ftplugin/python.lua`\n\n```vim\nsetlocal makeprg=ruff-quickfix\\ %\nsetlocal errorformat=%f:%l:%c:%t:%m\n```\n\n## Usage\n\nThe command can be manually called from any Python file by calling the ex\ncommand `:make`, which will lint your current buffer. I would recommend the\nplugin [vim-qf](https://github.com/romainl/vim-qf) for some quickfix niceties.\n\n## Advanced Usage\n\nThe main benefit of using the quickfix with a linter is that you can do more\nwider scope lints, example: the entire project, and have **all**\nerrors in a single quickfix! This requires making custom user commands\n\n### Neovim\n\n```lua\n-- Current directory of focused buffer `:Druff`\nvim.api.nvim_create_user_command(\"Druff\", function()\n    local _errorformat = vim.opt.errorformat\n    vim.opt.errorformat = [[%f:%l:%c:%t:%m]]\n    vim.g._cexpr = vim.fn.system({ \"ruff-quickfix\", vim.fn.expand(\"%:p:h\") })\n    vim.cmd([[:cexpr g:_cexpr]])\n    vim.opt.errorformat = _errorformat\nend, {})\n\n-- Current working directory, \"project wide\" `:Pruff`\nvim.api.nvim_create_user_command(\"Pruff\", function()\n    local _errorformat = vim.opt.errorformat\n    vim.opt.errorformat = [[%f:%l:%c:%t:%m]]\n    vim.g._cexpr = vim.fn.system({ \"ruff-quickfix\", vim.fn.getcwd() })\n    vim.cmd([[:cexpr g:_cexpr]])\n    vim.opt.errorformat = _errorformat\nend, {})\n```\n\n### Vim\n\n```vim\n\" Current Directory of focused buffer `:Druff`\nfunction! s:DirRuffMake()\n    let l:_errorformat = &errorformat\n    set errorformat=%f:%l:%c:%t:%m\n    cexpr system( \"ruff-quickfix \" .. expand(\"%:p:h\") )\n    let &errorformat = l:_errorformat \nendfunction\ncommand Druff call s:DirRuffMake()\n\n-- Current working directory, \"project wide\" `:Pruff`\nfunction! s:ProjectRuffMake()\n    let l:_errorformat = &errorformat\n    set errorformat=%A%f:%l:%c:%t:\\ %m,%A%f:%l:\\ %m,%A%f:(%l):\\ %m,%-Z%p^%.%#,%-G%.%#\n    cexpr system( \"pylint --output-format=text --msg-template='{path}:{line}:{column}:{C}: [{symbol}] {msg}' --reports=no \" .. expand(\"%:p:h\") )\n    let &errorformat = l:_errorformat \nendfunction\ncommand Pruff call s:ProjectRuffMake()\n```\n\n## Extras\n\nInside the extras directory you will find files that allow you to easily toggle\nbetween pylint and ruff. It also contains a standalone file of ruff-quickfix\nthat doesn't require on [click](https://click.palletsprojects.com)\n",
    "bugtrack_url": null,
    "license": "LICENSE",
    "summary": "Wrapper for the `ruff` command for (neo)vim's quickfix",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/Nealium/ruff-quickfix",
        "Repository": "https://github.com/Nealium/ruff-quickfix"
    },
    "split_keywords": [
        "ruff",
        " cli",
        " vim",
        " neovim",
        " nvim",
        " quickfix"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d352082d22fafd27f3c6b1024c593e785fd023b8b5ed99a90ef919055c509f5",
                "md5": "73421d504307c956feb7bcdb32898698",
                "sha256": "89e7cc6822a990d31b816f9b174f8c8b154d7428f74734ddf3b056417fdfaefc"
            },
            "downloads": -1,
            "filename": "ruff_quickfix-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "73421d504307c956feb7bcdb32898698",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 9647,
            "upload_time": "2024-09-14T19:20:13",
            "upload_time_iso_8601": "2024-09-14T19:20:13.109853Z",
            "url": "https://files.pythonhosted.org/packages/4d/35/2082d22fafd27f3c6b1024c593e785fd023b8b5ed99a90ef919055c509f5/ruff_quickfix-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73613a2cc1d15cb7f904960503b6967809a53a6246f78f5be55a60ad31df5fd4",
                "md5": "785673a948c0a508946a1e67f62926fc",
                "sha256": "250fff933e8b398e6fb8cd7688d0ed2d9e86d14fba3218773df1372b4ac4eccf"
            },
            "downloads": -1,
            "filename": "ruff_quickfix-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "785673a948c0a508946a1e67f62926fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 8424,
            "upload_time": "2024-09-14T19:20:15",
            "upload_time_iso_8601": "2024-09-14T19:20:15.099671Z",
            "url": "https://files.pythonhosted.org/packages/73/61/3a2cc1d15cb7f904960503b6967809a53a6246f78f5be55a60ad31df5fd4/ruff_quickfix-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-14 19:20:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Nealium",
    "github_project": "ruff-quickfix",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "ruff-quickfix"
}
        
Elapsed time: 5.00744s