ruff icon indicating copy to clipboard operation
ruff copied to clipboard

I001 does not use human sort.

Open ghuls opened this issue 3 years ago • 1 comments

I001 does not use human sort like isort.

I001 also does not indicate the lines on which it finds the problem, but always mentions the first line of the file even if the first x lines are correctly sorted.

# Output as generated by: isort --profile=black /tmp/human_sort_import.py
$ ❯ cat /tmp/human_sort_import.py
from numpy import (
    cos,
    int8,
    int16,
    int32,
    int64,
    sin,
    tan,
    uint8,
    uint16,
    uint32,
    uint64,
)
$ ruff --select I001 --ignore F401  --no-cache /tmp/human_sort_import.py 
/tmp/human_sort_import.py:1:1: I001 Import block is un-sorted or un-formatted
Found 1 error(s).
1 potentially fixable with the --fix option.

$ cp -a /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py

$ ruff --select I001 --ignore F401 --no-cache --fix /tmp/human_sort_import.fixed.py 
Found 1 error(s) (1 fixed, 0 remaining).

$ diff -u /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py
--- /tmp/human_sort_import.py	2022-12-25 11:06:19.072930208 +0100
+++ /tmp/human_sort_import.fixed.py	2022-12-25 11:17:51.707302881 +0100
@@ -1,13 +1,13 @@
 from numpy import (
     cos,
-    int8,
     int16,
     int32,
     int64,
+    int8,
     sin,
     tan,
-    uint8,
     uint16,
     uint32,
     uint64,
+    uint8,
 )

$ isort --profile=black /tmp/human_sort_import.fixed.py
Fixing /tmp/human_sort_import.fixed.py

$ diff -u /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py

ghuls avatar Dec 25 '22 10:12 ghuls

Makes sense, thank you! Hopefully easy to fix.

The error ranges could be improved too but it will take a bit more care. Right now, they report based on the start and end of the import block (slew of consecutive imports), since we compare entire blocks at a time.

charliermarsh avatar Dec 25 '22 15:12 charliermarsh