]> git.lizzy.rs Git - rust.git/commitdiff
Add skeleton for double_parens lint.
authorTheemathas Chirananthavat <theemathas@gmail.com>
Wed, 28 Dec 2016 18:54:23 +0000 (10:54 -0800)
committerTheemathas Chirananthavat <theemathas@gmail.com>
Wed, 28 Dec 2016 19:21:53 +0000 (11:21 -0800)
clippy_lints/src/double_parens.rs [new file with mode: 0644]
clippy_lints/src/lib.rs

diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs
new file mode 100644 (file)
index 0000000..85611cd
--- /dev/null
@@ -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.
+    }
+}
index 06aab286b2fe6effdf60b5724169c8ca0449c33d..ac92d5ec97bc5ce1ae9b4bcb1439b028050ae37e 100644 (file)
@@ -69,6 +69,7 @@ macro_rules! declare_restriction_lint {
 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,