Add 7 cross-language code quality recipes#853
Open
jkschneider wants to merge 8 commits intomainfrom
Open
Conversation
New recipes implementing SonarQube RSPEC rules with auto-remediation: - S1066 CollapsibleIfStatements: merge nested ifs with && - S1656 RemoveSelfAssignment: remove x = x dead assignments - S3923 AllBranchesIdentical: collapse if/else where all branches match - S1764 SimplifyRedundantLogicalExpression: simplify x && x to x - S1862 RemoveDuplicateConditions: remove dead duplicate-condition branches - S1871 MergeIdenticalBranches: merge identical branch bodies with || - S4143 RemoveUnconditionalValueOverwrite: remove dead map.put overwrites These are part of a cross-language initiative covering Java, Go, C#, JavaScript, and Python with the same rules in each language.
Contributor
If these recipes are meant to work for all these 5 languages, should we add at least one case for each of the language in each test? |
Resolve conflicts in recipes.csv by keeping all new recipe entries from both branches.
Return directly when a branch has no else, removing the need for the `hasExplicitElse` flag and its follow-up guard.
`SemanticallyEqual` already matches `(a)` with `a`, but returning `b.getLeft()` preserved the surrounding parens. Call `unwrap()` so `(a) && a` simplifies to `a` rather than `(a)`.
Expressions containing method invocations, assignments, increments, or `new` may produce different results across repeated evaluations, so simplifying `iterator.next() && iterator.next()` to `iterator.next()` changes semantics. Only simplify when both operands are side-effect free.
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.
Summary
&&ifstatements should be merged.RSPEC-1066#45ifstatements should be combined - RSPEC-S1066 #734x = xdead assignmentsx && xtox||map.putoverwritesPart of a cross-language initiative implementing the same 9 RSPEC rules across Java, Go, C#, JavaScript, and Python.
Test plan