You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set filetype to javascript if shebang is bun, deno, node, or zx
What is the current/expected behavior?
Presently must end in .js or .jsx in order to match for formatting.
1. Respect existing filetype
I have a very minimal config and I believe that vim-ale is already setting filetype to javascript - such as when the shebang looks like #!/usr/bin/env node or #!/usr/bin/node --debug, etc.
Update: It seems that adding this line to my ~/.vimrc causes this to function as intended:
I think vim-ale may be setting the filetype to javascript based on shebang already.
I put this in my local vim-prettier config at ~/.vim/plugins/prettier.vim (which is sourced from ~/.vimrc):
augroup RunPrettierByFiletype
" run if the filetype is detected as javascript or typescript autocmd FileType javascript,typescript autocmd BufWritePre <buffer> PrettierAsyncaugroup END
Now prettier runs when shebangs for node, deno, or zx, but strangely not bun.
I'm not sure where to look to debug that. I searched in ~/.vim/ for deno as I thought that would be the most unique, but I can't seem to find anywhere that it does shebang detection for it.
coolaj86
changed the title
Request: check shebang when setting filetype (or how to set local config such)
Request: check for filetype javascript (not just the .js and .jsx extensions)
Mar 6, 2023
Easier to explain in code
See https://github.com/prettier/vim-prettier/pull/341/files?diff=unified&w=1.
Feature Request
Do you want to request a feature or report a bug?
Requesting two related features:
filetype
, if anyfiletype
tojavascript
if shebang isbun
,deno
,node
, orzx
What is the current/expected behavior?
Presently must end in
.js
or.jsx
in order to match for formatting.1. Respect existing
filetype
I have a very minimal config and I believe that
vim-ale
is already settingfiletype
tojavascript
- such as when the shebang looks like#!/usr/bin/env node
or#!/usr/bin/node --debug
, etc.Update: It seems that adding this line to my
~/.vimrc
causes this to function as intended:2. Set filetype to javascript for js shebangs
Something (possibly
vim-ale
?) already sets filetype tojavascript
when the shebang matches node, such as:#!/usr/bin/env node
#!/usr/local/bin/node --debug
But there are a number of other popular js runtimes that should be detected as JS as well, such as:
#!/usr/bin/env bun
#!/usr/bin/env zx
#!/usr/bin/env deno
When I add this line to my
~/.vimrc
I almost get the expected behavior. It then works as described fordeno
andzx
... but curiously not forbun
.What version of
vim-prettier
are you using - (output of:PrettierVersion
) ?1.0.0-beta
What version of
prettier
are you using - (output of:PrettierCliVersion
) ?3.8.4
What is your
prettier
executable path - (output of:PrettierCliPath
) ?~/.local/opt/node/bin/prettier
Did this work in previous versions of vim-prettier and/or prettier ?
No.
The text was updated successfully, but these errors were encountered: