From bd332080f2fc56cd25a9182043ece6631fb2f16a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:10:52 +0000 Subject: [PATCH] Create rule S7439 Comparisons with overlapping ranges that are always false should not be made (#4782) * Create rule S7439 * Update rule.adoc * Update metadata.json * Update rule.adoc * Update metadata.json --------- Co-authored-by: sallaigy Co-authored-by: Gyula Sallai --- rules/S7439/metadata.json | 2 ++ rules/S7439/rust/metadata.json | 24 ++++++++++++++++++++++++ rules/S7439/rust/rule.adoc | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 rules/S7439/metadata.json create mode 100644 rules/S7439/rust/metadata.json create mode 100644 rules/S7439/rust/rule.adoc diff --git a/rules/S7439/metadata.json b/rules/S7439/metadata.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/rules/S7439/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S7439/rust/metadata.json b/rules/S7439/rust/metadata.json new file mode 100644 index 0000000000..368f7b4e43 --- /dev/null +++ b/rules/S7439/rust/metadata.json @@ -0,0 +1,24 @@ +{ + "title": "Comparisons with overlapping ranges that are always false should not be made", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "clippy" + ], + "defaultSeverity": "Critical", + "ruleSpecification": "RSPEC-7439", + "sqKey": "S7439", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "RELIABILITY": "HIGH" + }, + "attribute": "LOGICAL" + } +} diff --git a/rules/S7439/rust/rule.adoc b/rules/S7439/rust/rule.adoc new file mode 100644 index 0000000000..db99ae0caa --- /dev/null +++ b/rules/S7439/rust/rule.adoc @@ -0,0 +1,20 @@ + +== Why is this an issue? + +Comparisons involving overlapping ranges that can never be true are likely a programming mistake and can result in unreachable code. + + +=== Code examples + +==== Noncompliant code example +[source,rust] +---- +if status_code <= 400 && status_code > 500 { // Noncompliant: The condition can never be true. + // ... +} +---- + +== Resources +=== Documentation + +* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons