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

TSLint is ignoring the .prettierrc file #1347

Closed
ohcibi opened this issue Feb 14, 2018 · 16 comments
Closed

TSLint is ignoring the .prettierrc file #1347

ohcibi opened this issue Feb 14, 2018 · 16 comments

Comments

@ohcibi
Copy link

ohcibi commented Feb 14, 2018

Information

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

:ALEInfo


 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

What went wrong

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.

Reproducing the bug

Steps for repeating the bug:

  1. Put files as above in a directory
  2. Install tslint and prettier with npm and enable it in vim settings:
    let g:ale_fixers = {
    \ 'typescript': ['tslint']
    \ }
  3. Configure tslint to pick up prettiers configuration by installing 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)
  4. Open foo.ts. ALE/prettier now report the single quote when it shouldn't.
    Note: When configured in tslint.json (i.e. add "prettier": [true, { "singleQuote": true }] instead of simply "prettier": true to tslint.json), it works as expected.
@w0rp w0rp changed the title ALEFix with Prettier is ignoring the .prettierrc file TSLint is ignoring the .prettierrc file Feb 18, 2018
@ijsnow
Copy link

ijsnow commented Mar 19, 2018

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 :)

@ijsnow
Copy link

ijsnow commented Mar 19, 2018

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 :)

@devth
Copy link

devth commented Mar 20, 2018

Is there an easy way to disable prettier only on TypeScript until this issue is resolved?

@w0rp
Copy link
Member

w0rp commented Mar 20, 2018

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.

@devth
Copy link

devth commented Mar 20, 2018

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?

@w0rp
Copy link
Member

w0rp commented Mar 20, 2018

Yes. palantir/tslint#1590

I'm working on it now, because nobody else seems to have attempted it yet.

@w0rp
Copy link
Member

w0rp commented Mar 20, 2018

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.

@devth
Copy link

devth commented Mar 20, 2018

Got it. Thanks @w0rp!

@bengro
Copy link

bengro commented Sep 7, 2018

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.

@w0rp
Copy link
Member

w0rp commented Sep 9, 2018

No, this needs to be fixed in tslint itself. Use the tsserver TSLint plugin instead, which works better.

bengro added a commit to bengro/vim-config that referenced this issue Sep 9, 2018
Due to a bug in tslint, fixing should happen on the command line. For
linting using tsserver is more robust.

See dense-analysis/ale#1347
@CorbanR
Copy link

CorbanR commented Oct 30, 2018

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"]
  }
}

@tracehelms
Copy link

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!

@w0rp
Copy link
Member

w0rp commented Nov 4, 2018

You can't fix files with tsserver. Eventually I'd like to implement "quick fix" support, which will work separately from :ALEFix.

@dosentmatter
Copy link

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.

@w0rp
Copy link
Member

w0rp commented Jul 30, 2019

I'm going to close this issue as TSLint is going away this year. I recommend trying ESLint with recent plugins and tsserver instead.

@w0rp w0rp closed this as completed Jul 30, 2019
@heisian
Copy link

heisian commented Aug 17, 2019

@CorbanR that's a great solution, thanks!!

tjmw added a commit to tjmw/config that referenced this issue Nov 1, 2019
This was conflicting with prettier and reporting issues which weren’t
consistent with the prettier config. This comment was how I figured
this out: dense-analysis/ale#1347 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants