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

WIP: detect js by shebang and run by filetype #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ftdetect/javascript.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
augroup PrettierFileDetect
autocmd BufNewFile,BufReadPost *.js,*jsx setfiletype javascript
autocmd BufRead,BufNewFile * if getline(1) =~ '#!/.*\<\(bun\|deno\|node\|zx\)\>' | setfiletype javascript | endif
augroup end
5 changes: 3 additions & 2 deletions plugin/prettier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let g:prettier#config#arrow_parens = get(g:,'prettier#config#arrow_parens', 'alw

" Define the flavor of line endings
" lf|crlf|cr|all
" defaut: 'lf'
" defaut: 'lf'
let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf')

" Print trailing commas wherever possible when multi-line.
Expand Down Expand Up @@ -156,7 +156,7 @@ command! -nargs=? -range=% PrettierCliPath call prettier#PrettierCliPath()
" sends selected text to prettier cli for formatting
command! -nargs=? -range=% PrettierFragment call prettier#Prettier(g:prettier#exec_cmd_async, <line1>, <line2>, 0)

" sends entire buffer to prettier cli but format just selection
" sends entire buffer to prettier cli but format just selection
command! -nargs=? -range=% PrettierPartial call prettier#Prettier(g:prettier#exec_cmd_async, <line1>, <line2>, 1)

" map command
Expand All @@ -175,4 +175,5 @@ nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR>
augroup Prettier
autocmd!
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.gql,*.markdown,*.md,*.mdown,*.mkd,*.mkdn,*.mdx,*.vue,*.svelte,*.yml,*.yaml,*.html,*.php,*.rb,*.ruby,*.xml noautocmd call prettier#Autoformat()
autocmd FileType javascript,typescript noautocmd BufWritePre <buffer> call prettier#Autoformat()
augroup end