Can I Sort work with Ruff formatter? (not linter)

1.2k views Asked by At

I am migrating my project to RUFF. The migration was kind of straightforward, but for some reason, ISort rules are not being applied when I do this commands on VSCode: Format code with > Ruff

I see this when I have my imports usorted:

enter image description here

I can click con the Fast fix option (Ctrl+.. sorry, my VSCode is in Spanish) and it get fixed, but it does not when I do the VSCode Format Code With > Ruff.

In case you want to know, the imports gets fixed when I run ruff check . --fix.

Here is my ruff.toml


[lint]
extend-select = [
  "E501", # Add the `line-too-long` rule to the enforced rule set.  # By default, Ruff omits rules that overlap with the use of a formatter
]
ignore = [
  "E712", # (x == True) is allowed.
  "D100", # Docstring allowed rules
  "D105",
  "D107",
  "D203",
  "D213",
]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or McCabe complexity (`C901`) by default.
# Also add ISort (`I`) rules.
select = ["E4", "E7", "E9", "F", "I"]

# Allow fix for all enabled rules (when `--fix`) is provided. (only safes fixes will be applied)
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

I am probably doing something wrong, because this iSort fixes used to work with the black formatter. And I have this option selected in VSCode settings.

enter image description here

Thanks in advance.

1

There are 1 answers

0
timo.rieber On

I don't know if ruff is executed with the --fix flag in this VS Code command, but I would try to include fix = true in the ruff.toml.

See https://docs.astral.sh/ruff/settings/#fix for details.