-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Infer file type for CLI Javascript files #5122
Copy link
Copy link
Closed
Labels
area:apiIssues with Prettier's Application Programming InterfaceIssues with Prettier's Application Programming Interfacelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!
Milestone
Metadata
Metadata
Assignees
Labels
area:apiIssues with Prettier's Application Programming InterfaceIssues with Prettier's Application Programming Interfacelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!
Environments:
Steps to reproduce:
where
bin/cleanis 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.