Skip to content

Add 7 cross-language code quality recipes#853

Merged
steve-aom-elliott merged 11 commits into
mainfrom
more-csa
Jun 26, 2026
Merged

Add 7 cross-language code quality recipes#853
steve-aom-elliott merged 11 commits into
mainfrom
more-csa

Conversation

@jkschneider

@jkschneider jkschneider commented Apr 9, 2026

Copy link
Copy Markdown
Member

Summary

Part of a cross-language initiative implementing the same 9 RSPEC rules across Java, Go, C#, JavaScript, and Python.

Test plan

  • All 7 new recipe test classes pass (40 tests)
  • Full existing test suite passes with no regressions

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.
@greg-at-moderne

Copy link
Copy Markdown
Contributor

cross-language initiative

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.
# Conflicts:
#	src/main/resources/META-INF/rewrite/recipes.csv
}

@Test
void mergeNonConsecutiveIdenticalBranches() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor thing that they are technically "consecutive", just not starting from the initial if

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Jun 25, 2026
@steve-aom-elliott steve-aom-elliott merged commit 8674121 into main Jun 26, 2026
1 check passed
@steve-aom-elliott steve-aom-elliott deleted the more-csa branch June 26, 2026 13:52
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Collapsible if statements should be merged. RSPEC-1066

4 participants