From afbc055587e88554b1fd11408cfab859d0cd40d3 Mon Sep 17 00:00:00 2001 From: Anton Ryazantsev <46319329+airreality@users.noreply.github.com> Date: Wed, 22 Nov 2023 08:58:02 +0800 Subject: [PATCH] Python ruff formatter (#484) Add python ruff formatter support https://github.com/astral-sh/ruff --- README.md | 3 ++- autoload/neoformat/formatters/python.vim | 10 +++++++++- doc/neoformat.txt | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e60ef0a..57365e27 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,8 @@ that caused Neoformat to be invoked. [`pydevf`](https://github.com/fabioz/PyDev.Formatter), [`isort`](https://github.com/timothycrosley/isort), [`docformatter`](https://github.com/myint/docformatter), - [`pyment`](https://github.com/dadadel/pyment) + [`pyment`](https://github.com/dadadel/pyment), + [`ruff`](https://github.com/astral-sh/ruff) - R - [`styler`](https://github.com/r-lib/styler), [`formatR`](https://github.com/yihui/formatR) diff --git a/autoload/neoformat/formatters/python.vim b/autoload/neoformat/formatters/python.vim index a6b98950..8257a3ca 100644 --- a/autoload/neoformat/formatters/python.vim +++ b/autoload/neoformat/formatters/python.vim @@ -1,5 +1,5 @@ function! neoformat#formatters#python#enabled() abort - return ['yapf', 'autopep8', 'black', 'isort', 'docformatter', 'pyment', 'pydevf'] + return ['yapf', 'autopep8', 'black', 'isort', 'docformatter', 'pyment', 'pydevf', 'ruff'] endfunction function! neoformat#formatters#python#yapf() abort @@ -58,3 +58,11 @@ function! neoformat#formatters#python#pydevf() abort \ 'replace': 1, \ } endfunction + +function! neoformat#formatters#python#ruff() abort + return { + \ 'exe': 'ruff', + \ 'stdin': 1, + \ 'args': ['format', '-q', '-'], + \ } +endfunction diff --git a/doc/neoformat.txt b/doc/neoformat.txt index 81e3da44..c09485c9 100644 --- a/doc/neoformat.txt +++ b/doc/neoformat.txt @@ -432,7 +432,8 @@ SUPPORTED FILETYPES *neoformat-supported-filetypes* [`pydevf`](https://github.com/fabioz/PyDev.Formatter), [`isort`](https://github.com/timothycrosley/isort), [`docformatter`](https://github.com/myint/docformatter), - [`pyment`](https://github.com/dadadel/pyment) + [`pyment`](https://github.com/dadadel/pyment), + [`ruff`](https://github.com/astral-sh/ruff) - R - [`styler`](https://github.com/r-lib/styler), [`formatR`](https://github.com/yihui/formatR)