Skip to content

Request: check for filetype javascript (not just the .js and .jsx extensions) #340

@coolaj86

Description

@coolaj86

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:

  • Respect existing filetype, if any
  • 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:

autocmd FileType javascript,typescript autocmd BufWritePre <buffer> PrettierAsync

2. Set filetype to javascript for js shebangs

Something (possibly vim-ale?) already sets filetype to javascript 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 for deno and zx... but curiously not for bun.

" set filetype to javascript by shebang
autocmd BufRead,BufNewFile * if getline(1) =~ '#!/.*\<\(bun\|deno\|zx\)\>' | setfiletype javascript | endif

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions