Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate fixers on save from enabled fixers. #1930

Closed
davidtwco opened this issue Sep 17, 2018 · 5 comments
Closed

Separate fixers on save from enabled fixers. #1930

davidtwco opened this issue Sep 17, 2018 · 5 comments

Comments

@davidtwco
Copy link
Contributor

I'd like to be able to have a set of fixers that run on save that is separate from the fixers that run with :ALEFix.

For example, I universally want to have the remove_trailing_lines and trim_whitespace fixers to run when I save a file, but I do not always want to run the rustfmt fixer when I save (some projects don't use it and I don't want to reformat lots of code that isn't my own).

" `ale_fixers` is a superset of `ale_fixers_on_save` and contains those listed in `ale_fixers_on_save`.
let g:ale_fixers = {
\   'rust': [ 'rustfmt' ],
\ }
let g:ale_fixers_on_save = {
\   '*': [ 'remove_trailing_lines', 'trim_whitespace' ],
\ }

This would enable me to always have trailing lines removed and whitespace trimmed without needing to remember to do that, but gives me the option of triggering rustfmt manually through ALE on my own projects with my binding to :ALEFix.

@w0rp
Copy link
Member

w0rp commented Sep 17, 2018

For now, you can also use :ALEFix rustfmt You can pass the names of fixers to use for one run.

@JeanMertz
Copy link
Contributor

I ran into this today as well. As a first step, I have something like this:

nnoremap F :ALEFixToggle<CR>

function! ALEFixToggle()
	if g:ale_fix_on_save ==# 1
		let g:ale_fix_on_save = 0
		echo "ALEFix disabled"
	else
		let g:ale_fix_on_save = 1
		echo "ALEFix enabled"
	endif
endfunction

command! ALEFixToggle call ALEFixToggle()

And in a custom after/ftplugin/rust.vim:

" Only enable rustfmt if a `rustfmt.toml` file exists.
let g:ale_fix_on_save = filereadable("rustfmt.toml")

This makes it easy to only use rustfmt when a project explicitly requires it through the rustfmt.toml configuration file, but also quickly enable/disable it using F.

This has a dependecy on something like vim-rooter.

@w0rp w0rp added this to To Do in Old Working List via automation Apr 10, 2019
@w0rp w0rp moved this from To Do to In Progress in Old Working List Apr 15, 2019
@w0rp
Copy link
Member

w0rp commented Apr 15, 2019

Having thought about this, it will be better to add an option to ignore fixers on save, rather than select them. Consider the following case where you select fixers to run.

let g:ale_fixers = {'foo': ['a', 'b'], 'bar': ['c']}
let g:ale_fixers_on_save = {'foo': ['b']}
" Say your filetype is `foo.bar`.
" Whether you want ['b', 'c'] or only ['b'] is ambiguous.

Consider it again where you ignore them.

let g:ale_fixers = {'foo': ['a', 'b'], 'bar': ['c']}
let g:ale_fix_on_save_ignore = {'foo': ['a']}
" No ambiguity, the result is ['b', 'c'] 

" Lists would also work for applying to all filetypes.
let g:ale_fix_on_save_ignore = ['a']

As always, Lists in ftplugin files are preferred, and make life simpler.

let b:ale_fixers = ['a', 'b', 'c']
let b:ale_fix_on_save_ignore = ['b']

I have implemented this, pending some tests.

@w0rp w0rp closed this as completed in 59f8c35 Apr 16, 2019
Old Working List automation moved this from In Progress to Done Apr 16, 2019
@w0rp
Copy link
Member

w0rp commented Apr 16, 2019

That option has been added now.

@davidtwco
Copy link
Contributor Author

Thanks, that’s great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants