Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support allowlisting via struct literal level comment rather than global config #69

Closed
navijation opened this issue Jul 30, 2023 · 0 comments

Comments

@navijation
Copy link
Contributor

navijation commented Jul 30, 2023

Similar to #37, but at the level of struct literals rather than struct definitions.

The use case: ensuring that "type mapper" functions are properly updated when the destination type gets updated. For example

type InternalStatement struct {
	Balance   int
	StartDate time.Time
	EndDate   time.Time
}

type ExternalStatement struct {
	Balance   money.Amount `json:"balance"`
	StartDate string       `json:"start_date"`
	EndDate   string       `json:"end_date"`
}

func ToExternalStatement(statement *InternalStatement) *ExternalStatement {
	//exhaustruct:enforce
	return &ExternalStatement{
		Balance:   money.FromCents(statement.Balance),
		StartDate: formatMonthDay(statement.StartDate),
		EndDate:   formatMonthDay(statement.EndDate),
	}
}

If the external statement acquires a new field such as "overdue balance", the analyzer will catch if the mapper has not been updated to populate this new field. However, it is might not necessary for every external statement instantiation to require every field be populated.

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

No branches or pull requests

1 participant