getgrit / stdlib

The GritQL standard library provides common patterns for refactoring and upgrading code.
https://docs.grit.io/patterns
48 stars 18 forks source link

unused_private_fields removes fields referenced from other fields #207

Closed buerkle closed 4 months ago

buerkle commented 4 months ago

https://github.com/getgrit/stdlib/blob/main/.grit/patterns/java/unused_private_fields.md

Code:

public class Test {

    private static final String HELLO = "Hello, ";
    private static final String WORLD = "World";

    private static final String HELLO_WORLD = HELLO + WORLD;

    public static void main(String[] args) {
        System.out.println(HELLO_WORLD);
    }
}

Command: grit apply unused_private_fields

Output:

public class Test {

    private static final String HELLO_WORLD = HELLO + WORLD;

    public static void main(String[] args) {
        System.out.println(HELLO_WORLD);
    }
}

Same applies to non-static fields

morgante commented 4 months ago

Thanks for the report, fixed here: https://github.com/getgrit/stdlib/pull/208