<?xml version="1.0"?>
<ruleset name="JOSM ruleset"
    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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

  <description>JOSM PMD ruleset</description>
  <!-- Generated files -->
  <exclude-pattern>.*/org/openstreetmap/josm/gui/mappaint/mapcss/parsergen/.*</exclude-pattern>

  <rule ref="category/java/bestpractices.xml">
    <exclude name="ArrayIsStoredDirectly"/>
    <exclude name="AvoidPrintStackTrace"/>
    <exclude name="AvoidReassigningLoopVariables"/>
    <exclude name="AvoidReassigningParameters"/>
    <exclude name="AvoidStringBufferField"/>
    <exclude name="ConstantsInInterface"/>
    <exclude name="GuardLogStatement"/>
    <exclude name="JUnit4TestShouldUseTestAnnotation" reason="False positive in src/org/openstreetmap/josm/data/validation/Test.java"/>
    <exclude name="LiteralsFirstInComparisons" reason="Introduced in 6.24, some positives in source code at this time. Replaces PositionLiteralsFirstInComparisons."/>
    <exclude name="LooseCoupling"/>
    <exclude name="MethodReturnsInternalArray"/>
    <exclude name="OneDeclarationPerLine"/>
    <exclude name="ReplaceHashtableWithMap"/>
    <exclude name="SwitchStmtsShouldHaveDefault"/>
    <exclude name="SystemPrintln"/>
    <exclude name="UnusedAssignment" reason="Introduced in 6.26, some number of positives in source code at this time"/>
    <exclude name="UnusedPrivateMethod" reason="Broken since PMD 6.33, see https://github.com/pmd/pmd/issues/3468"/>
    <exclude name="UnusedPrivateField" reason="Broken in 7.2.x"/>
    <exclude name="UseVarargs"/>
  </rule>
  <rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach">
    <properties>
      <!-- The list is expanded during iteration -->
      <property name="violationSuppressXPath" value="//ClassDeclaration[@SimpleName='PurgeCommand']/ClassBody/MethodDeclaration[@Name='build']/Block/IfStatement/Block/ForStatement/InfixExpression/MethodCall/VariableAccess[@Name='relLst']"/>
    </properties>
  </rule>
  <rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP">
    <properties>
      <property name="violationSuppressXPath" value="//ClassDeclaration[@SimpleName='DefaultProxySelector' or @SimpleName='RemoteControl']"/>
    </properties>
  </rule>
  <rule ref="category/java/codestyle.xml">
    <exclude name="AtLeastOneConstructor"/>
    <exclude name="BooleanGetMethodName"/>
    <exclude name="CallSuperInConstructor"/>
    <exclude name="ClassNamingConventions"/>
    <exclude name="CommentDefaultAccessModifier"/>
    <exclude name="ConfusingTernary"/>
    <exclude name="ControlStatementBraces"/>
    <!-- EmptyControlStatement is not configurable, so the behavior of the old excludes of EmptyIfStmt/EmptyWhileStmt (errorprone.xml) while getting new functionality cannot be done -->
    <exclude name="EmptyControlStatement"/>
    <exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/>
    <exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
    <exclude name="FieldNamingConventions"/>
    <exclude name="LinguisticNaming"/>
    <exclude name="LocalVariableCouldBeFinal"/>
    <exclude name="LongVariable"/>
    <exclude name="MethodArgumentCouldBeFinal"/>
    <exclude name="MethodNamingConventions"/>
    <exclude name="NoPackage"/>
    <exclude name="OnlyOneReturn"/>
    <exclude name="PrematureDeclaration"/>
    <exclude name="ShortClassName"/>
    <exclude name="ShortMethodName"/>
    <exclude name="ShortVariable"/>
    <exclude name="TooManyStaticImports"/>
    <exclude name="UnnecessaryCast" reason="Introduced in 6.24, some positives in source code at this time"/>
    <exclude name="UnnecessaryConstructor"/>
    <exclude name="UseUnderscoresInNumericLiterals"/>
    <exclude name="UselessParentheses"/>
    <exclude name="UnnecessaryFullyQualifiedName" reason="7.x increased sensitivity (250 new issues), and it now warns on qualified names inside a class, e.g. ClassName.STATIC_VARIABLE. Should probably be fixed in our source code."/>
  </rule>
  <rule ref="category/java/codestyle.xml/ShortMethodName">
    <properties>
      <property name="violationSuppressXPath" value="//MethodDeclaration[@Name='at' or @Name='ht' or @Name='of' or @Name='ok' or @Name='tr']"/>
    </properties>
  </rule>
  <rule ref="category/java/codestyle.xml/MethodNamingConventions">
    <properties>
      <property name="violationSuppressXPath" value="//ClassDeclaration[@SimpleName='Functions' or @SimpleName='PseudoClasses' or @SimpleName='Role' or @SimpleName='TaggingPreset' or @SimpleName='RegionSpecific']"/>
    </properties>
  </rule>
  <rule ref="category/java/codestyle.xml/FieldNamingConventions">
    <properties>
        <property name="enumConstantPattern" value="[A-Za-z][A-Za-z_0-9]*"/>
        <property name="violationSuppressXPath" value="//FieldDeclaration[@Visibility='public']
          | //FieldDeclaration/ModifierList/Annotation[@SimpleName='StructEntry']
          | //FieldDeclaration/ClassType[@SimpleName!='Boolean' and
                                         @SimpleName!='Byte' and
                                         @SimpleName!='Character' and
                                         @SimpleName!='Class' and
                                         @SimpleName!='Double' and
                                         @SimpleName!='Enum' and
                                         @SimpleName!='Float' and
                                         @SimpleName!='Integer' and
                                         @SimpleName!='Long' and
                                         @SimpleName!='Number' and
                                         @SimpleName!='Short' and
                                         @SimpleName!='String' ]"/>
    </properties>
  </rule>
  <rule ref="category/java/codestyle.xml/LongVariable">
    <properties>
        <property name="minimum" value="44"/>
    </properties>
  </rule>
  <rule ref="category/java/design.xml">
    <exclude name="PublicMemberInNonPublicType" reason="Fixing these issues does not improve the code quality, rather the opposite"/>
    <exclude name="AvoidDeeplyNestedIfStmts"/>
    <exclude name="AvoidRethrowingException"/>
    <exclude name="AvoidUncheckedExceptionsInSignatures" reason="We disagree with the reasoning for making this an issue; a strength of Java is verbosity, and warning users about adding `@throws &lt;? extends RuntimeException&gt;` is probably a bad long-term idea."/>
    <exclude name="CognitiveComplexity" reason="Introduced in 6.35, some number of positives in source code at this time"/>
    <exclude name="CollapsibleIfStatements"/>
    <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="ImmutableField"/>
    <exclude name="LawOfDemeter"/>
    <exclude name="LoosePackageCoupling"/>
    <exclude name="MutableStaticState" reason="Introduced in 6.35, some number of positives in source code at this time"/>
    <exclude name="NcssCount"/>
    <exclude name="NPathComplexity"/>
    <exclude name="SignatureDeclareThrowsException"/>
    <exclude name="SimplifiedTernary"/>
    <exclude name="SimplifyBooleanReturns" reason="Increased sensitivity in 7.x; should be fixed in our source code." />
    <exclude name="SimplifyConditional"/>
    <exclude name="SingularField"/>
    <exclude name="SwitchDensity"/>
    <exclude name="TooManyFields"/>
    <exclude name="TooManyMethods"/>
    <exclude name="UseObjectForClearerAPI"/>
    <exclude name="UselessOverridingMethod"/>
    <exclude name="UseUtilityClass"/>
  </rule>
  <rule ref="category/java/design.xml/SignatureDeclareThrowsException">
    <properties>
        <property name="violationSuppressXPath" value="//MethodDeclaration/ModifierList/Annotation[@SimpleName='Override']"/>
        <property name="IgnoreJUnitCompletely" value="true"/>
    </properties>
  </rule>
  <rule ref="category/java/errorprone.xml">
    <exclude name="AvoidCatchingGenericException"/>
    <exclude name="AssignmentInOperand"/>
    <exclude name="AssignmentToNonFinalStatic"/>
    <exclude name="AvoidBranchingStatementAsLastInLoop"/>
    <exclude name="AvoidCatchingNPE"/>
    <exclude name="AvoidDuplicateLiterals"/>
    <exclude name="AvoidFieldNameMatchingMethodName"/>
    <exclude name="AvoidFieldNameMatchingTypeName"/>
    <exclude name="AvoidInstanceofChecksInCatchClause"/>
    <exclude name="AvoidLiteralsInIfCondition"/>
    <exclude name="CompareObjectsWithEquals"/>
    <exclude name="ConfusingArgumentToVarargsMethod" reason="Introduced in 7.1.0; there are false positives in source code at this time."/>
    <exclude name="ConstructorCallsOverridableMethod"/>
    <exclude name="DoNotTerminateVM"/>
    <exclude name="DontImportSun"/>
    <exclude name="ImplicitSwitchFallThrough"/>
    <exclude name="MissingSerialVersionUID"/>
    <exclude name="MissingStaticMethodInNonInstantiatableClass"/>
    <exclude name="NonSerializableClass"/>
    <exclude name="NonStaticInitializer"/>
    <exclude name="NullAssignment"/>
    <exclude name="ReturnEmptyCollectionRatherThanNull" reason="Introduced in 6.37, there are positives in source code at this time"/>
    <exclude name="SimpleDateFormatNeedsLocale"/>
    <exclude name="SingleMethodSingleton"/>
    <exclude name="SingletonClassReturningNewInstance"/>
    <exclude name="TestClassWithoutTestCases"/>
    <exclude name="UseProperClassLoader"/>
  </rule>
  <rule ref="category/java/errorprone.xml/AvoidAccessibilityAlteration">
    <properties>
      <property name="violationSuppressXPath" value="//ClassDeclaration[@SimpleName='ReflectionUtils']"/>
    </properties>
  </rule>
  <rule ref="category/java/performance.xml">
    <exclude name="AvoidInstantiatingObjectsInLoops"/>
    <exclude name="ConsecutiveLiteralAppends"/>
    <exclude name="InefficientEmptyStringCheck"/>
    <exclude name="InsufficientStringBufferDeclaration" reason="PMD 6.40 has a bug where it doesn't properly count appended strings in if statements."/>
    <exclude name="TooFewBranchesForASwitchStatement"/>
    <exclude name="UseArrayListInsteadOfVector"/>
    <exclude name="UselessStringValueOf"/>
    <exclude name="UseStringBufferForStringAppends"/>
  </rule>

</ruleset>
