Variables should not be self-assigned

Java pattern

It is redundant and usually a bug when a variable is assigned to itself.


Apply with the Grit CLI
grit apply no_self_assigned_variables

Optimistically rewrites variable to instance variable when it is not one

BEFORE
class Watermelon {
    private String name;

    public void setName(String name) {
        name = name;
    }
}
AFTER
class Watermelon {
    private String name;

    public void setName(String name) {
        this.name = name;
    }
}

Removes self-assigned instance variables

BEFORE
class Watermelon {
    public void setName(String name) {
        this.name = this.name;
        void method = oranges.map((n) -> { this.orange = this.orange; });
    }
}
AFTER
class Watermelon {
    public void setName(String name) {
        void method = oranges.map((n) -> {  });
    }
}