Ignore semicolon in multiline shebang
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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