Skip to content

[java] New rule: UnnecessaryBlock #6622

@UncleOwen

Description

@UncleOwen

Also wondering if UnnecessaryBlock should be ported from JS to Java

Originally posted by @zbynek in #6523 (comment)

Proposed Rule Name: UnnecessaryBlock

Proposed Category: Code Style.

Description: A block is unnecessary, if it is

a) not a class body/method body/body of a control statement/initializer block/... AND
b) not used to restrict the scope of a variable.

Code Sample:

public class Foo {
    public boolean bad(Object o) {
        {
            if(obj == null) return false;
        }
        return true;
    }

    public boolean good(Object o) {
        if(obj == null) return false;
        return true;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rule

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions