nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: fatih/gomodifytags
Pull request #62 (2020-05-12 04:05:58)

Fix skipping unexported embedded fields
closes: https://github.com/fatih/gomodifytags/issues/58


Patch:
diff --git a/main.go b/main.go
index c40d601..821a55b 100644
--- a/main.go
+++ b/main.go
@@ -649,11 +649,6 @@ func (c *config) rewrite(node ast.Node, start, end int) (ast.Node, error) {
 						break
 					}
 				}
-
-				// nothing to process, continue with next line
-				if fieldName == "" {
-					continue
-				}
 			}
 
 			// anonymous field
@@ -663,7 +658,14 @@ func (c *config) rewrite(node ast.Node, start, end int) (ast.Node, error) {
 					continue
 				}
 
-				fieldName = ident.Name
+				if !c.skipUnexportedFields {
+					fieldName = ident.Name
+				}
+			}
+
+			// nothing to process, continue with next line
+			if fieldName == "" {
+				continue
 			}
 
 			if f.Tag == nil {


Test patch:
diff --git a/main_test.go b/main_test.go
index bf6204e..452645a 100644
--- a/main_test.go
+++ b/main_test.go
@@ -391,6 +391,16 @@ func TestRewrite(t *testing.T) {
 				skipUnexportedFields: true,
 			},
 		},
+		{
+			file: "skip_embedded",
+			cfg: &config{
+				add:                  []string{"json"},
+				output:               "source",
+				structName:           "StationCreated",
+				transform:            "snakecase",
+				skipUnexportedFields: true,
+			},
+		},
 		{
 			file: "all_structs",
 			cfg: &config{
diff --git a/test-fixtures/skip_embedded.golden b/test-fixtures/skip_embedded.golden
new file mode 100644
index 0000000..318373e
--- /dev/null
+++ b/test-fixtures/skip_embedded.golden
@@ -0,0 +1,21 @@
+package event
+
+import "time"
+
+type StationEvent interface {
+	DomainEvent
+	isStationEvent()
+}
+
+type stationEvent struct{}
+
+func (evt stationEvent) isStationEvent() {}
+
+type StationCreated struct {
+	stationEvent
+	ConnectorID    int                       `json:"connector_id"`
+	MeterStop      int                       `json:"meter_stop"`
+	TransactionID  int32                     `json:"transaction_id"`
+	ChargingCardID identifier.ChargingCardID `json:"charging_card_id"`
+	Timestamp      time.Time                 `json:"timestamp`
+}
diff --git a/test-fixtures/skip_embedded.input b/test-fixtures/skip_embedded.input
new file mode 100644
index 0000000..8623b9f
--- /dev/null
+++ b/test-fixtures/skip_embedded.input
@@ -0,0 +1,21 @@
+package event
+
+import "time"
+
+type StationEvent interface {
+	DomainEvent
+	isStationEvent()
+}
+
+type stationEvent struct{}
+
+func (evt stationEvent) isStationEvent() {}
+
+type StationCreated struct {
+	stationEvent
+	ConnectorID    int
+	MeterStop      int
+	TransactionID  int32
+	ChargingCardID identifier.ChargingCardID
+	Timestamp      time.Time `json:"timestamp`
+}
Repository: fatih/gomodifytags
Pull request #66 (2020-07-05 07:20:57)

Added 'Title Case' to the the list of cases
Code changes for Issue #65 


Patch:
diff --git a/main.go b/main.go
index 821a55b..61f88f3 100644
--- a/main.go
+++ b/main.go
@@ -107,7 +107,7 @@ func realMain() error {
 		flagSkipPrivateFields = flag.Bool("skip-unexported", false, "Skip unexported fields")
 		flagTransform         = flag.String("transform", "snakecase",
 			"Transform adds a transform rule when adding tags."+
-				" Current options: [snakecase, camelcase, lispcase, pascalcase, keep]")
+				" Current options: [snakecase, camelcase, lispcase, pascalcase, keep, titlecase]")
 		flagSort = flag.Bool("sort", false,
 			"Sort sorts the tags in increasing order according to the key name")
 
@@ -392,6 +392,13 @@ func (c *config) addTags(fieldName string, tags *structtag.Tags) (*structtag.Tag
 		name = strings.Join(titled, "")
 	case "keep":
 		name = fieldName
+	case "titlecase":
+		var titled []string
+		for _, s := range splitted {
+			titled = append(titled, strings.Title(s))
+		}
+
+		name = strings.Join(titled, " ")
 	default:
 		unknown = true
 	}


Test patch:
diff --git a/main_test.go b/main_test.go
index 452645a..8c961c2 100644
--- a/main_test.go
+++ b/main_test.go
@@ -410,6 +410,24 @@ func TestRewrite(t *testing.T) {
 				transform: "snakecase",
 			},
 		},
+		{
+			file: "line_titlecase_add",
+			cfg: &config{
+				add:       []string{"json"},
+				output:    "source",
+				line:      "4,6",
+				transform: "titlecase",
+			},
+		},
+		{
+			file: "line_titlecase_add_embedded",
+			cfg: &config{
+				add:       []string{"json"},
+				output:    "source",
+				line:      "4,6",
+				transform: "titlecase",
+			},
+		},
 	}
 
 	for _, ts := range test {
diff --git a/test-fixtures/line_titlecase_add.golden b/test-fixtures/line_titlecase_add.golden
new file mode 100644
index 0000000..81a521a
--- /dev/null
+++ b/test-fixtures/line_titlecase_add.golden
@@ -0,0 +1,7 @@
+package foo
+
+type foo struct {
+	bar       string   `json:"Bar"`
+	MyExample bool     `json:"My Example"`
+	MyAnother []string `json:"My Another"`
+}
diff --git a/test-fixtures/line_titlecase_add.input b/test-fixtures/line_titlecase_add.input
new file mode 100644
index 0000000..77c7967
--- /dev/null
+++ b/test-fixtures/line_titlecase_add.input
@@ -0,0 +1,7 @@
+package foo
+
+type foo struct {
+	bar       string
+	MyExample bool
+	MyAnother []string
+}
diff --git a/test-fixtures/line_titlecase_add_embedded.golden b/test-fixtures/line_titlecase_add_embedded.golden
new file mode 100644
index 0000000..9cc0990
--- /dev/null
+++ b/test-fixtures/line_titlecase_add_embedded.golden
@@ -0,0 +1,7 @@
+package foo
+
+type foo struct {
+	bar       `json:"Bar"`
+	MyExample bool     `json:"My Example"`
+	MyAnother []string `json:"My Another"`
+}
diff --git a/test-fixtures/line_titlecase_add_embedded.input b/test-fixtures/line_titlecase_add_embedded.input
new file mode 100644
index 0000000..a9e3704
--- /dev/null
+++ b/test-fixtures/line_titlecase_add_embedded.input
@@ -0,0 +1,7 @@
+package foo
+
+type foo struct {
+	bar
+	MyExample bool
+	MyAnother []string
+}