Update RSPEC

This commit is contained in:
yassin-kammoun-sonarsource 2025-03-26 15:39:10 +01:00
parent 0f59803695
commit 32914e08dd
2 changed files with 48 additions and 30 deletions

View File

@ -1,12 +1,13 @@
{
"title": "FIXME",
"type": "CODE_SMELL",
"title": "Serde `visit_str` method should be implemented when `visit_string` is implemented",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7460",
@ -16,10 +17,8 @@
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "HIGH",
"RELIABILITY": "MEDIUM",
"SECURITY": "LOW"
"RELIABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
"attribute": "LOGICAL"
}
}

View File

@ -1,16 +1,10 @@
FIXME: add a description
// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
== Why is this an issue?
FIXME: remove the unused optional headers (that are commented out)
Serde is a popular framework in the Rust ecosystem for serializing and deserializing data. It provides a flexible and efficient way to convert Rust data structures into various formats (e.g., JSON, YAML) and vice versa.
//=== What is the potential impact?
One of the core components of Serde is the `Visitor` trait, which allows custom deserialization logic by visiting each element of the data structure. According to Serde's documentation, any implementation of the `Visitor` trait that implements the `visit_string` method must also implement the `visit_str` method. Failing to do so can lead to unexpected behavior.
== How to fix it
//== How to fix it in FRAMEWORK NAME
This rule ensures that implementations of the `Visitor` trait adhere to this requirement, promoting correctness and preventing subtle bugs in deserialization logic.
=== Code examples
@ -18,27 +12,52 @@ FIXME: remove the unused optional headers (that are commented out)
[source,rust,diff-id=1,diff-type=noncompliant]
----
FIXME
struct A;
impl<'de> serde::de::Visitor<'de> for A {
type Value = ();
fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
unimplemented!()
}
fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
unimplemented!()
}
}
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
FIXME
impl<'de> serde::de::Visitor<'de> for A {
type Value = ();
fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
unimplemented!()
}
fn visit_str<E>(self, _v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
unimplemented!()
}
fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
unimplemented!()
}
}
----
//=== How does this work?
== Resources
=== Documentation
//=== Pitfalls
//=== Going the extra mile
//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse