_It appears to be a similar issue as in #983. The new setting that solved the problem there, seems not to be used for tslint. But actually this is an issue about prettier and neither eslint nor tslint directly. There should be a generic setting for prettier, that works for all languages which prettier supports._
VIM version
NVIM v0.2.3-616-gdc5362958
Build type: Release
Operating System: WHAT OS WERE YOU USING?
MacOS
Current Filetype: typescript
Available Linters: ['eslint', 'tslint', 'tsserver', 'typecheck']
Enabled Linters: ['eslint', 'tslint', 'tsserver', 'typecheck']
Linter Variables:
let g:ale_typescript_tslint_config_path = ''
let g:ale_typescript_tslint_executable = 'tslint --project tsconfig.json'
let g:ale_typescript_tslint_ignore_empty_files = 0
let g:ale_typescript_tslint_options = '--no-ignore'
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_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {'typescript': ['tslint'], 'javascript': ['eslint']}
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_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_open_list = 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_offset = 1000000
let g:ale_sign_warning = 'ï¹…'
let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK']
let g:ale_warn_about_trailing_whitespace = 1
Command History:
(executable check - success) eslint
(started) ['/usr/local/bin/zsh', '-c', '''eslint'' --no-ignore -f unix --stdin --stdin-filename ''/Users/ohcibi/Documents/Projekte/fdos/foo.ts'' < ''/var/folders/59/2l_s0_xn7dq3_h9rp3b_fd9r0000gn/T/nvimSuqvsw/10/foo.ts''']
(executable check - success) /Users/ohcibi/Documents/Projekte/fdos/node_modules/.bin/tslint
(started) ['/usr/local/bin/zsh', '-c', 'cd ''/Users/ohcibi/Documents/Projekte/fdos'' && /Users/ohcibi/Documents/Projekte/fdos/node_modules/.bin/tslint --format json -c ''/Users/ohcibi/Documents/Projekte/fdos/tslint.json'' ''/var/folders/59/2l_s0_xn7dq3_h9rp3b_fd9r0000gn/T/nvimSuqvsw/11/foo.ts''']
(started) ['/usr/local/bin/zsh', '-c', '/Users/ohcibi/Documents/Projekte/fdos/node_modules/.bin/tsserver']
(executable check - failure) typecheck
(finished - exit code 1) ['/usr/local/bin/zsh', '-c', '''eslint'' --no-ignore -f unix --stdin --stdin-filename ''/Users/ohcibi/Documents/Projekte/fdos/foo.ts'' < ''/var/folders/59/2l_s0_xn7dq3_h9rp3b_fd9r0000gn/T/nvimSuqvsw/12/foo.ts''']
<<<NO OUTPUT RETURNED>>>
(finished - exit code 2) ['/usr/local/bin/zsh', '-c', 'cd ''/Users/ohcibi/Documents/Projekte/fdos'' && /Users/ohcibi/Documents/Projekte/fdos/node_modules/.bin/tslint --format json -c ''/Users/ohcibi/Documents/Projekte/fdos/tslint.json'' ''/var/folders/59/2l_s0_xn7dq3_h9rp3b_fd9r0000gn/T/nvimSuqvsw/13/foo.ts''']
<<<OUTPUT STARTS>>>
[{"endPosition":{"character":13,"line":1,"position":30},"failure":"Replace `'bar'` with `\"bar\"`","fix":{"innerStart":25,"innerLength":5,"innerText":"\"bar\""},"name":"../../../../../var/folders/59/2l_s0_xn7dq3_h9rp3b_fd9r0000gn/T/nvimSuqvsw/13/foo.ts","ruleName":"prettier","ruleSeverity":"ERROR","startPosition":{"character":8,"line":1,"position":25}}]
<<<OUTPUT ENDS>>>
(executable check - failure) typecheck
A file with this content:
foo.ts
function foo() {
alert('bar');
}
and with this .prettierrc file:
singleQuote: true
will still report an error about 'bar' should be replaced with "bar". ALEFix also makes that change whereas tslint --project tsconfig.json foo.ts and prettier foo.ts invoked from the command line fully respect the single quote setting in .prettierrc.
Steps for repeating the bug:
tslint and prettier with npm and enable it in vim settings:tslint-plugin-prettier and tslint-config-prettier and follow instructions (tl;dr: install both packages and add both to the extends clause of tslint.json and add "prettier": true to the rules clause)foo.ts. ALE/prettier now report the single quote when it shouldn't.tslint.json (i.e. add "prettier": [true, { "singleQuote": true }] instead of simply "prettier": true to tslint.json), it works as expected._Just found this project and tried it out and love it because the feedback is so much faster than neomake but I'm seeing this too and can't use this at work because of that :/
If this is still open because it's low priority for you, @w0rp, and you think it might be an easy fix for someone not acquainted with the project who cares more about this specific configuration than you, I'd love for pointers on where to look to start making a change :)
Actually, no need for the pointers. I'll just use prettier as an example since it finds the .prettierrc and see if I can update the tslint fixer https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/w0rp/ale%24+%28tslint%7Cprettier%29
I'll see if I can find enough time to figure this out soon :)
Is there an easy way to disable prettier only on TypeScript until this issue is resolved?
Fixing this will probably involve someone patching tslint itself so we can tell it what the filename when checking a buffer. This is how ESLint works, with the --stdin-filename option.
patching tslint itself
Has anyone filed an issue on https://github.com/palantir/tslint yet? I can do so if not.
Also, bump on any way to disable prettier in the meantime?
Yes. https://github.com/palantir/tslint/issues/1590
I'm working on it now, because nobody else seems to have attempted it yet.
The only way to "disable prettier" for TSLint is to remove the plugin from the TSLint configuration file. Turn TSLint off completely if you can't use it with that plugin.
Got it. Thanks @w0rp!
Hi! Are there updates on this? I'm running on latest version (prettier and tslint), and I'm getting exactly the same behaviour as described in the initial post.
Thanks for all the hard work, ale is an amazing vim plugin.
No, this needs to be fixed in tslint itself. Use the tsserver TSLint plugin instead, which works better.
I was running into the exact same issue.. While this isn't the best solution, explicitly setting the .prettierrc path in tslint.json fixed the issue for me.
example:
{
"extends": [
"tslint:latest",
"tslint-plugin-prettier",
"tslint-config-prettier"
],
"rules": {
"prettier": [true, ".prettierrc"]
}
}
Explicitly setting the .prettierrc path worked for me too, thanks!
Use the tsserver TSLint plugin instead, which works better.
@w0rp tsserver with the plugin does seem to work better for linting but can ale do fixing with it? I get There is no fixer named tsserver. Check :ALEFixSuggest when I try to use it.
I'm currently using tsserver for linting and tslint with the .prettierrc fix above for fixing:
let g:ale_linters = {
\ 'typescript': ['tsserver']
}
let g:ale_fixers = {
\ 'typescript': ['tslint']
}
Also: just want to say thanks for the awesome plugin!
You can't fix files with tsserver. Eventually I'd like to implement "quick fix" support, which will work separately from :ALEFix.
If you guys use coc.nvim with coc-tslint-plugin, it has quick fix and autofix on save. It is a TypeScript TSLint plugin for vim.
Coc is intellisense for vim. coc-tslint-plugin adds tslint as a plugin to typescript.
For autofix on save is similar to vscode where you configure a json file. See :CocConfig.
I'm going to close this issue as TSLint is going away this year. I recommend trying ESLint with recent plugins and tsserver instead.
@CorbanR that's a great solution, thanks!!
Most helpful comment
I was running into the exact same issue.. While this isn't the best solution, explicitly setting the
.prettierrcpath intslint.jsonfixed the issue for me.example: