dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

Code not fixed with Typescript and tslint #3053

Closed hmatheisen closed 4 years ago

hmatheisen commented 4 years ago

Information

VIM version

NVIM v0.4.3 Build type: Release

Operating System

macOS Catalina Version 10.15.2

What went wrong

:AleFix does not fix the file when using Typescript and tslint, there seem to be something wrong with the quotes in the command array.

Reproducing the bug

  1. Write unordered imports in a Typescript file:
import VisualRecognitionV4 from 'ibm-watson/visual-recognition/v4';
import { IamAuthenticator } from 'ibm-watson/auth';
  1. Try to fix it:

Run :AleFix

:ALEInfo

 Current Filetype: typescript
Available Linters: ['eslint', 'standard', 'tslint', 'tsserver', 'typecheck', 'xo']
  Enabled Linters: ['tslint']
 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
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
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': ['tslint'], '*': ['trim_whitespace'], 'javascript': ['eslint']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
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 = {'typescript': ['tslint'], 'javascript': ['eslint']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
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 = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
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/henrymatheisen/Documents/IBM/Projets/DiceNode/node_modules/.bin/tslint
(finished - exit code 2) ['/usr/local/bin/bash', '-c', 'cd ''/Users/henrymatheisen/Documents/IBM/Projets/DiceNode/src/services'' && ''/Users/henrymatheisen/Documents/IBM/Projets/DiceNode/node_modules/.bin/tslint'' --format json -c ''/Users/henrymatheisen/Documents/IBM/Projets/DiceNode/tslint.json'' ''/var/folders/1f/vnrvwfqd1gd2n30x5b52x8x00000gn/T/nvimZ1ItQO/3/detection.ts''']

<<<OUTPUT STARTS>>>
[{"endPosition":{"character":51,"line":1,"position":119},"failure":"Import sources within a group must be alphabetized.","fix":[{"innerStart":0,"innerLength":120,"innerText":"import { IamAuthenticator } from 'ibm-watson/auth';\nimport VisualRecognitionV4 from 'ibm-watson/visual-recognition/v4';\n"}],"name":"../../../../../../../../var/folders/1f/vnrvwfqd1gd2n30x5b52x8x00000gn/T/nvimZ1ItQO/3/detection.ts","ruleName":"ordered-imports","ruleSeverity":"ERROR","startPosition":{"character":0,"line":1,"position":68}}]
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/usr/local/bin/bash', '-c', '''/Users/henrymatheisen/Documents/IBM/Projets/DiceNode/node_modules/.bin/tslint'' -c ''/Users/henrymatheisen/Documents/IBM/Projets/DiceNode/tslint.json'' --fix ''/var/folders/1f/vnrvwfqd1gd2n30x5b52x8x00000gn/T/nvimZ1ItQO/4/detection.ts''']
acro5piano commented 4 years ago

As TSLint cannot accept input from stdin, I think the feature isn't be implemented in Ale. See https://github.com/palantir/tslint/issues/1590

And TSLint is deprecated now, so the best solution is to switch to ESLint + TypeScript.

As a workaround, I define and use the following command:

command! TSLint !yarn tslint --fix %
w0rp commented 4 years ago

I recommend upgrading to ESLint and @typescript-eslint, which replace TSLint. I use the combination of the two all the time at work.