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

running ALEFix on save #591

Closed
dxu opened this issue May 30, 2017 · 6 comments
Closed

running ALEFix on save #591

dxu opened this issue May 30, 2017 · 6 comments

Comments

@dxu
Copy link

dxu commented May 30, 2017

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!

@w0rp
Copy link
Member

w0rp commented May 30, 2017

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.

@w0rp
Copy link
Member

w0rp commented May 30, 2017

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.

@w0rp w0rp added this to the Version 1.4 milestone May 30, 2017
w0rp added a commit that referenced this issue May 30, 2017
@w0rp
Copy link
Member

w0rp commented May 30, 2017

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

@w0rp w0rp closed this as completed May 30, 2017
@dxu
Copy link
Author

dxu commented May 30, 2017

wow, thank you for the incredibly quick turnaround!

@sdondley
Copy link

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

@w0rp
Copy link
Member

w0rp commented Aug 15, 2018

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

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