-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement dbg_macro rule #3723
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
Merged
Merged
Implement dbg_macro rule #3723
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f894adc
implement dbg_macro rule (fixes #3721)
rhysd 7ec5528
fix category and use suggestion
rhysd 9d130a5
add dbg_macro rule to CHANGELOG.md and update count in README
rhysd 06e4e9c
remove TODO comment which was already done
rhysd b52a9bd
`cargo +nightly fmt` at clippy_lints/
rhysd 268ff85
use span_help_and_lint() instead of span_lint_and_sugg()
rhysd 54d49af
add more test cases for dbg_macro rule
rhysd 3100fec
use snippet for making a suggestion if possible
rhysd 60f723f
prefer `if` to `match`
rhysd 4b736ff
Merge branch 'master' into issue3721
rhysd 83d620b
run `util/dev update_lints` and `cargo fmt --all`
rhysd 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; | ||
use rustc::{declare_tool_lint, lint_array}; | ||
use crate::utils::span_lint; | ||
use syntax::ast; | ||
|
||
/// **What it does:** Checks for usage of dbg!() macro not to have it in | ||
/// version control. | ||
/// | ||
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool. | ||
/// | ||
/// **Known problems:** None. | ||
/// | ||
/// **Example:** | ||
/// ```rust,ignore | ||
/// // Bad | ||
/// dbg!(true) | ||
/// | ||
/// // Good | ||
/// true | ||
/// ``` | ||
declare_clippy_lint! { | ||
pub DBG_MACRO, | ||
style, | ||
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 wonder if we need a whole new category for such lints at some point. We already have things like linting |
||
"`dbg!` macro is intended as a debugging tool" | ||
} | ||
|
||
#[derive(Copy, Clone, Debug)] | ||
pub struct Pass; | ||
|
||
impl LintPass for Pass { | ||
fn get_lints(&self) -> LintArray { | ||
lint_array!(DBG_MACRO) | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"DbgMacro" | ||
} | ||
} | ||
|
||
impl EarlyLintPass for Pass { | ||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { | ||
if mac.node.path == "dbg" { | ||
rhysd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
span_lint( | ||
rhysd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cx, | ||
DBG_MACRO, | ||
mac.span, | ||
"`dbg!` macro is intended as a debugging tool. ensure to avoid having uses of it in version control", | ||
rhysd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
} | ||
} |
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,3 @@ | ||
fn main() { | ||
dbg!(42); | ||
rhysd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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,10 @@ | ||
error: `dbg!` macro is intended as a debugging tool. ensure to avoid having uses of it in version control | ||
--> $DIR/dbg_macro.rs:2:5 | ||
| | ||
LL | dbg!(42); | ||
| ^^^^^^^^ | ||
| | ||
= note: `-D clippy::dbg-macro` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.