Closed MaxG87 closed 1 year ago
Hi @MaxG87
You can try using ALEFixPre
and ALEFixPost
autocmd
s to control this. I have not tried this myself, but something similar to this might be what you're looking for:
augroup PythonRuffFixer
autocmd!
autocmd User ALEFixPre let b:ale_python_ruff_options = '--select=I'
autocmd User ALEFixPost let b:ale_python_ruff_options = ''
augroup END
This works. Thank you very much.
I had to translate the autocommand group to Lua yesterday. It was quite hard to figure out, so I want to share the result with anyone dropping in here:
local python_ruff_fixer = vim.api.nvim_create_augroup("PythonRuffFixer", { clear = true })
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "ALEFixPre",
group = python_ruff_fixer,
callback = function() vim.g.ale_python_ruff_options = '--select=I' end,
})
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "ALEFixPost",
group = python_ruff_fixer,
callback = function() vim.g.ale_python_ruff_options = '' end ,
})
Hi there,
thank you for the great tool! I depend really on it!
tl;dr: I would like to specify
let g:ale_python_ruff_options = '--select=I'
, but only when running fixers, not when generating lints. I am sure other use cases would benefit from that too.I recently onboarded
ruff
to my Python tool chain. I have enabled all sorts of lints, but in particular the usualflake8
andisort
rules are enabled. I want to replace my usage ofisort
with it, among other things.When I got rid of
isort
in some project, I noticed that the imports were not automatically ordered when saving. So I addedruff
to the list of ALE Fixers. Unfortunately, this is annoying, as now, upon saving, unused imports and unused variables are removed byruff
.So, I could add
let g:ale_python_ruff_options = '--select=I'
to my VIM settings. Unfortunately, with that I would disable all interesting and helpful lints too. What I actually would like to do is to pass settings toruff
only when running it as fixer, not as linter.