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

analyzer: add options to cover all cases #42

Merged
merged 2 commits into from
Feb 5, 2025
Merged

Conversation

catenacyber
Copy link
Owner

For #39, new version of #41

@alexandear @mmorel-35 @ccoVeille

What do you think of this ?

integer-format
error-format
bool-format
hex-format
string-format
@catenacyber catenacyber mentioned this pull request Jan 30, 2025
@catenacyber
Copy link
Owner Author

I did not have a good command to generate all the test files...

README.md Outdated Show resolved Hide resolved
analyzer/analyzer.go Show resolved Hide resolved
Comment on lines +65 to 75
r.Flags.BoolVar(&n.intFormat.enabled, "integer-format", true, "enable/disable optimization of integer formatting")
r.Flags.BoolVar(&n.intFormat.intConv, "int-conversion", true, "optimizes even if it requires an int or uint type cast")
r.Flags.BoolVar(&n.errFormat.enabled, "error-format", true, "enable/disable optimization of error formatting")
r.Flags.BoolVar(&n.errFormat.errError, "err-error", false, "optimizes into err.Error() even if it is only equivalent for non-nil errors")
r.Flags.BoolVar(&n.errFormat.errorf, "errorf", true, "optimizes fmt.Errorf")
r.Flags.BoolVar(&n.boolFormat, "bool-format", true, "enable/disable optimization of bool formatting")
r.Flags.BoolVar(&n.hexFormat, "hex-format", true, "enable/disable optimization of hex formatting")
r.Flags.BoolVar(&n.strFormat.enabled, "string-format", true, "enable/disable optimization of string formatting")
r.Flags.BoolVar(&n.strFormat.sprintf1, "sprintf1", true, "optimizes fmt.Sprintf with only one argument")
r.Flags.BoolVar(&n.strFormat.strconcat, "strconcat", true, "optimizes into strings concatenation")
r.Flags.BoolVar(&n.fiximports, "fiximports", true, "fix needed imports from other fixes")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
r.Flags.BoolVar(&n.intFormat.enabled, "integer-format", true, "enable/disable optimization of integer formatting")
r.Flags.BoolVar(&n.intFormat.intConv, "int-conversion", true, "optimizes even if it requires an int or uint type cast")
r.Flags.BoolVar(&n.errFormat.enabled, "error-format", true, "enable/disable optimization of error formatting")
r.Flags.BoolVar(&n.errFormat.errError, "err-error", false, "optimizes into err.Error() even if it is only equivalent for non-nil errors")
r.Flags.BoolVar(&n.errFormat.errorf, "errorf", true, "optimizes fmt.Errorf")
r.Flags.BoolVar(&n.boolFormat, "bool-format", true, "enable/disable optimization of bool formatting")
r.Flags.BoolVar(&n.hexFormat, "hex-format", true, "enable/disable optimization of hex formatting")
r.Flags.BoolVar(&n.strFormat.enabled, "string-format", true, "enable/disable optimization of string formatting")
r.Flags.BoolVar(&n.strFormat.sprintf1, "sprintf1", true, "optimizes fmt.Sprintf with only one argument")
r.Flags.BoolVar(&n.strFormat.strconcat, "strconcat", true, "optimizes into strings concatenation")
r.Flags.BoolVar(&n.fiximports, "fiximports", true, "fix needed imports from other fixes")
r.Flags.BoolVar(&n.intFormat.activated, "integer-format", true, "activate/deactivate optimization of integer formatting")
r.Flags.BoolVar(&n.intFormat.intConv, "int-conversion", true, "optimizes even if it requires an int or uint type cast")
r.Flags.BoolVar(&n.errFormat.activated, "error-format", true, "activate/deactivate optimization of error formatting")
r.Flags.BoolVar(&n.errFormat.errError, "err-error", false, "optimizes into err.Error() even if it is only equivalent for non-nil errors")
r.Flags.BoolVar(&n.errFormat.errorf, "errorf", true, "optimizes fmt.Errorf")
r.Flags.BoolVar(&n.boolFormat, "bool-format", true, "activate/deactivate optimization of bool formatting")
r.Flags.BoolVar(&n.hexFormat, "hex-format", true, "activate/deactivate optimization of hex formatting")
r.Flags.BoolVar(&n.strFormat.activated, "string-format", true, "activate/deactivate optimization of string formatting")
r.Flags.BoolVar(&n.strFormat.sprintf1, "sprintf1", true, "optimizes fmt.Sprintf with only one argument")
r.Flags.BoolVar(&n.strFormat.strconcat, "strconcat", true, "optimizes into strings concatenation")
r.Flags.BoolVar(&n.fiximports, "fiximports", true, "fix needed imports from other fixes")

analyzer/analyzer_test.go Outdated Show resolved Hide resolved
analyzer/analyzer_test.go Outdated Show resolved Hide resolved
@catenacyber catenacyber merged commit eff1a84 into main Feb 5, 2025
1 check passed
This was referenced Feb 5, 2025
@ccoVeille
Copy link
Contributor

The code was working as a CLI.

Unfortunately the code used for the testing was incomplete and misleading.

Deactivating a flag such as integer-format should invalidate int-conversion with wasn't the case

Same for string-format

So the tests and golden files that were added were wrong, this is blocking as it prevent the code to be refactored further

The problem is sorted with #44

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