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

Autoformat on save not working for .ts and .tsx files. #280

Open
solidiquis opened this issue Jan 24, 2021 · 6 comments
Open

Autoformat on save not working for .ts and .tsx files. #280

solidiquis opened this issue Jan 24, 2021 · 6 comments

Comments

@solidiquis
Copy link

First of all, I really appreciate all the hard-work that went into this amazing plugin, as it has made my life at work tremendously easier.

Issue: Autosave works just fine on .js files, but not .ts and .tsx files.

Here are some of my configurations from my .vimrc:

call plug#begin('~/.vim/plugged')

    " TypeScript
    Plug 'leafgarland/typescript-vim'

    " CoffeeScript
    Plug 'kchmck/vim-coffee-script'
    
    " JavaScript
    Plug 'pangloss/vim-javascript'
    Plug 'maxmellon/vim-jsx-pretty'

    " Prettifier
    Plug 'prettier/vim-prettier', {
      \ 'do': 'yarn install',
      \ 'for': ['javascript', 'typescript'] }
call plug#end()


" vim-prettier
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0

Manually calling the command :Prettier works just fine, but unfortunately I can't get that to run automatically on save. Any ideas?

@solidiquis
Copy link
Author

For anyone else experiencing this issue, here is my hacky fix:
autocmd BufWritePre *.tsx,*.ts Prettier

@yzia2000
Copy link
Contributor

yzia2000 commented Feb 1, 2021

 Plug 'prettier/vim-prettier', {
      \ 'do': 'yarn install',
      \ 'for': ['javascript', 'typescript', 'typescriptreact', 'javascriptreact'] }

I think you also need to include typescriptreact and javascriptreact in your plug begin. You might need to reinstall vim-prettier to install these missing plugins

@pdfrod
Copy link

pdfrod commented Mar 4, 2021

I confirm that adding javascriptreact and typescriptreact solved the problem for me.

Was this changed recently? Because I never had those before and .tsx always worked fine for me.

Maybe this should be mentioned in the documentation; I was pulling my hair out trying to figure out why it stopped working.

@bwilytsch
Copy link

I confirm that adding javascriptreact and typescriptreact solved the problem for me.

Was this changed recently? Because I never had those before and .tsx always worked fine for me.

Maybe this should be mentioned in the documentation; I was pulling my hair out trying to figure out why it stopped working.

Worked like a charm. Thank you!

@yzia2000
Copy link
Contributor

yzia2000 commented Feb 2, 2022

Maybe we can close this issue then?

@pdfrod
Copy link

pdfrod commented Feb 3, 2022

The VSCode integration repo has a helpful list of supported languages. Can we add something similar to vim-prettier's documentation? As it is, it's not obvious at all how to make it work for .jsx / .tsx files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants