-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Pass entire text through formatWithShebang() to format() #1718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass entire text through formatWithShebang() to format() #1718
Conversation
That way, we won't have to do any arithmetic on range and cursor locations when there is a shebang. See here for details: prettier#1637 (comment) This required changing comment printing such that comments that are actually shebangs are just ignored.
src/comments.js
Outdated
@@ -801,6 +801,9 @@ function printComment(commentPath) { | |||
return "/*" + comment.value + "*/"; | |||
case "CommentLine": | |||
case "Line": | |||
// Don't print the shebang, it's taken care of in index.js | |||
if (options.originalText.slice(util.locStart(comment)).startsWith("#!")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add {} :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, i'll also add an eslint rule in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome :)
Oh nice! We used to have this crazy setup because the parsers threw syntax errors with shebang. Glad to know they are now handling it :) Feel free to merge once you address my small nit |
Ah, that's neat to know. Ideally, we could handle actually printing the shebang in |
Now we handle actually printing the shebang in `printComment`, rather than lopping it off beforehand and reattaching it afterward, as suggested in prettier#1718 (comment)
* Add shebang comment nodes to Flow/TypeScript ASTs Now we handle actually printing the shebang in `printComment`, rather than lopping it off beforehand and reattaching it afterward, as suggested in #1718 (comment) * Dedupe AST shebang-insertion code into helper function
That way, we won't have to do any arithmetic on range and cursor locations
when there is a shebang. See here for details:
#1637 (comment)
This required changing comment printing such that comments that are
actually shebangs are just ignored.