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

ale_fix_on_save creates junk files when fixing buffers not in focus (neovim) #2711

Closed
good-idea opened this issue Aug 17, 2019 · 5 comments
Closed
Labels

Comments

@good-idea
Copy link

good-idea commented Aug 17, 2019

Information

VIM version

NVIM v0.4.0-1472-gbae02eb39
Build type: Release
LuaJIT 2.0.5
Compilation: /Applications/Xcode-10.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=
3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -f
diagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/Users/travis/build/neovim/bot-ci/build/neovim/build/
config -I/Users/travis/build/neovim/bot-ci/build/neovim/src -I/Users/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/
Users/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/Users/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by [email protected]

Operating System:

OS X 10.14.5

Other Config

Here is my .vimrc:

https://github.com/good-idea/dotfiles/blob/master/vim/vimrc.vim

I've toggled all of the other installed plugins, it doesn't seem to be a problem with anything else that is installed. It's also happening with both the eslint and prettier fixers, on both .js and .ts files.

What went wrong

I have Ale configured to auto-fix on file save. When I save a file that is not the currently focused buffer, a "junk file" is created with a filename like "12:p". This file contains the "fixed" contents.

The fixes are applied in Buffer A, but, after quitting vim (:qa) and re-opening, the original file does not show the fixes. (This is all happening in Neovim, see the notes about behavior from standard vim below)

Reproducing the bug

Given a file foo.ts:

const sum = (a: number, b: number) => {



  return a + b

}
  1. Open two files in split buffers
  2. Make changes to the file in buffer A that will auto-fix (for instance, add a bunch of newlines that will be removed with the auto-fix)
  3. Change focus to buffer 2
  4. Execute :wa to save all files
  • Newlines have been removed in Buffer A, as expected:
const sum = (a: number, b: number) => {
  return a + b
}
  • Junk file "1:p" is now in the directory, with the contents:
const sum = (a: number, b: number) => {
  return a + b
}
  1. Open vim again, then open test.tsx
  • File has original, unfixed contents

When using normal vim

It's only Neovim that creates the junk files. When doing the above steps in standard vim (8.0.1283), the fix does correctly apply to the file, but the changes are not reflected in the buffer until I change focus back to it.

This seems related to #1960 and #591

:ALEInfo

From Buffer A (the file getting fixed, after running :wa from buffer B):

 Current Filetype: typescript
Available Linters: ['eslint', 'tslint', 'tsserver', 'typecheck', 'xo']
  Enabled Linters: ['tslint', 'tsserver']
 Suggested Fixers: 
  'eslint' - Apply eslint --fix to a file.
  'prettier' - Apply prettier to a file.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'tslint' - Fix typescript files with tslint --fix.
  'xo' - Fix JavaScript/TypeScript files using xo --fix.
 Linter Variables:

let g:ale_typescript_tslint_config_path = ''
let g:ale_typescript_tslint_executable = 'tslint'
let g:ale_typescript_tslint_ignore_empty_files = 0
let g:ale_typescript_tslint_rules_dir = ''
let g:ale_typescript_tslint_use_global = 0
let g:ale_typescript_tsserver_config_path = ''
let g:ale_typescript_tsserver_executable = 'tsserver'
let g:ale_typescript_tsserver_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = 50
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'javascript': ['prettier'], 'typescript': ['prettier'], 'css': ['prettier']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'javascript': ['eslint', 'flow-language-server'], 'typescript': ['tslint', 'tsserver']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = v:null
let g:ale_list_window_size = v:null
let g:ale_loclist_msg_format = v:null
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = v:null
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:null
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '◉'
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = '◉'
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) /Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/tsserver
(started) ['/usr/local/bin/zsh', '-c', '''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/tsserver''']
(finished - exit code 0) ['/usr/local/bin/zsh', '-c', '''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/prettier'' --version']

<<<OUTPUT STARTS>>>
1.18.2
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/usr/local/bin/zsh', '-c', 'cd ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/src'' && ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/prettier'' --stdin-filepath ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/src/test.ts'' --stdin < ''/var/folders/d7/tlsyl3dx2f73v9j7ght57cqm0000gn/T/nvimmmkrF9/3/test.ts''']

From Buffer B (not the file that is getting fixed):


 Current Filetype: typescript.tsx
Available Linters: ['eslint', 'tslint', 'tsserver', 'typecheck', 'xo']
  Enabled Linters: ['tslint', 'tsserver']
 Suggested Fixers: 
  'eslint' - Apply eslint --fix to a file.
  'prettier' - Apply prettier to a file.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'tslint' - Fix typescript files with tslint --fix.
  'xo' - Fix JavaScript/TypeScript files using xo --fix.
 Linter Variables:

let g:ale_typescript_tslint_config_path = ''
let g:ale_typescript_tslint_executable = 'tslint'
let g:ale_typescript_tslint_ignore_empty_files = 0
let g:ale_typescript_tslint_rules_dir = ''
let g:ale_typescript_tslint_use_global = 0
let g:ale_typescript_tsserver_config_path = ''
let g:ale_typescript_tsserver_executable = 'tsserver'
let g:ale_typescript_tsserver_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = 50
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'javascript': ['prettier'], 'typescript': ['prettier'], 'css': ['prettier']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'javascript': ['eslint', 'flow-language-server'], 'typescript': ['tslint', 'tsserver']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = v:null
let g:ale_list_window_size = v:null
let g:ale_loclist_msg_format = v:null
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = v:null
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:null
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '◉'
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = '◉'
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(started) ['/usr/local/bin/zsh', '-c', '''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/tsserver''']
(finished - exit code 0) ['/usr/local/bin/zsh', '-c', '''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/prettier'' --version']

<<<OUTPUT STARTS>>>
1.18.2
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/usr/local/bin/zsh', '-c', 'cd ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/src'' && ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/node_modules/.bin/prettier'' --stdin-filepath ''/Users/joseph/Sites/special---offer/songsforyou.tinashenow.com/app/src/index.tsx'' --stdin < ''/var/folders/d7/tlsyl3dx2f73v9j7ght57cqm0000gn/T/nvimmmkrF9/2/index.tsx''']
@good-idea
Copy link
Author

@w0rp , I just realized that I was on a pre-release of nvim 4 (from their nightlies). I tried it with nvim 3.8, and it doesn't happen there - so, it looks like it's an issue with nvim 4

It might make sense to close this issue for now, and revisit if it still comes up once a stable nvim 4 is released

@promisedlandt
Copy link

Fwiw, this also happens to me in Vim 8.1 (using rubocop for Ruby).

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 15 2019 16:41:15)
Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401

@good-idea
Copy link
Author

nvim 4 was released, this is still an issue with nvim 4.2

@w0rp
Copy link
Member

w0rp commented Sep 19, 2019

I've fixed this now. The issue was just writing to a junk filename instead of the buffer because '#' was omitted at the front of expand().

@promisedlandt
Copy link

Man, vimscript is weird :)
Thanks!

timlag1305 pushed a commit to timlag1305/ale that referenced this issue Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants