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:
github-actions[bot] 2025-03-19 13:07:29 +00:00 committed by GitHub
parent 7cf7c53935
commit ca818ac21b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View 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"
}
}

View 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