prettier / prettier/vim-prettier

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

Open
#340 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vim Script
Stars
1.8k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the plugin's filetype matching and BufRead/BufNewFile handling; the issue provides no source file or test entry point. Compare detection of node with bun, deno, and zx, and verify that existing javascript and typescript filetypes are respected. Done means JavaScript formatting is selected for the listed shebangs without overriding an existing filetype.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, vim
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.