Skip to content

New Lint: Warn dbg!() macro use #3721

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
rhysd opened this issue Jan 30, 2019 · 0 comments
Closed

New Lint: Warn dbg!() macro use #3721

rhysd opened this issue Jan 30, 2019 · 0 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-macros Type: Issues with macros and macro expansion

Comments

@rhysd
Copy link
Contributor

rhysd commented Jan 30, 2019

At Rust v1.32, dbg! macro was added.

https://doc.rust-lang.org/std/macro.dbg.html

This macro is supposed to be used for print debugging. So it should not be contained in final code (e.g. when git commit).

From doc, it says:

Note that the macro is intended as a debugging tool and therefore you should avoid having uses of it in version control for longer periods. Use cases involving debug output that should be added to version control may be better served by macros such as debug! from the log crate.

I want to suggest to make clippy warn dbg!() macro use in code.

As related works, eslint, most popular linter for JavaScript, has rule no-console which prevents use of console.log.

https://eslint.org/docs/rules/no-console

@phansch phansch added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints L-unnecessary Lint: Warn about unnecessary code T-macros Type: Issues with macros and macro expansion labels Jan 30, 2019
rhysd added a commit to rhysd/rust-clippy that referenced this issue Jan 30, 2019
bors added a commit that referenced this issue Feb 3, 2019
Implement dbg_macro rule

Fixes  #3721

This patch adds new `dbg_macro` rule to check `dbg!` macro use.

Since this is my first patch to clippy, I'm not confident about following points:

- ~~Currently only checks `dbg!` span. Is it possible to check if the `dbg!` macro is provided by standard library or user-defined? If it's possible, I can make the check more strict.~~ Resolved as #3723 (comment)
- ~~Is category `style` correct for this rule?~~'restriction' is used instead
- ~~Should I use `span_lint_and_sugg` instead of `span_lint`? Currently entire message is put as `msg`.  But later part `ensure to avoid having uses of it in version control` may be put as suggestion.~~ Done
- I'm not native English speaker. The message and doc may not be natural as English.
@bors bors closed this as completed in #3723 Feb 3, 2019
g-bartoszek pushed a commit to g-bartoszek/rust-clippy that referenced this issue Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

2 participants