All Downloads are FREE. Search and download functionalities are using the official Maven repository.

category.swift.errorprone.xml Maven / Gradle / Ivy

<?xml version="1.0" encoding="UTF-8"?>

<ruleset name="Error Prone"
         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>
        Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
    </description>

    <rule name="ForceCast"
          language="swift"
          since="7.0.0"
          message="Force casts should be avoided."
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_swift_errorprone.html#forcecast">
        <description>
            Force casts should be avoided. This may lead to a crash if it's not used carefully.
            For example assuming a JSON property has a given type, or your reused Cell has a certain contract.
            Consider using conditional casting and handling the resulting optional.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
//TypeCastingOperator[T-as and T-bang]
]]>
                </value>
            </property>
        </properties>
        <example>
            <![CDATA[
NSNumber() as! Int // violation, force casting

NSNumber() as? Int // no violation
]]>
        </example>
    </rule>

    <rule name="ForceTry"
          language="swift"
          since="7.0.0"
          message="Force tries should be avoided."
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_swift_errorprone.html#forcetry">
        <description>
            Force tries should be avoided. If the code being wrapped happens to raise and exception, our application will crash.
            Consider using a conditional try and handling the resulting optional, or wrapping the try statement in a do-catch block.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//TryOperator[T-bang]
]]>
                </value>
            </property>
        </properties>
        <example>
            <![CDATA[
let x = try! someThrowingFunction() // violation, force trying

let x = try? someThrowingFunction() // no violation
]]>
        </example>
    </rule>
</ruleset>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy