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

No linting TypeScript files on filenames with brackets #3183

Closed
thisjeremiah opened this issue May 22, 2020 · 4 comments
Closed

No linting TypeScript files on filenames with brackets #3183

thisjeremiah opened this issue May 22, 2020 · 4 comments
Labels
bug LSP Any issue relating to LSP or tsserver

Comments

@thisjeremiah
Copy link

Information

VIM version

NVIM v0.5.0-nightly
Build type: Release
LuaJIT 2.0.5

Operating System:

macOS Catalina
10.15.4 (19E287)

What went wrong

Linting does not work for files with square brackets in the name.

This is a problem with some other linting projects:

stylelint/stylelint#4515
lint-staged/lint-staged#676

Reproducing the bug

  1. Create a typescript (react) file script.tsx.
  2. Check that linting works.
  3. Rename the file to [script].tsx.
  4. Observe that linting no longer works.

:ALEInfo

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']

<<>>
1.19.1
<<>>

(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''']

@sudobash1
Copy link
Contributor

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.

@thisjeremiah
Copy link
Author

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.

@thisjeremiah thisjeremiah changed the title No linting files on filenames with brackets No linting TypeScript files on filenames with brackets Jun 19, 2020
@indiesquidge
Copy link

indiesquidge commented Aug 20, 2020

For those looking for the file it can be found here:

function! s:HandleTSServerDiagnostics(response, error_type) abort

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.

@w0rp w0rp added the LSP Any issue relating to LSP or tsserver label Aug 27, 2020
@w0rp w0rp added this to To Do in On the Radar via automation Aug 29, 2020
@w0rp w0rp moved this from To Do to In Progress in On the Radar Sep 5, 2020
@w0rp w0rp closed this as completed in 5bc49d2 Sep 5, 2020
On the Radar automation moved this from In Progress to Done Sep 5, 2020
@w0rp
Copy link
Member

w0rp commented Sep 5, 2020

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.

jsit added a commit to jsit/ale that referenced this issue Apr 19, 2021
* master: (123 commits)
  Add tests for maven.vim file
  Fix grammatical error in doc
  Add maven helper file; use maven wrapper if available instead of global 'mvn' executable
  fix lint, fix variable semantics and update tests
  bibclean: update matchlist reges for bibclean > v2.11.4
  Bump the ALE version to 3.0.0
  Close dense-analysis#2522 - Check pylint on the fly
  Add tests for covering the coming Vint version
  Close dense-analysis#3003 - Show ignored linters in :ALEInfo
  Close dense-analysis#3333 - Add an ALECompletePost event
  Fix a completion error
  Fix typo
  Close dense-analysis#3268 - Implement :ALEImport
  Fix dense-analysis#3183 - Escape filename characters from LSP/tsserver
  Clean up embertemplatelint code
  Fix asciidoc languagetool integration
  Fix dense-analysis#3322 - Apply rename changes correctly
  feat(template-lint): Read from stdin (dense-analysis#2622)
  Fix flake8 cd logic for invalid options
  Add tests for \r removal
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug LSP Any issue relating to LSP or tsserver
Projects
Development

No branches or pull requests

4 participants