Skip to main content

Command Palette

Search for a command to run...

SonarLint: Replace if-then-else statement by single return statement.

Updated
1 min read
SonarLint: Replace if-then-else statement by single return statement.
S

I love learning about technology and sharing that with others

This is the most common issue you will see while fixing the sonarQube reported issues.

here we are returning true and false based on the condition.

Non Compliant Code

 private boolean isTextField(CustomField field) {
        if (field.getCustomFieldType().getKey().equals("com.atlassian.jira.")) {
            return true;
        }
        return false;
}

Compliant Code

Just return the comparison of the string whether it is true or false.

 private boolean isTextField(CustomField field) {        
        return field.getCustomFieldType().getKey().equals("com.atlassian.jira.") ;
    }

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)