Skip to content

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

@philip-couling-oxa

Description

@philip-couling-oxa
  • 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,
+) {
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions