segmentio / golines

A golang formatter that fixes long lines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backslashes being removed from struct tag

thijsheijden opened this issue · comments

I have the following struct tag: jsonschema:"title=Title,minLength=1,maxLength=40,pattern=^[^\\-<>%{}\\[\\]&#\\\\\\\"]+$", and upon running golines ${file} -w -m 120 using the Run on Save extension in VSCode, the tag is changed into jsonschema:"title=title=Title,maxLength=40,pattern=^[^\-<>%{}\[\]&#\\\"]+$", turning it into an invalid struct tag.

To reproduce the bug, run golines on this file and notice how “pattern” changes.

package main

import "fmt"

type foo struct {
	Name string `jsonschema:"pattern=^[^\\-<>%{}\\[\\]&#\\\\\\\"]+$"`
}

func main() {
	// The below forces golines to rewrite the file and in doing so it changes the foo.Name field's "pattern"
	aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa := 1
	bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb := 1
	if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb == 2 {
		fmt.Println("true")
	}
}

Even if the regular expression is invalid, the tool should not try to change it.