Ale: ALEDisable does not disable "fix on save"

Created on 9 Mar 2018  路  6Comments  路  Source: dense-analysis/ale

## Information
VIM version
NVIM v0.2.2
Build Type: Release
Operating System: macOS 10.13.3 (17D47)
## What went wrong
I ran the :ALEDisable command so ALE wouldn't fix the file on save, checked if g:ale_enabled
~~was falsy and saved the file, but the fixers still ran.
~~
## Reproducing the bug
Steps for repeating the bug:
1. Open a file that fixers would be applied to
1. Set g:ale_fix_on_save to 1 if not yet set
1. Run :ALEDisable
1. Save the file
### Expected
No fixers applied to the file when saved
### Actual Result
Prettier is still applied to the current file.
### Caveats
Manually setting g:ale_fix_on_save to 0 make ALE behave as expected.

Most helpful comment

If anyone comes here with the same problem, here's how I've worked my way around this:

I created a few commands in the file ~/.vim/plugin/commands.vim:

command! ALEDisableFixers       let g:ale_fix_on_save=0
command! ALEEnableFixers        let g:ale_fix_on_save=1
command! ALEDisableFixersBuffer let b:ale_fix_on_save=0
command! ALEEnableFixersBuffer  let b:ale_fix_on_save=0
command! ALEToggleFixers call functions#fckALEToggle('global')
command! ALEToggleFixersBuffer call functions#fckALEToggle('buffer')

And on my ~/.vim/autoload/functions.vim I've added the toggle function:

function! functions#fckALEToggle(...)
    let s:fckALEStatus = {}
    let s:fckALEStatus['global'] = get(g:, 'ale_fix_on_save', 0)
    let s:fckALEStatus['buffer'] = get(b:, 'ale_fix_on_save', s:fckALEStatus['global'])
    let s:fckCurrentScope = get(a:, 1, 'global')
    if (s:fckALEStatus[s:fckCurrentScope] == 1)
        let s:fckALEStatus[s:fckCurrentScope]=0
    else
        let s:fckALEStatus[s:fckCurrentScope]=1
    endif
    let g:ale_fix_on_save=s:fckALEStatus['global']
    let b:ale_fix_on_save=s:fckALEStatus['buffer']
endfunction

All 6 comments

So yeah, I guess I missed #1353 when looking through the issues and this is the expected behavior. Maybe add this info on the README to make it clear that :ALEDisable does not affect fixers?

If anyone comes here with the same problem, here's how I've worked my way around this:

I created a few commands in the file ~/.vim/plugin/commands.vim:

command! ALEDisableFixers       let g:ale_fix_on_save=0
command! ALEEnableFixers        let g:ale_fix_on_save=1
command! ALEDisableFixersBuffer let b:ale_fix_on_save=0
command! ALEEnableFixersBuffer  let b:ale_fix_on_save=0
command! ALEToggleFixers call functions#fckALEToggle('global')
command! ALEToggleFixersBuffer call functions#fckALEToggle('buffer')

And on my ~/.vim/autoload/functions.vim I've added the toggle function:

function! functions#fckALEToggle(...)
    let s:fckALEStatus = {}
    let s:fckALEStatus['global'] = get(g:, 'ale_fix_on_save', 0)
    let s:fckALEStatus['buffer'] = get(b:, 'ale_fix_on_save', s:fckALEStatus['global'])
    let s:fckCurrentScope = get(a:, 1, 'global')
    if (s:fckALEStatus[s:fckCurrentScope] == 1)
        let s:fckALEStatus[s:fckCurrentScope]=0
    else
        let s:fckALEStatus[s:fckCurrentScope]=1
    endif
    let g:ale_fix_on_save=s:fckALEStatus['global']
    let b:ale_fix_on_save=s:fckALEStatus['buffer']
endfunction

@w0rp do you mind if I make a pull-request to add these commands to the plugin itself? Or do you prefer to leave this to be solved on a per-user basis?

The commands don't need to be in the plugin, as they'd just do the same as using let.

My 2-cent: ALEDisable should switch everything off. I was caught quite off-guard when some subtle fixers were active despite by asking ALE to step down.

No. The command has a very different purpose, and predates fixing files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chauncey-garrett picture chauncey-garrett  路  3Comments

garand picture garand  路  4Comments

sublee picture sublee  路  3Comments

EdmundsEcho picture EdmundsEcho  路  3Comments

lervag picture lervag  路  3Comments