Infer file type for CLI Javascript files #5122
Labels
area:api
Issues with Prettier's Application Programming Interface
locked-due-to-inactivity
Please open a new issue and fill out the template instead of commenting.
status:has pr
Issues with an accompanying pull request. These issues will probably be fixed soon!
type:enhancement
A potential new feature to be added, or an improvement to how we print something
Milestone
Environments:
Steps to reproduce:
where
bin/clean
is a Javascript CLI script.Actual behavior:
Suggested behavior:
I’m guessing that Prettier infers file types from file extension. However, CLI scripts often aren’t given any extensions. It might be fairly easy to infer the type by reading the first line of such files and checking if it’s a common hashbang string, e.g. something like
Alternatively, if this is deemed unsafe, perhaps (somewhat less conveniently) the existing pragma could be augmented to accept an optional parameter indicating file type.
Not as convenient, and requires scanning more of the file than just the hashbang line to infer type, but if the former proposal is unsafe in some edge case I’m not thinking of (sufficiently common not to be relegated to
.prettierignore
), it would at last provide a way to opt in.The text was updated successfully, but these errors were encountered: