prettier / prettier/prettier

Ignore semicolon in multiline shebang

Open
#7,562 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang:javascript
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 1.19.1
Playground link

--parser babel

Input:

#!/bin/sh
":" //; exec /usr/bin/env ts-node --transpile-only "$0" "$@"
const ten = 10;

Output:

#!/bin/sh
":"; //; exec /usr/bin/env ts-node --transpile-only "$0" "$@"
const ten = 10;

Expected behavior:

#!/bin/sh
":" //; exec /usr/bin/env ts-node --transpile-only "$0" "$@"
const ten = 10;

Because env is not portable regarding options, A shebang like above is required. The problem is that when Prettier is configured to insert semicolons, the shell is not always happy.

Some shells will print "./example.ts: 2: ./example.ts: //: Permission denied" before executing the script.
There is no good way to add a prettier-ignore there either because not all shells accept "//" comments.

Because of the above reasons, prettier should not insert a semi colon in this case.

Contributor guide

Open the contributing guide

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 provided Playground link and reproduce the semicolon insertion using the shown shell shebang with the Babel parser. Trace the formatter's handling of the multiline shebang and semicolon placement. Done means formatting preserves the expected ":" //; exec ... line without inserting a semicolon between the quoted shell command and //.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.