Skip to content

Golines does not write a file on Macos 15.3.1 go version 1.24.0 #160

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

Open
philip-couling-oxa opened this issue Feb 26, 2025 · 0 comments
Open

Comments

@philip-couling-oxa
Copy link

  • golines version: v0.12.2
  • go version: go1.24.0 darwin/arm64
  • OS: MacOS 15.3.1

I've just tried using golines for the first time and can't get it to make any changes at all. This has lists a file to change but does not change it:

go get -tool github.com/segmentio/golines@latest
go tool golines -w -l .

I can keep re-running golines -w -l . and every time it reports the same file but makes no changes.

Nothing I can do seems to make it actually write a file.

As a temporary work around I tried t run golines --dry-run . | patch But then ...

Related or Unrelated?

Not sure if these are both the same issue or unrelated issues. I'm happy to raise a second issue if you think they are unrelated

I can get the changes golines was trying to make with:

go tool golines --dry-run .

I had hoped to simply apply this output as a patch but there's a catch: I immediately get an error from patch:

patch: **** malformed patch at line 14: @@ -34,7 +37,10 @@

The root cause of this is that the --dry-run output is somehow generating an incorrect patch and the block sizes are incorrect. This causes patch to read the next block header as content of the previous block and get confused.

The number after the comma is supposed to be the number of lines contained in the patch file.
So the example line @@ -34,7 +37,10 @@ tells patch to expect:

  • 7 Lines starting with - plus context lines.
  • 10 lines starting with + plus context lines.

example.go

package main

func ReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
}

func main() {
	ReallyLong(1, 2, 3)
	AnotherReallyLong(1, 2, 3)
}

func AnotherReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
}

Generated diff with golines --dry-run example.go

--- example.go
+++ example.go.shortened
@@ -1,6 +1,10 @@
 package main
-func ReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
+func ReallyLong(
+	aReallyReallyReallyReallyReallyReallyLongName int,
+	anotherReallyReallyReallyReallyReallyReallyLongName int,
+	andAnotheraReallyReallyReallyReallyReallyReallyLongName int,
+) {
 }
 func main() {
@@ -8,6 +12,10 @@
 	AnotherReallyLong(1, 2, 3)
 }
-func AnotherReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
+func AnotherReallyLong(
+	aReallyReallyReallyReallyReallyReallyLongName int,
+	anotherReallyReallyReallyReallyReallyReallyLongName int,
+	andAnotheraReallyReallyReallyReallyReallyReallyLongName int,
+) {
 }

The patch should have been this:

--- example.go
+++ example.go
@@ -1,4 +1,8 @@
 package main
-func ReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
+func ReallyLong(
+	aReallyReallyReallyReallyReallyReallyLongName int,
+	anotherReallyReallyReallyReallyReallyReallyLongName int,
+	andAnotheraReallyReallyReallyReallyReallyReallyLongName int,
+) {
 }
 func main() {
@@ -8,5 +12,9 @@
 	AnotherReallyLong(1, 2, 3)
 }
-func AnotherReallyLong(aReallyReallyReallyReallyReallyReallyLongName int, anotherReallyReallyReallyReallyReallyReallyLongName int, andAnotheraReallyReallyReallyReallyReallyReallyLongName int) {
+func AnotherReallyLong(
+	aReallyReallyReallyReallyReallyReallyLongName int,
+	anotherReallyReallyReallyReallyReallyReallyLongName int,
+	andAnotheraReallyReallyReallyReallyReallyReallyLongName int,
+) {
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant