Implicit type conversion
Reports implicit conversions between the predefined XPath-types STRING
, NUMBER
, BOOLEAN
, and NODESET
. Helps to write XSLT scripts that are more expressive about types and prevents subtle bugs:
Example:
is not the same as
The first test checks whether the element "foo" exists (count(foo) > 0)
; the latter one however is only true if the element actually contains any text (string-length(foo) > 0
). Suggests making the type conversion more explicit.
Use the following options to configure the inspection:
Enable or disable implicit conversions between certain types
Always report explicit conversions that do not result in the actually expected type, for example,
<xsl:if test="number(foo)" />
Ignore conversion from
NODESET
toBOOLEAN
by using thestring()
function as a shortcut for writingstring-length() > 0
.
Inspection options
Option | Type | Default |
---|---|---|
To STRING | Group | None |
From NODESET | Checkbox | false |
From NUMBER | Checkbox | false |
From BOOLEAN | Checkbox | true |
To NUMBER | Group | None |
From NODESET | Checkbox | true |
From STRING | Checkbox | true |
From BOOLEAN | Checkbox | true |
To BOOLEAN | Group | None |
From NODESET | Checkbox | false |
From STRING | Checkbox | true |
From NUMBER | Checkbox | true |
Separator | None | |
Always flag explicit conversion to unexpected type | Checkbox | true |
Ignore conversion of NODESET to BOOLEAN by string()-conversion | Checkbox | true |
Inspection Details | |
---|---|
Available in: | AppCode 2023.3, CLion 2023.3, DataGrip 2023.3, IntelliJ IDEA 2023.3, JetBrains Rider 2023.1, PhpStorm 2023.3, Qodana for .NET 2023.1, Qodana for JVM 2023.3, Qodana for PHP 2023.3 |
Plugin: | XPathView + XSLT, 233.SNAPSHOT |