Skip to content

Commit

Permalink
Add ruff-isort formatter (#279)
Browse files Browse the repository at this point in the history
`ruff` doesn't run isort as part of its format, so to maintain parity
with the sort rules that black/isort offer, this is the ruff isort.

---------

Co-authored-by: Radon Rosborough <[email protected]>
  • Loading branch information
offbyone and raxod502 authored Jan 12, 2024
1 parent 1d6f821 commit 96a9805
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog].
for JSON ([#257]).
* [`robotidy`](https://robotidy.readthedocs.io) for Robot Framework files
([#263]).
* [`ruff-isort`](https://github.com/astral-sh/ruff) for [Python](https://python.org) imports using ruff ([#279]).
* [denofmt](https://docs.deno.com/runtime/manual/tools/formatter) for
js, jsx, ts, tsx, json, jsonc, md files. ([#264])
* [docformatter](https://github.com/PyCQA/docformatter) for Python docstrings ([#267])
Expand All @@ -51,6 +52,7 @@ The format is based on [Keep a Changelog].
[#271]: https://github.com/radian-software/apheleia/pull/271
[#274]: https://github.com/radian-software/apheleia/issues/274
[#275]: https://github.com/radian-software/apheleia/pull/275
[#279]: https://github.com/radian-software/apheleia/pull/279

## 4.0 (released 2023-11-23)
### Breaking changes
Expand Down
6 changes: 6 additions & 0 deletions apheleia-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
(apheleia-formatters-fill-column "--line-length")
"--stdin-filename" filepath
"-"))
(ruff-isort . ("ruff" "check"
"-n"
"--select" "I"
"--fix" "--fix-only"
"--stdin-filename" filepath
"-"))
(shfmt . ("shfmt"
"-filename" filepath
"-ln" (cl-case (bound-and-true-p sh-shell)
Expand Down
2 changes: 2 additions & 0 deletions test/formatters/installers/ruff-isort.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt-get install -y python3-pip
pip install ruff
20 changes: 20 additions & 0 deletions test/formatters/samplecode/ruff-isort/in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from my_lib import Object

import os

from my_lib import Object3

from my_lib import Object2

import sys

from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14

import sys

from __future__ import absolute_import

from third_party import lib3

print("Hey")
print("yo")
26 changes: 26 additions & 0 deletions test/formatters/samplecode/ruff-isort/out.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import absolute_import

import os
import sys

from my_lib import Object, Object2, Object3
from third_party import (
lib1,
lib2,
lib3,
lib4,
lib5,
lib6,
lib7,
lib8,
lib9,
lib10,
lib11,
lib12,
lib13,
lib14,
lib15,
)

print("Hey")
print("yo")

0 comments on commit 96a9805

Please sign in to comment.