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
errors from Prettier overwrite code in vim integration #743
Comments
Just ran into this and I immediately became curious as to how tools like It seems like we should probably write plugins that handle this scenario. Notice that |
This sounds like a terrible experience :( Note that prettier returns a non 0 exit code when there's a syntax error and writes the error on stderr. So the problem is inside of the editor integration. with prettier. |
@vjeux FYI
|
It seems intended, but I'm not sure I understand why: |
If you know the right incantation to get it to work with vi, we should definitely update the instructions for it |
@rauchg The emacs integration pops open a new buffer with the error and it's a nice experience. It points me exactly to where it errored and I usually can fix it quickly, reformat, and the error buffer goes away. The Emacs integration was forked from refmt which derives from other various integrations. It looks like it just checks for a 0 exit status: https://github.com/jlongster/prettier/blob/master/editors/emacs/prettier-js.el#L204. If it's non-zero it shows it in a new buffer. You can also customize where errors are shown, either in the echo area, a new buffer, or in the current buffer. I agree that vim's integration could be a lot better. I'd love for someone to work on more thorough vim integration. |
A workaround for now is to create a script file named stdin=`tee`
formatted=`prettier --stdin <<< "$stdin" 2> /dev/null`
if [ $? -ne 0 ]; then
formatted=$stdin
fi
printf %s "$formatted" Add that file to your $PATH and change the vim setting:
|
@greis - Unfortunately, I can't seem to get this to work. I'm not too familiar with vim/prettier inner workings, would something like |
Fixes prettier#743 Fixes prettier#1191 Fixes prettier#1466
* Add warning about vanilla Vim integration Fixes #743 Fixes #1191 Fixes #1466 * Recommend Neoformat over vanilla Vim integration See #743 See #1191 See #1466 * Remove vanilla Vim integration from README Since it's relatively broken, we don't want to recommend it. See #1568 (comment) This also adds a TOC link for the "Other `autocmd` events" section, which was previously missing.
Hi, despite using Neoformat it seems that the file is still overwritten on errors, at least when using the instructions provided for custom prettier settings. I am using neovim, if that helps. |
@TinyBuilder, can you show your |
We no longer recommend this integration for vim because of this issue. Using neoformat should work fine. |
Very sorry for taking a while, I have had no access to my configuration for the last couple of days. filetype plugin indent on
syntax enable
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set number
set cursorline
set showcmd
colorscheme slate
set colorcolumn=101
highlight ColorColumn ctermbg=235
"Install Vim Plug if not installed.
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -flo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall
endif
call plug#begin('~/.local/share/nvim/plugged')
Plug 'rust-lang/rust.vim'
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'elzr/vim-json'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'w0rp/ale'
Plug 'roxma/nvim-completion-manager'
Plug 'roxma/nvim-cm-tern', {'do': 'npm install'}
Plug 'tpope/vim-fugitive'
Plug 'sbdchd/neoformat'
call plug#end()
let g:ale_linters = { 'javascript': ['eslint'] }
let g:deoplete#enable_at_startup = 1
let g:airline_powerline_fonts = 1
let g:airline_skip_empty_sections = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='durant'
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_flow = 1
autocmd FileType javascript.jsx,javascript setlocal formatprg=prettier\ --stdin\ --single-quote\ --trailing-comma\ all\ --print-width\ 100
autocmd BufWritePre,InsertLeave *.js Neoformat
autocmd BufWritepre,InsertLeave *.jsx Neoformat
autocmd BufWritePre *.js exe "normal! gggqG\<C-o>\<C-o>"
autocmd BufWritePre *.jsx exe "normal! gggqG\<C-o>\<C-o>"
let g:neoformat_try_formatprg = 1 |
This issue has been solved in https://github.com/mitermayer/vim-prettier, when any syntax error occur a quickfix will open with the line and error by default (this behaviour can be updated with configuration). |
I have my editor configured to automatically format the code with Prettier on save.
If there is a syntax error in the code, Prettier will replace the code with its error output.
Is there a recommended way to avoid this?
The text was updated successfully, but these errors were encountered: