Skip to content

Idea of a new rule "Assignment statement rather than assignment in expression" #491

@nbauma109

Description

@nbauma109

This new rule would be the equivalent of the one with increment/decrement inside expression.
https://github.com/JnRouvignac/AutoRefactor/blob/master/plugin/src/main/java/org/autorefactor/jdt/internal/ui/fix/ObsoleteIncrementStatementRatherThanIncrementExpressionCleanUp.java

As you may already know, Sonar raises a warning when assignement is inside an expression.

Example of non-compliant code candidate for refactoring

if ((str = cont.substring(pos1, pos2)).isEmpty()) { 
  //...

Desired refactoring result would be the Sonar-compliant version

str = cont.substring(pos1, pos2);
if (str.isEmpty()) {
  //...

Let me know you thoughts on it.

Would it be complicated to do?

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions