From 6cda19949a1060733348def9faf6196a59d5aa83 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 12:02:14 +0300 Subject: [PATCH 1/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt | 2 +- .../org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index 81f77ce4e8..04a1c3f6cf 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -108,7 +108,7 @@ class MagicNumberRule(configRules: List) : DiktatRule( companion object { const val IGNORE_TEST = true const val NAME_ID = "aca-magic-number" - val ignoreNumbersList = listOf("-1", "1", "0", "2") + val ignoreNumbersList = listOf("-1", "1", "0", "2", "0U", "1U", "2U", "0L", "1L", "2L", "0UL", "1UL", "2UL") val mapConfiguration = mapOf( "ignoreHashCodeFunction" to true, "ignorePropertyDeclaration" to false, diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt index 22c83a8987..e42d79f793 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt @@ -44,6 +44,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | val b = 128L | val e = 3.4f | val g = 4/3 + | val h = 0U | val f = "qwe\$\{12\}hhe" |} | From 683362ee72c988bb3f6f4966d6c46eda47f3efbf Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 12:05:53 +0300 Subject: [PATCH 2/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index 04a1c3f6cf..4299946738 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -108,7 +108,7 @@ class MagicNumberRule(configRules: List) : DiktatRule( companion object { const val IGNORE_TEST = true const val NAME_ID = "aca-magic-number" - val ignoreNumbersList = listOf("-1", "1", "0", "2", "0U", "1U", "2U", "0L", "1L", "2L", "0UL", "1UL", "2UL") + val ignoreNumbersList = listOf("-1", "1", "0", "2", "0U", "1U", "2U", "-1L", "0L", "1L", "2L", "0UL", "1UL", "2UL") val mapConfiguration = mapOf( "ignoreHashCodeFunction" to true, "ignorePropertyDeclaration" to false, From ea2d05fc9d31bb5218211c8e9cc3e37393245c8e Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 12:24:56 +0300 Subject: [PATCH 3/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt | 3 --- .../ruleset/rules/chapter2/comments/HeaderCommentRule.kt | 1 - .../diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt | 1 - 3 files changed, 5 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt index 2db2dc6d2a..49c99c4288 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt @@ -9,10 +9,7 @@ import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_PATH import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_PREFIX import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_SYMBOLS import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_MISSING -import org.cqfn.diktat.ruleset.rules.DIKTAT_RULE_SET_ID import org.cqfn.diktat.ruleset.rules.DiktatRule -import org.cqfn.diktat.ruleset.rules.chapter2.kdoc.CommentsFormatting -import org.cqfn.diktat.ruleset.rules.chapter2.kdoc.KdocComments import org.cqfn.diktat.ruleset.utils.* import com.pinterest.ktlint.core.ast.ElementType.BLOCK_COMMENT diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt index dee979e02e..a3b0b6ceef 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt @@ -8,7 +8,6 @@ import org.cqfn.diktat.ruleset.constants.Warnings.HEADER_MISSING_OR_WRONG_COPYRI import org.cqfn.diktat.ruleset.constants.Warnings.HEADER_NOT_BEFORE_PACKAGE import org.cqfn.diktat.ruleset.constants.Warnings.HEADER_WRONG_FORMAT import org.cqfn.diktat.ruleset.constants.Warnings.WRONG_COPYRIGHT_YEAR -import org.cqfn.diktat.ruleset.rules.DIKTAT_RULE_SET_ID import org.cqfn.diktat.ruleset.rules.DiktatRule import org.cqfn.diktat.ruleset.utils.copyrightWords import org.cqfn.diktat.ruleset.utils.findChildAfter diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt index 6b7e6e6b59..d9422f0713 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt @@ -7,7 +7,6 @@ import org.cqfn.diktat.ruleset.constants.Warnings.COMMENT_WHITE_SPACE import org.cqfn.diktat.ruleset.constants.Warnings.FIRST_COMMENT_NO_BLANK_LINE import org.cqfn.diktat.ruleset.constants.Warnings.IF_ELSE_COMMENTS import org.cqfn.diktat.ruleset.constants.Warnings.WRONG_NEWLINES_AROUND_KDOC -import org.cqfn.diktat.ruleset.rules.DIKTAT_RULE_SET_ID import org.cqfn.diktat.ruleset.rules.DiktatRule import org.cqfn.diktat.ruleset.utils.* From b969f4c50a923716a651345703bb8efe291a1a16 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 12:44:46 +0300 Subject: [PATCH 4/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index 4299946738..b67528e651 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -120,4 +120,5 @@ class MagicNumberRule(configRules: List) : DiktatRule( "ignoreRanges" to false, "ignoreExtensionFunctions" to false) } + } From 05aaba458426ee3c956334c948e18dcfe921dc00 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 12:53:41 +0300 Subject: [PATCH 5/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index b67528e651..4299946738 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -120,5 +120,4 @@ class MagicNumberRule(configRules: List) : DiktatRule( "ignoreRanges" to false, "ignoreExtensionFunctions" to false) } - } From 77333f3abe36602ccf770813f9429ff1e877cdc0 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 13:10:59 +0300 Subject: [PATCH 6/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../diktat/ruleset/chapter3/files/TopLevelOrderRuleFixTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/TopLevelOrderRuleFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/TopLevelOrderRuleFixTest.kt index b3789ba210..4b6d875b60 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/TopLevelOrderRuleFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/TopLevelOrderRuleFixTest.kt @@ -4,7 +4,6 @@ import org.cqfn.diktat.ruleset.rules.chapter3.files.TopLevelOrderRule import org.cqfn.diktat.util.FixTestBase import generated.WarningNames -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test From 92958a2e4ea0cdc7f825f006b95c2800cd09c0e7 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 13:35:05 +0300 Subject: [PATCH 7/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt index e42d79f793..a6625c2b39 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt @@ -45,6 +45,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | val e = 3.4f | val g = 4/3 | val h = 0U + | val r = 1 | val f = "qwe\$\{12\}hhe" |} | From 5540d839bce223715a8875210159c120ce48fc8c Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Thu, 28 Apr 2022 17:39:00 +0300 Subject: [PATCH 8/8] Unsigned integer literal is perhaps incorrectly marked as a MAGIC_NUMBER ### What's done: * fixed ignore number in MAGIC_NUMBER rule Closes #1224 --- .../diktat/ruleset/rules/chapter3/MagicNumberRule.kt | 9 ++++++++- diktat-rules/src/main/resources/diktat-analysis.yml | 2 +- .../diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt | 2 +- pom.xml | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index 4299946738..0bef978165 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -90,7 +90,7 @@ class MagicNumberRule(configRules: List) : DiktatRule( /** * List of ignored numbers */ - val ignoreNumbers = config["ignoreNumbers"]?.split(",")?.map { it.trim() }?.filter { it.isNumber() } ?: ignoreNumbersList + val ignoreNumbers = config["ignoreNumbers"]?.split(",")?.map { it.trim() }?.filter { it.isNumber() || it.isOtherNumberType() } ?: ignoreNumbersList /** * @param param parameter from config @@ -102,7 +102,14 @@ class MagicNumberRule(configRules: List) : DiktatRule( /** * Check if string is number */ + // || ((this.last().uppercase() == "L" || this.last().uppercase() == "U") && this.substring(0, this.lastIndex-1).isNumber()) private fun String.isNumber() = (this.toLongOrNull() ?: this.toFloatOrNull()) != null + + /** + * Check if string include a char of number type + */ + private fun String.isOtherNumberType(): Boolean = ((this.last().uppercase() == "L" || this.last().uppercase() == "U") && this.substring(0, this.lastIndex).isNumber()) || + (this.substring(this.lastIndex - 1).uppercase() == "UL" && this.substring(0, this.lastIndex - 1).isNumber()) } companion object { diff --git a/diktat-rules/src/main/resources/diktat-analysis.yml b/diktat-rules/src/main/resources/diktat-analysis.yml index 2ca9d28455..763fd01307 100644 --- a/diktat-rules/src/main/resources/diktat-analysis.yml +++ b/diktat-rules/src/main/resources/diktat-analysis.yml @@ -304,7 +304,7 @@ # Ignore numbers from test ignoreTest: "true" # Ignore numbers - ignoreNumbers: "-1, 1, 0, 2" + ignoreNumbers: "-1, 1, 0, 2, 0U, 1U, 2U, -1L, 0L, 1L, 2L, 0UL, 1UL, 2UL" # Is ignore override hashCode function ignoreHashCodeFunction: "true" # Is ignore property diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt index a6625c2b39..aa3886cab7 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt @@ -45,7 +45,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | val e = 3.4f | val g = 4/3 | val h = 0U - | val r = 1 + | val r = 1UL | val f = "qwe\$\{12\}hhe" |} | diff --git a/pom.xml b/pom.xml index 875e03038d..0e86a2062e 100644 --- a/pom.xml +++ b/pom.xml @@ -256,7 +256,7 @@ -Werror - -Xopt-in=kotlin.RequiresOptIn + -opt-in=kotlin.RequiresOptIn true