-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WIP: empty_doc #11633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+133
−0
Closed
WIP: empty_doc #11633
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
68c27c8
basic implementation
SET001 33edb6d
fix message
SET001 7fc4671
Update clippy_lints/src/empty_docs.rs
SET001 5b0122b
better lint description
SET001 debe26d
function return type in example
SET001 60c3820
function return type in example
SET001 3ce3569
optimise code for readability
SET001 40f3102
Merge branch 'empty-docs' of github.com:SET001/rust-clippy into empty…
SET001 941876c
update tests
SET001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use clippy_utils::diagnostics::span_lint_and_help; | ||
use rustc_ast::ast::*; | ||
use rustc_lint::{EarlyContext, EarlyLintPass}; | ||
use rustc_session::{declare_lint_pass, declare_tool_lint}; | ||
|
||
declare_clippy_lint! { | ||
/// ### What it does | ||
/// Detects documentation that is empty. | ||
/// ### Why is this bad? | ||
/// It is unlikely that there is any reason to have empty documentation for an item | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// /// | ||
/// fn returns_true() -> bool { | ||
/// true | ||
/// } | ||
/// ``` | ||
/// Use instead: | ||
/// ```rust | ||
/// fn returns_true() -> bool { | ||
/// true | ||
/// } | ||
/// ``` | ||
#[clippy::version = "1.74.0"] | ||
pub EMPTY_DOCS, | ||
suspicious, | ||
"docstrings exist but documentation is empty" | ||
} | ||
|
||
declare_lint_pass!(EmptyDocs => [EMPTY_DOCS]); | ||
|
||
fn trim_comment(comment: &str) -> String { | ||
comment | ||
.trim() | ||
.split("\n") | ||
.map(|comment| comment.trim().trim_matches('*').trim_matches('!')) | ||
.collect::<Vec<&str>>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a missing |
||
.join("") | ||
} | ||
|
||
impl EarlyLintPass for EmptyDocs { | ||
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attribute: &Attribute) { | ||
if let AttrKind::DocComment(_line, comment) = attribute.kind { | ||
if trim_comment(comment.as_str()).len() == 0 { | ||
span_lint_and_help( | ||
cx, | ||
EMPTY_DOCS, | ||
attribute.span, | ||
"empty doc comment", | ||
None, | ||
"consider removing or fill it", | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![allow(unused)] | ||
#![warn(clippy::empty_docs)] | ||
|
||
pub mod outer_module { | ||
|
||
//! | ||
//! valid doc comment | ||
//!! | ||
//!! valid doc comment | ||
|
||
/// | ||
/// valid doc comment | ||
/// | ||
/// valid block doc comment | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
/** | ||
* valid block doc comment | ||
* | ||
*/ | ||
|
||
pub mod inner_module {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
error: empty doc comment | ||
--> $DIR/empty_docs.rs:11:5 | ||
| | ||
LL | /// | ||
| ^^^ | ||
| | ||
= help: consider removing or fill it | ||
= note: `-D clippy::empty-docs` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` | ||
|
||
error: empty doc comment | ||
--> $DIR/empty_docs.rs:13:5 | ||
| | ||
LL | /// | ||
| ^^^ | ||
| | ||
= help: consider removing or fill it | ||
|
||
error: empty doc comment | ||
--> $DIR/empty_docs.rs:16:5 | ||
| | ||
LL | / /** | ||
LL | | * | ||
LL | | */ | ||
| |_______^ | ||
| | ||
= help: consider removing or fill it | ||
|
||
error: empty doc comment | ||
--> $DIR/empty_docs.rs:6:5 | ||
| | ||
LL | //! | ||
| ^^^ | ||
| | ||
= help: consider removing or fill it | ||
|
||
error: empty doc comment | ||
--> $DIR/empty_docs.rs:8:5 | ||
| | ||
LL | //!! | ||
| ^^^^ | ||
| | ||
= help: consider removing or fill it | ||
|
||
error: aborting due to 5 previous errors | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that one shouldn't be needed.