mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-06 08:22:59 +00:00
Add a couple of errorprone plugins
- Check that common code does not reference client-only classes. - Check that @ForgeOverride really overrides a method in Forge projects.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package cc.tweaked.linter;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class AnnotatedClientClass {
|
||||
public static void doSomething() {
|
||||
}
|
||||
|
||||
public static int field = 0;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package cc.tweaked.linter;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestSideChecker {
|
||||
private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(SideChecker.class, getClass());
|
||||
|
||||
@Test
|
||||
public void textExtendsAnnotated() {
|
||||
compilationHelper
|
||||
.addSourceLines("UsesClientOnly.java", """
|
||||
// BUG: Diagnostic matches: X
|
||||
class UsesClientOnly extends cc.tweaked.linter.AnnotatedClientClass {
|
||||
}
|
||||
""")
|
||||
.expectErrorMessage("X", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportsAnnotated() {
|
||||
compilationHelper
|
||||
.addSourceLines("UsesClientOnly.java", """
|
||||
import cc.tweaked.linter.AnnotatedClientClass;
|
||||
// BUG: Diagnostic matches: X
|
||||
class UsesClientOnly extends AnnotatedClientClass {
|
||||
}
|
||||
""")
|
||||
.expectErrorMessage("X", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textUsesAnnotated() {
|
||||
compilationHelper
|
||||
.addSourceLines("UsesClientOnly.java", """
|
||||
import cc.tweaked.linter.AnnotatedClientClass;
|
||||
class UsesClientOnly {
|
||||
public void f() {
|
||||
// BUG: Diagnostic matches: X
|
||||
AnnotatedClientClass.doSomething();
|
||||
// BUG: Diagnostic matches: Y
|
||||
System.out.println(AnnotatedClientClass.field);
|
||||
// BUG: Diagnostic matches: Z
|
||||
AnnotatedClientClass.field = 0;
|
||||
}
|
||||
}
|
||||
""")
|
||||
.expectErrorMessage("X", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.expectErrorMessage("Y", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.expectErrorMessage("Z", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendsPackage() {
|
||||
compilationHelper
|
||||
.addSourceLines("UsesClientOnly.java", """
|
||||
// BUG: Diagnostic matches: X
|
||||
class UsesClientOnly extends cc.tweaked.linter.client.PackageClientClass {
|
||||
}
|
||||
""")
|
||||
.expectErrorMessage("X", Predicates.containsPattern("Using client-only symbol in common source set"))
|
||||
.doTest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package cc.tweaked.linter.client;
|
||||
|
||||
public class PackageClientClass {
|
||||
}
|
||||
Reference in New Issue
Block a user