Skip to content

Add HideName option to printer#33

Merged
alecthomas merged 1 commit intoalecthomas:masterfrom
LeonHuston:ignore-struct-field-by-name
Jun 5, 2025
Merged

Add HideName option to printer#33
alecthomas merged 1 commit intoalecthomas:masterfrom
LeonHuston:ignore-struct-field-by-name

Conversation

@LeonHuston
Copy link
Copy Markdown
Contributor

I have run into a situation where we are using assert to compare some structs, however some of these structs have some fields we don't care about but the same type as one of the fields we are directly trying to compare. This means the existing Hide option does not work because it will exclude everything.

This PR adds a slightly alternative option HideName which will hide all struct fields matching that given name, i've kept it at struct names for now but it could be extended to map keys too if we so wished. Included a test similar to the existing ones, but if you want more let me know :)

repr.go Outdated
}
}

func HideName(name string) Option {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the idea, but can you rename this to HideField or something similar, as "name" is a bit ambiguous - it could be field name or type name.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you write a doc comment please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, ive done this now :)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Also, NZ represent! :)

@LeonHuston LeonHuston force-pushed the ignore-struct-field-by-name branch from 10e4ceb to 66daa83 Compare June 5, 2025 03:47
@alecthomas alecthomas merged commit 21b2102 into alecthomas:master Jun 5, 2025
2 checks passed
@LeonHuston LeonHuston deleted the ignore-struct-field-by-name branch July 29, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants