mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
The framework fundamentally relies on the continuation API added in Java 21 (which is currently internal to the JDK). Continuations allow for call stacks to be saved to the heap and resumed later. The async framework allows command bodies to be written in an imperative style. However, an async command will need to be actively cooperative and periodically call coroutine.yield() in loops to yield control back to the command scheduler to let it process other commands. There are also some other additions like priority levels (as opposed to a blanket yes/no for ignoring incoming commands), factories requiring names be provided for commands, and the scheduler tracking all running commands and not just the highest-level groups. However, those changes aren't unique to an async framework, and could just as easily be used in a traditional command framework.
143 lines
5.6 KiB
XML
143 lines
5.6 KiB
XML
<?xml version="1.0"?>
|
|
<ruleset name="WPILibRuleset"
|
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
|
|
|
<description>PMD Ruleset for WPILib</description>
|
|
|
|
<!-- Generated files -->
|
|
<exclude-pattern>.*/*EntryImpl\.java</exclude-pattern>
|
|
<exclude-pattern>.*/*Subscriber\.java</exclude-pattern>
|
|
<exclude-pattern>.*/Timestamped.*\.java</exclude-pattern>
|
|
<exclude-pattern>.*/units/measure/.*\.java</exclude-pattern>
|
|
|
|
<exclude-pattern>.*/*IntegrationTests.*</exclude-pattern>
|
|
<exclude-pattern>.*/*JNI.*</exclude-pattern>
|
|
<exclude-pattern>.*/math/proto.*</exclude-pattern>
|
|
<exclude-pattern>.*/commands3/proto.*</exclude-pattern>
|
|
|
|
<rule ref="category/java/bestpractices.xml">
|
|
<exclude name="AccessorClassGeneration" />
|
|
<exclude name="AccessorMethodGeneration" />
|
|
<exclude name="AvoidPrintStackTrace" />
|
|
<exclude name="AvoidReassigningCatchVariables" />
|
|
<exclude name="AvoidReassigningParameters" />
|
|
<exclude name="AvoidUsingHardCodedIP" />
|
|
<exclude name="ConstantsInInterface" />
|
|
<exclude name="ExhaustiveSwitchHasDefault" />
|
|
<exclude name="LooseCoupling" />
|
|
<exclude name="NonExhaustiveSwitch" />
|
|
<exclude name="PreserveStackTrace" />
|
|
<exclude name="ReplaceHashtableWithMap" />
|
|
<exclude name="ReplaceVectorWithList" />
|
|
<exclude name="SystemPrintln" />
|
|
<exclude name="UnitTestAssertionsShouldIncludeMessage" />
|
|
<exclude name="UnitTestContainsTooManyAsserts" />
|
|
<exclude name="UnitTestShouldIncludeAssert" />
|
|
<exclude name="UnitTestShouldUseAfterAnnotation" />
|
|
<exclude name="UnitTestShouldUseBeforeAnnotation" />
|
|
<exclude name="UnitTestShouldUseTestAnnotation" />
|
|
<exclude name="UseVarargs" />
|
|
</rule>
|
|
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
|
|
<properties>
|
|
<property name="violationSuppressRegex"
|
|
value=".*'.*Arguments\(\)'.*" />
|
|
</properties>
|
|
</rule>
|
|
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable">
|
|
<properties>
|
|
<property name="violationSuppressXPath" value="//Resource"/>
|
|
</properties>
|
|
</rule>
|
|
|
|
<rule ref="category/java/design.xml">
|
|
<exclude name="AvoidThrowingNewInstanceOfSameException" />
|
|
<exclude name="AvoidThrowingRawExceptionTypes" />
|
|
<exclude name="CognitiveComplexity" />
|
|
<exclude name="CouplingBetweenObjects" />
|
|
<exclude name="CyclomaticComplexity" />
|
|
<exclude name="DataClass" />
|
|
<exclude name="ExceptionAsFlowControl" />
|
|
<exclude name="ExcessiveImports" />
|
|
<exclude name="ExcessiveParameterList" />
|
|
<exclude name="ExcessivePublicCount" />
|
|
<exclude name="GodClass" />
|
|
<exclude name="LawOfDemeter" />
|
|
<exclude name="LoosePackageCoupling" />
|
|
<exclude name="NPathComplexity" />
|
|
<exclude name="NcssCount" />
|
|
<exclude name="TooManyFields" />
|
|
<exclude name="TooManyMethods" />
|
|
</rule>
|
|
|
|
<rule ref="category/java/errorprone.xml">
|
|
<exclude name="AssignmentToNonFinalStatic" />
|
|
<exclude name="AvoidCatchingThrowable" />
|
|
<exclude name="AvoidDuplicateLiterals" />
|
|
<exclude name="AvoidLiteralsInIfCondition" />
|
|
<exclude name="CloseResource" />
|
|
<exclude name="ConstructorCallsOverridableMethod" />
|
|
<exclude name="DoNotTerminateVM" />
|
|
<exclude name="EmptyCatchBlock" />
|
|
<exclude name="FinalizeDoesNotCallSuperFinalize" />
|
|
<exclude name="JUnitSpelling" />
|
|
<exclude name="MissingSerialVersionUID" />
|
|
<exclude name="NonSerializableClass" />
|
|
<exclude name="NullAssignment" />
|
|
</rule>
|
|
|
|
<rule ref="category/java/multithreading.xml">
|
|
<exclude name="AvoidSynchronizedAtMethodLevel" />
|
|
<exclude name="AvoidSynchronizedStatement" />
|
|
<exclude name="AvoidUsingVolatile" />
|
|
<exclude name="DoNotUseThreads" />
|
|
<exclude name="UseConcurrentHashMap" />
|
|
</rule>
|
|
|
|
<rule ref="category/java/performance.xml">
|
|
<exclude name="AvoidInstantiatingObjectsInLoops" />
|
|
<!--
|
|
This rule is in place to save three (!) bytecode instructions when initializing a field to its default value.
|
|
Code that's more readable due to having explicit initial values is more important than reducing class size by a
|
|
few bytes.
|
|
-->
|
|
<exclude name="RedundantFieldInitializer" />
|
|
</rule>
|
|
|
|
<rule name="UnnecessaryCastRule" language="java"
|
|
message="Avoid unnecessary casts"
|
|
class="net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryCastRule"
|
|
externalInfoUrl="https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java" />
|
|
|
|
<!-- Custom Rules -->
|
|
<rule name="UseRequireNonNull"
|
|
message="Use Objects.requireNonNull() instead of throwing a NullPointerException yourself."
|
|
language="java" class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
|
|
<description>Use Objects.requireNonNull() instead of throwing a
|
|
NullPointerException yourself.</description>
|
|
<properties>
|
|
<property name="xpath">
|
|
<value>
|
|
<![CDATA[
|
|
//IfStatement[child::Expression//NullLiteral]/Statement//ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
|
|
]]>
|
|
</value>
|
|
</property>
|
|
</properties>
|
|
<priority>3</priority>
|
|
<example>
|
|
<![CDATA[
|
|
public class Example {
|
|
public Example(Object example) {
|
|
if (example == null) {
|
|
throw new NullPointerException();
|
|
}
|
|
}
|
|
}
|
|
]]>
|
|
</example>
|
|
</rule>
|
|
</ruleset>
|