VIM version
NVIM v0.5.0-nightly
Build type: Release
LuaJIT 2.0.5
Operating System:
macOS Catalina
10.15.4 (19E287)
Linting does not work for files with square brackets in the name.
This is a problem with some other linting projects:
https://github.com/stylelint/stylelint/issues/4515
https://github.com/okonet/lint-staged/issues/676
script.tsx.[script].tsx.Current Filetype: typescriptreact
Available Linters: ['eslint', 'standard', 'tslint', 'tsserver', 'typecheck', 'xo']
Enabled Linters: ['tsserver']
Suggested Fixers:
'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.
Linter Variables:
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 = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
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 = {'typescript': ['prettier'], 'json': ['prettier'], 'typescriptreact': ['prettier'], 'javascriptreact': ['prettier'], 'graphql': ['prettier'], 'prisma': ['prettier'], 'javascript': ['prettier'], 'css': ['prettier'], 'python': ['black']}
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 = 100
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 = {'cs': ['OmniSharp'], 'javascript': ['tsserver'], 'javascriptreact': ['tsserver'], 'typescriptreact': ['tsserver'], 'json': ['jsonlint'], 'typescript': ['tsserver'], 'python': ['mypy']}
let g:ale_linters_explicit = 1
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 = 1
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 = 2
let g:ale_set_signs = 1
let g:ale_sign_column_always = v:null
let g:ale_sign_error = v:null
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 = v:null
let g:ale_sign_highlight_linenrs = v:null
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = 1
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) tsserver
(started) ['/bin/zsh', '-c', '''tsserver''']
(finished - exit code 0) ['/bin/zsh', '-c', '''prettier'' --version']
<<
(finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/Users/jeremiahmontoya/Documents/x/repos/x.com/src/pages/post'' && ''prettier'' --stdin-filepath ''/Users/jeremiahmontoya/Documents/x/repos/x.com/src/pages/post/[slug].tsx'' --stdin < ''/var/folders/63/bmfw9dcd0n59c7jfmt75pq8m0000gp/T/nvimDv04h9/4/[slug].tsx''']
I don't have tsserver on my box, so I can't speak to it. However, with other linters I have, file names with brackets work fine. I tried this:
user@box:~% nvim foo.c
user@box:~% mv foo.c '[foo].c'
user@box:~% nvim '[foo].c'
And it linted just fine. Same with .sh and .py files
Perhaps it has something to do with tsserver.
Noted. Thanks for checking.
I was able to bypass the problem by adding this:
autoload/ale/ale_linter.vim (line 53)
function! s:HandleTSServerDiagnostics(response, error_type) abort
let l:linter_name = 'tsserver'
let l:buffer = bufnr('^' . a:response.body.file . '$')
" start edit
if l:buffer == -1
let l:buffer = 1
endif
" end edit
let l:info = get(g:ale_buffer_info, l:buffer, {})
It seems function bufnr is returning -1 instead of 1 when I'm editing files with bracket-filenames, so I'm forcing the value to 1 instead. Clearly, this is not an actual fix, but it does seem to solve the problem for me.
For those looking for the file it can be found here: https://github.com/dense-analysis/ale/blob/5eda1df0a96e691ebf24e5d8a3585c2feb2a48a3/autoload/ale/lsp_linter.vim#L53
And to highlight the changes @thisjeremiah made:
function! s:HandleTSServerDiagnostics(response, error_type) abort
let l:linter_name = 'tsserver'
let l:buffer = bufnr('^' . a:response.body.file . '$')
+ if l:buffer == -1
+ let l:buffer = 1
+ endif
Many ALE users are likely to encounter this issue as bracket filenames are how the popular framework Next.js handles dynamic routing.
I've pushed a fix for this now. I can't work out how to escape { or } in filenames on Windows, so I didn't bother right now. If any Windows users know how to handle that, let me know. All other filename characters should work now.
Most helpful comment
For those looking for the file it can be found here: https://github.com/dense-analysis/ale/blob/5eda1df0a96e691ebf24e5d8a3585c2feb2a48a3/autoload/ale/lsp_linter.vim#L53
And to highlight the changes @thisjeremiah made:
Many ALE users are likely to encounter this issue as bracket filenames are how the popular framework Next.js handles dynamic routing.