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

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

Open
nbauma109 opened this issue Jun 16, 2021 · 2 comments
Assignees
Labels

Comments

@nbauma109
Copy link

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?

@Fabrice-TIERCELIN
Copy link
Collaborator

What is the difference with the existing rule No assignment in if condition (ObsoleteNoAssignmentInIfConditionCleanUp.java)?

@nbauma109
Copy link
Author

Ah ok, I didn't notice that rule "No assignment in if condition (ObsoleteNoAssignmentInIfConditionCleanUp.java)" existed.
So the idea would be to extend the principle to other expressions than if expressions, such as method invocations, array accesses,...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants