From 2b6012a79cb092e5d88c050cb494057efef28fc2 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 20 Nov 2021 18:56:26 +0530 Subject: introduce --config flag --- lib/src/lib.rs | 19 ++++++------------- lib/src/lints.rs | 4 ++-- lib/src/lints/collapsible_let_in.rs | 2 +- lib/src/lints/deprecated_is_null.rs | 2 +- lib/src/lints/empty_let_in.rs | 2 +- lib/src/lints/empty_pattern.rs | 2 +- lib/src/lints/eta_reduction.rs | 2 +- lib/src/lints/legacy_let_syntax.rs | 2 +- lib/src/lints/manual_inherit.rs | 2 +- lib/src/lints/manual_inherit_from.rs | 2 +- lib/src/lints/redundant_pattern_bind.rs | 2 +- lib/src/lints/unquoted_splice.rs | 2 +- lib/src/lints/unquoted_uri.rs | 2 +- lib/src/lints/useless_parens.rs | 2 +- 14 files changed, 20 insertions(+), 27 deletions(-) (limited to 'lib/src') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 5347666..d96d9eb 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -255,31 +255,24 @@ pub trait Lint: Metadata + Explain + Rule + Send + Sync {} /// /// See `lints.rs` for usage. #[macro_export] -macro_rules! lint_map { +macro_rules! lints { ($($s:ident),*,) => { - lint_map!($($s),*); + lints!($($s),*); }; ($($s:ident),*) => { - use ::std::collections::HashMap; - use ::rnix::SyntaxKind; $( mod $s; )* ::lazy_static::lazy_static! { - pub static ref LINTS: HashMap>> = { - let mut map = HashMap::new(); + pub static ref LINTS: Vec<&'static Box> = { + let mut v = Vec::new(); $( { let temp_lint = &*$s::LINT; - let temp_matches = temp_lint.match_kind(); - for temp_match in temp_matches { - map.entry(temp_match) - .and_modify(|v: &mut Vec<_>| v.push(temp_lint)) - .or_insert_with(|| vec![temp_lint]); - } + v.push(temp_lint); } )* - map + v }; } } diff --git a/lib/src/lints.rs b/lib/src/lints.rs index 8b0f92b..b4d4af3 100644 --- a/lib/src/lints.rs +++ b/lib/src/lints.rs @@ -1,6 +1,6 @@ -use crate::lint_map; +use crate::lints; -lint_map! { +lints! { bool_comparison, empty_let_in, manual_inherit, diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index 26a3102..aa7e5a7 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs @@ -37,7 +37,7 @@ use rowan::Direction; /// a + b /// ``` #[lint( - name = "collapsible let in", + name = "collapsible_let_in", note = "These let-in expressions are collapsible", code = 6, match_with = SyntaxKind::NODE_LET_IN diff --git a/lib/src/lints/deprecated_is_null.rs b/lib/src/lints/deprecated_is_null.rs index fce6931..c814e87 100644 --- a/lib/src/lints/deprecated_is_null.rs +++ b/lib/src/lints/deprecated_is_null.rs @@ -27,7 +27,7 @@ use rnix::{ /// e == null /// ``` #[lint( - name = "deprecated isNull", + name = "deprecated_is_null", note = "Found usage of deprecated builtin isNull", code = 13, match_with = SyntaxKind::NODE_APPLY diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index 5a51ea3..d33d0ae 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs @@ -26,7 +26,7 @@ use rnix::{ /// pkgs.statix /// ``` #[lint( - name = "empty let-in", + name = "empty_let_in", note = "Useless let-in expression", code = 2, match_with = SyntaxKind::NODE_LET_IN diff --git a/lib/src/lints/empty_pattern.rs b/lib/src/lints/empty_pattern.rs index c0cb5a4..f66a3b1 100644 --- a/lib/src/lints/empty_pattern.rs +++ b/lib/src/lints/empty_pattern.rs @@ -35,7 +35,7 @@ use rnix::{ /// }; /// ``` #[lint( - name = "empty pattern", + name = "empty_pattern", note = "Found empty pattern in function argument", code = 10, match_with = SyntaxKind::NODE_PATTERN diff --git a/lib/src/lints/eta_reduction.rs b/lib/src/lints/eta_reduction.rs index 454c78f..580f4a0 100644 --- a/lib/src/lints/eta_reduction.rs +++ b/lib/src/lints/eta_reduction.rs @@ -34,7 +34,7 @@ use rnix::{ /// map double [ 1 2 3 ] /// ``` #[lint( - name = "eta reduction", + name = "eta_reduction", note = "This function expression is eta reducible", code = 7, match_with = SyntaxKind::NODE_LAMBDA diff --git a/lib/src/lints/legacy_let_syntax.rs b/lib/src/lints/legacy_let_syntax.rs index cdd012d..5d0028b 100644 --- a/lib/src/lints/legacy_let_syntax.rs +++ b/lib/src/lints/legacy_let_syntax.rs @@ -36,7 +36,7 @@ use rnix::{ /// }.body /// ``` #[lint( - name = "legacy let syntax", + name = "legacy_let_syntax", note = "Using undocumented `let` syntax", code = 5, match_with = SyntaxKind::NODE_LEGACY_LET diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 1813af3..7717dc9 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.rs @@ -32,7 +32,7 @@ use rnix::{ /// { inherit a; b = 3; } /// ``` #[lint( - name = "manual inherit", + name = "manual_inherit", note = "Assignment instead of inherit", code = 3, match_with = SyntaxKind::NODE_KEY_VALUE diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs index ab2579d..05d6bc8 100644 --- a/lib/src/lints/manual_inherit_from.rs +++ b/lib/src/lints/manual_inherit_from.rs @@ -32,7 +32,7 @@ use rnix::{ /// null /// ``` #[lint( - name = "manual inherit from", + name = "manual_inherit_from", note = "Assignment instead of inherit from", code = 4, match_with = SyntaxKind::NODE_KEY_VALUE diff --git a/lib/src/lints/redundant_pattern_bind.rs b/lib/src/lints/redundant_pattern_bind.rs index 882a660..88ce4b0 100644 --- a/lib/src/lints/redundant_pattern_bind.rs +++ b/lib/src/lints/redundant_pattern_bind.rs @@ -27,7 +27,7 @@ use rnix::{ /// inputs: inputs.nixpkgs /// ``` #[lint( - name = "redundant pattern bind", + name = "redundant_pattern_bind", note = "Found redundant pattern bind in function argument", code = 11, match_with = SyntaxKind::NODE_PATTERN diff --git a/lib/src/lints/unquoted_splice.rs b/lib/src/lints/unquoted_splice.rs index ce269b6..7649fbc 100644 --- a/lib/src/lints/unquoted_splice.rs +++ b/lib/src/lints/unquoted_splice.rs @@ -32,7 +32,7 @@ use rnix::{ /// pkgs /// ``` #[lint( - name = "unquoted splice", + name = "unquoted_splice", note = "Found unquoted splice expression", code = 9, match_with = SyntaxKind::NODE_DYNAMIC diff --git a/lib/src/lints/unquoted_uri.rs b/lib/src/lints/unquoted_uri.rs index b111f78..8835338 100644 --- a/lib/src/lints/unquoted_uri.rs +++ b/lib/src/lints/unquoted_uri.rs @@ -38,7 +38,7 @@ use rnix::{types::TypedNode, NodeOrToken, SyntaxElement, SyntaxKind}; /// } /// ``` #[lint( - name = "unquoted uri", + name = "unquoted_uri", note = "Found unquoted URI expression", code = 12, match_with = SyntaxKind::TOKEN_URI diff --git a/lib/src/lints/useless_parens.rs b/lib/src/lints/useless_parens.rs index dccc717..09d6f04 100644 --- a/lib/src/lints/useless_parens.rs +++ b/lib/src/lints/useless_parens.rs @@ -33,7 +33,7 @@ use rnix::{ /// 2 + 3 /// ``` #[lint( - name = "useless parens", + name = "useless_parens", note = "These parentheses can be omitted", code = 8, match_with = [ -- cgit v1.2.3