Skip to content

fix: omit JsonValue type if not used#235

Open
joshhunt wants to merge 1 commit intoopen-feature:mainfrom
joshhunt:fix-jsonvalue-type
Open

fix: omit JsonValue type if not used#235
joshhunt wants to merge 1 commit intoopen-feature:mainfrom
joshhunt:fix-jsonvalue-type

Conversation

@joshhunt
Copy link
Copy Markdown

@joshhunt joshhunt commented Apr 3, 2026

This PR

If you don't use flags with the object type, the React generator will make code that contains errors/warnings that the JsonValue import is unused. This PR fixes that by only including the JsonValue import if it is needed by object flags.

  • fixes the React and Angular generator to omit the JsonValue type if not used
  • fixes the React generator to use the type import type for JsonValue

Signed-off-by: joshhunt <git@joshhunt.dev>
@joshhunt joshhunt force-pushed the fix-jsonvalue-type branch from 2e78c3a to acc5087 Compare April 3, 2026 12:42
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements conditional imports for the JsonValue type in Angular and React generators, ensuring it is only included when 'object' flags are defined. It introduces a HasFlagType method to the Flagset struct and adds corresponding test cases and golden files. Feedback was provided to improve the HasFlagType method by using enum comparisons and adding a nil check for better robustness.

Comment on lines +51 to +58
func (fs *Flagset) HasFlagType(typeName string) bool {
for _, f := range fs.Flags {
if f.Type.String() == typeName {
return true
}
}
return false
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The HasFlagType method currently relies on a direct string comparison with the output of f.Type.String(). This is somewhat fragile as it requires the caller to know the exact string representation used internally (e.g., "object" vs "Object").

It would be more robust and efficient to use the existing ParseFlagType function to convert the input string to a FlagType enum once, and then compare the enums in the loop. This also allows the method to support aliases (like "JSON" for objects) and case-insensitivity, consistent with how flags are parsed from the manifest. Additionally, adding a check for a nil receiver prevents potential panics.

func (fs *Flagset) HasFlagType(typeName string) bool {
	if fs == nil {
		return false
	}
	t, err := ParseFlagType(typeName)
	if err != nil {
		return false
	}
	for _, f := range fs.Flags {
		if f.Type == t {
			return true
		}
	}
	return false
}

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.

1 participant