Merge branch 'pmd/7.0.x' into pmd7-junit5-part3

This commit is contained in:
Andreas Dangel
2023-01-10 12:58:51 +01:00
398 changed files with 15202 additions and 3345 deletions

View File

@ -19,7 +19,10 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral
public String getNormalizedImage() {
String image = getImage();
image = image.replaceAll("_", "");
image = normalizeHexIntegerLiteral(image);
image = normalizeBinaryLiteral(image);
image = normalizeOctalLiteral(image);
image = image.replace('e', 'E');
if (image.indexOf('.') == -1 && image.indexOf('E') == -1) {
image = image + ".0";
@ -34,6 +37,20 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral
return image;
}
private String normalizeBinaryLiteral(String image) {
if (image.startsWith("0b") || image.startsWith("0B")) {
return String.valueOf(Integer.parseInt(image.substring(2), 2));
}
return image;
}
private String normalizeOctalLiteral(String image) {
if (image.startsWith("0o") || image.startsWith("0O")) {
return String.valueOf(Integer.parseInt(image.substring(2), 8));
}
return image;
}
public double getNumber() {
return node.getNumber();
}

View File

@ -58,4 +58,17 @@ var hex1 = 0x20;
var hex2 = 0X20;
]]></code>
</test-code>
<test-code>
<description>[javascript] InaccurateNumericLiteral underscore separator notation false positive #4165</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
const value1a = 1_000_000; // number
const value1b = 1_000.12_34; // decimal
const value2 = 0b1010_0001_1000_0101; // binary
const value3 = 0xA0_B0; // hex
const value4 = 9_223_372_036_854_775_807n; // big int
const value5 = 0o1234_5670; // octal
]]></code>
</test-code>
</test-data>