fatih/gomodifytags

Unexported embedded struct with skip-unexported option is still tagged

eduhenke opened this issue · 3 comments

Input:

type stationEvent struct{}

type StationConnectorUnplugged struct {
	stationEvent
	ConnectorID    int
	MeterStop      int
	TransactionID  int32
	ChargingCardID identifier.ChargingCardID
	Timestamp      time.Time `json:"timestamp`
}

Output:

type stationEvent struct{}

type StationConnectorUnplugged struct {
        stationEvent   `json:"stationEvent"`
        ConnectorID    int                       `json:"connectorID"`
        MeterStop      int                       `json:"meterStop"`
        TransactionID  int32                     `json:"transactionID"`
        ChargingCardID identifier.ChargingCardID `json:"chargingCardID"`
        Timestamp      time.Time                 `json:"timestamp`
}

Expected:

type stationEvent struct{}

type StationConnectorUnplugged struct {
        stationEvent
        ConnectorID    int                       `json:"connectorID"`
        MeterStop      int                       `json:"meterStop"`
        TransactionID  int32                     `json:"transactionID"`
        ChargingCardID identifier.ChargingCardID `json:"chargingCardID"`
        Timestamp      time.Time                 `json:"timestamp`
}
fatih commented

Thank you for opening the issue. Can you please give me the command line arguments (that you passed to gomodifytags) with the exact content, including the package name ? That would help me to better test and see the issue.

Sure!

// file.go
package event

type StationEvent interface {
	DomainEvent
	isStationEvent()
}

type stationEvent struct{}

func (evt stationEvent) isStationEvent() {}

type StationCreated struct {
	stationEvent
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Command:

go run github.com/fatih/gomodifytags -file file.go -line 1,100000 -add-tags json -transform camelcase --skip-unexported

Output:

package event

type StationEvent interface {
        DomainEvent
        isStationEvent()
}

type stationEvent struct{}

func (evt stationEvent) isStationEvent() {}

type StationCreated struct {
        stationEvent `json:"stationEvent"`
        ID           int    `json:"id"`
        Name         string `json:"name"`
}
fatih commented

This should be fixed with: #62 I'll merge it in couple of days and cut a new release. Let me know if you still see issues with it.