-
Notifications
You must be signed in to change notification settings - Fork 663
Emit shebangs when printing #1193
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
Conversation
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.
Pull Request Overview
This PR ensures that a file’s shebang (e.g., #!/usr/bin/env node
) is preserved when printing source files.
- Added
GetShebang
helper to extract the shebang line from text - Updated
Printer.emitShebangIfNeeded
to callGetShebang
and emit the line - No tests added for the new functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
internal/scanner/scanner.go | Added GetShebang function to return the shebang line if present |
internal/printer/printer.go | Updated emitShebangIfNeeded to call GetShebang and write the shebang to output |
Comments suppressed due to low confidence (2)
internal/scanner/scanner.go:2263
- There are no unit tests for
GetShebang
or the updatedemitShebangIfNeeded
logic. Adding tests that cover files both with and without a shebang will ensure this feature remains correct.
func GetShebang(text string) string {
internal/printer/printer.go:4341
- Using
writeComment
may prefix the shebang with comment markers (e.g.,//
). To emit the shebang exactly as written (including#!
), consider using a raw write method such asp.write(shebang)
.
p.writeComment(shebang)
Most likely we already have a test, such that running Otherwise, there are printer tests in the printer package you could add to. |
Done. I wasn't sure how to interpret the diff, but after accepting the output files look correct to me. |
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.
Yeah, this looks great to me, thank you!
Fixes: #1038
Ideally I'd like to add a test for this, but I have no clue how this works in this repo.