Create rule S7418: Lint attributes should not be used on crate imports (#4759)
* Create rule S7418 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
This commit is contained in:
parent
7cf7c53935
commit
ca818ac21b
2
rules/S7418/metadata.json
Normal file
2
rules/S7418/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
24
rules/S7418/rust/metadata.json
Normal file
24
rules/S7418/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"title": "Lint attributes should not be used on crate imports",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"clippy"
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Major",
|
||||||
|
"ruleSpecification": "RSPEC-7418",
|
||||||
|
"sqKey": "S7418",
|
||||||
|
"scope": "All",
|
||||||
|
"defaultQualityProfiles": ["Sonar way"],
|
||||||
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"RELIABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "LOGICAL"
|
||||||
|
}
|
||||||
|
}
|
33
rules/S7418/rust/rule.adoc
Normal file
33
rules/S7418/rust/rule.adoc
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
Lint attributes on crate imports and `use` statements have no effect and may indicate a misunderstanding or mistake in the code. This can lead to confusion or unintended behavior.
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
#[deny(dead_code)]
|
||||||
|
extern crate foo;
|
||||||
|
|
||||||
|
#[forbid(dead_code)]
|
||||||
|
use foo::bar; // Noncompliant: Lint attributes are ineffective on imports.
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use foo::baz;
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate baz; // Compliant: Example with appropriate usage.
|
||||||
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute
|
Loading…
x
Reference in New Issue
Block a user