Add fixer for prefer-equals-comparison rule#1790
Merged
charlieegan3 merged 3 commits intoopen-policy-agent:mainfrom Dec 8, 2025
Merged
Conversation
6242c6e to
068313e
Compare
charlieegan3
reviewed
Dec 4, 2025
| return | ||
| } | ||
|
|
||
| if tc.fixExpected && fixResults[0].Contents != tc.contentAfterFix { |
Contributor
There was a problem hiding this comment.
You might want to look into using cmp.Diff, that can be helpful for comparing strings. we use it in some other tests.
charlieegan3
reviewed
Dec 4, 2025
| Filename: "test.rego", | ||
| Contents: "package test\n\nlong := true\n\nlonger = true\nlongest = false\n", | ||
| }, | ||
| contentAfterFix: "package test\n\nlong := true\n\nlonger == true\nlongest == false\n", |
Contributor
There was a problem hiding this comment.
I think for some of these tests we might use a raw string instead.
Suggested change
| contentAfterFix: "package test\n\nlong := true\n\nlonger == true\nlongest == false\n", | |
| contentAfterFix: `package test | |
| long := true | |
| longer == true | |
| longest == false | |
| `, |
charlieegan3
reviewed
Dec 4, 2025
| &NoWhitespaceComment{}, | ||
| &DirectoryPackageMismatch{}, | ||
| &NonRawRegexPattern{}, | ||
| &PreferEqualsComparison{}, |
Contributor
There was a problem hiding this comment.
Have you run
go run main.go lint foo/wow.rego
go run main.go fix --force foo/wow.rego
?
There seems to be a slight difference in how the locations are matched which is causing the fix not to fire.
Contributor
Author
There was a problem hiding this comment.
Gotcha, addressed! Wondering how we feel about updating the rule itself to provide the exact column location of the violation 🤔, the use-assignment-operator rule does something like that it looks like.
Signed-off-by: Sean Ledford <s_ledford@apple.com>
Signed-off-by: Sean Ledford <s_ledford@apple.com>
Signed-off-by: Sean Ledford <s_ledford@apple.com>
068313e to
c24c127
Compare
charlieegan3
approved these changes
Dec 8, 2025
Contributor
charlieegan3
left a comment
There was a problem hiding this comment.
Looks good to me Sean! thanks for this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR to add fixer for the prefer-equals-comparison rule, as well as adequate coverage and docs updates. Done to address issue #1734.