Ale: running ALEFix on save

Created on 30 May 2017  路  6Comments  路  Source: dense-analysis/ale

Hello! I am a new user of ale, I noticed the work done on #571, and have started trying to use it. I'm running into issues when trying to run it on save (which is being tackled by #570), but figured I might as well ask in case it is due to user error.

Here are my configs:

let g:ale_fixers = {}
let g:ale_fixers.javascript = [
\ 'prettier',
\ 'eslint',
\]
let g:ale_javascript_prettier_options = ' --stdin\ --parser\ flow\ --single-quote\ --trailing-comma\ all\ --no-bracket-spacing'

autocmd BufWrite *.js ALEFix

I'm noticing a few things:

  1. I'm trying to set up a autocommand to run ALEFix on save, but for some reason when I save, the file will write, the checker will run, and then the buffer will update with the changes. As a result:
    a. vim complains that the buffer has not yet been saved when trying to quit
    b. if i very quickly quit before the buffer updates with the change, the fix won't actually occur (e.g, via :wq.

Is this due to some async feature of ale? I previously used neoformat to do something similar, for which this doesn't occur.

  1. when specifying ale_fixers for javascript, if I change the order of eslint and prettier so that eslint comes before prettier, the javascript_prettier_options don't get applied.

  2. If I don't specify ale_javascript_prettier_options, ALEFix runs into an error

Error detected while processing function ale#fix#Fix[21]..<SNR>213_RunFixer[6]..ale#handlers#prettier#Fix[1]..ale#Var:
line    3:
E716: Key not present in Dictionary: ale_javascript_prettier_options
E116: Invalid arguments for function getbufvar(str2nr(a:buffer), l:full_name, g:[l:full_name])
E15: Invalid expression: getbufvar(str2nr(a:buffer), l:full_name, g:[l:full_name])

Thank you for doing such amazing work!

enhancement

Most helpful comment

This is supported with an option now. See :help g:ale_fix_on_save.

All 6 comments

You can't accomplish this with a simple autocmd on BufWrite. I will add support for this eventually.

The jobs for fixing files run asynchronously, so eslint and prettier will stop executing _after_ the file has already been closed. I need to change the code so it can be used for writing changes back to the file on disk, even if the buffer is no longer open.

I'll have to make a note to change ale#Var so it can look up buffer variables from a Dictionary which is saved for fixing files if the buffer is closed before fixing is completed.

This is supported with an option now. See :help g:ale_fix_on_save.

wow, thank you for the incredibly quick turnaround!

Not sure if this can be fixed but when I do a :wq in NeoVim I get these errors:

Error detected while processing function <SNR>99_NeoVimCallback[29]..<SNR>106_HandleExit:
line   13:
E484: Can't open file /var/folders/nc/1y1czqf96736xppxnnkmgkrc0000gn/T/nvimrSHvON/6/keyword_args.rb

Please open a new issue with steps for repeating the bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aressler38 picture aressler38  路  3Comments

alexlafroscia picture alexlafroscia  路  4Comments

trevordmiller picture trevordmiller  路  3Comments

glepnir picture glepnir  路  3Comments

trevordmiller picture trevordmiller  路  3Comments