Skip to content

x/tools/go/analysis/passes/modernize/cmd/modernize: cannot apply omitzero alternative fix #77019

@andig

Description

@andig

Running

go tool modernize -omitzero -fix ./...

will always result in messages like this:

modernize: omitzero@github.com/evcc-io/evcc/core: ignoring alternative fix "Replace omitempty with omitzero (behavior change)"

While the message itself is clear, I'd like to make the replacement instead of removing the annotation. Cli docs say:

However, some other serialization packages (notably kubebuilder, see
https://book.kubebuilder.io/reference/markers.html) may have their own
interpretation of the json:",omitzero" tag, so removing it may affect
program behavior. For this reason, the omitzero modernizer will not
make changes in any package that contains +kubebuilder annotations.

Replacing omitempty with omitzero is a change in behavior. The
original code would always encode the struct field, whereas the
modified code will omit it if it is a zero-value.

I'm not in a kube environment and it is not clear, how the alternative fix can be enforced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions