diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs new file mode 100644 index 000000000..85611cd6c --- /dev/null +++ b/clippy_lints/src/double_parens.rs @@ -0,0 +1,35 @@ +use syntax::ast::*; +use rustc::lint::{EarlyContext, LintArray, LintPass, EarlyLintPass}; + +/// **What it does:** Checks for unnecessary double parentheses. +/// +/// **Why is this bad?** This makes code harder to read and might indicate a +/// mistake. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// ((0)) +/// foo((0)) +/// ((1, 2)) +/// ``` +declare_lint! { + pub DOUBLE_PARENS, Warn, + "Warn on unnecessary double parentheses" +} + +#[derive(Copy, Clone)] +pub struct DoubleParens; + +impl LintPass for DoubleParens { + fn get_lints(&self) -> LintArray { + lint_array!(DOUBLE_PARENS) + } +} + +impl EarlyLintPass for DoubleParens { + fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) { + // insert check here. + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 06aab286b..ac92d5ec9 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -69,6 +69,7 @@ pub mod copies; pub mod cyclomatic_complexity; pub mod derive; pub mod doc; +pub mod double_parens; pub mod drop_ref; pub mod entry; pub mod enum_clike; @@ -283,6 +284,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box if_let_redundant_pattern_matching::Pass); reg.register_late_lint_pass(box partialeq_ne_impl::Pass); reg.register_early_lint_pass(box reference::Pass); + reg.register_early_lint_pass(box double_parens::DoubleParens); reg.register_lint_group("clippy_restrictions", vec![ arithmetic::FLOAT_ARITHMETIC, @@ -355,6 +357,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { derive::DERIVE_HASH_XOR_EQ, derive::EXPL_IMPL_CLONE_ON_COPY, doc::DOC_MARKDOWN, + double_parens::DOUBLE_PARENS, drop_ref::DROP_REF, entry::MAP_ENTRY, enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,