Skip to content
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

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

Closed
rhysd opened this issue Jan 30, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@rhysd
Copy link
Contributor

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

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

Auto merge of #3723 - rhysd:issue3721, r=oli-obk
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 in #3723 Feb 3, 2019

g-bartoszek added 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
You can’t perform that action at this time.