aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/useless_parens.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-31 09:05:26 +0000
committerAkshay <[email protected]>2021-10-31 16:05:15 +0000
commite8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch)
tree0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lints/useless_parens.rs
parent246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff)
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/useless_parens.rs')
-rw-r--r--lib/src/lints/useless_parens.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/src/lints/useless_parens.rs b/lib/src/lints/useless_parens.rs
index 2d6ba8f..36ad1b7 100644
--- a/lib/src/lints/useless_parens.rs
+++ b/lib/src/lints/useless_parens.rs
@@ -1,12 +1,37 @@
1use crate::{Lint, Metadata, Report, Rule, Suggestion, Diagnostic}; 1use crate::{Diagnostic, Metadata, Report, Rule, Suggestion};
2 2
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
5use rnix::{ 5use rnix::{
6 types::{ParsedType, KeyValue, Paren, TypedNode, Wrapper}, 6 types::{KeyValue, Paren, ParsedType, TypedNode, Wrapper},
7 NodeOrToken, SyntaxElement, SyntaxKind, 7 NodeOrToken, SyntaxElement, SyntaxKind,
8}; 8};
9 9
10/// ## What it does
11/// Checks for unnecessary parentheses.
12///
13/// ## Why is this bad?
14/// Unnecessarily parenthesized code is hard to read.
15///
16/// ## Example
17///
18/// ```
19/// let
20/// double = (x: 2 * x);
21/// ls = map (double) [ 1 2 3 ];
22/// in
23/// (2 + 3)
24/// ```
25///
26/// Remove unnecessary parentheses:
27///
28/// ```
29/// let
30/// double = x: 2 * x;
31/// ls = map double [ 1 2 3 ];
32/// in
33/// 2 + 3
34/// ```
10#[lint( 35#[lint(
11 name = "useless parens", 36 name = "useless parens",
12 note = "These parentheses can be omitted", 37 note = "These parentheses can be omitted",
@@ -27,7 +52,7 @@ impl Rule for UselessParens {
27 52
28 if let Some(diagnostic) = do_thing(parsed_type_node); 53 if let Some(diagnostic) = do_thing(parsed_type_node);
29 then { 54 then {
30 let mut report = Self::report(); 55 let mut report = self.report();
31 report.diagnostics.push(diagnostic); 56 report.diagnostics.push(diagnostic);
32 Some(report) 57 Some(report)
33 } else { 58 } else {
@@ -79,7 +104,7 @@ fn do_thing(parsed_type_node: ParsedType) -> Option<Diagnostic> {
79 if let Some(parsed_inner) = ParsedType::cast(inner_node); 104 if let Some(parsed_inner) = ParsedType::cast(inner_node);
80 if matches!( 105 if matches!(
81 parsed_inner, 106 parsed_inner,
82 ParsedType::List(_) 107 ParsedType::List(_)
83 | ParsedType::Paren(_) 108 | ParsedType::Paren(_)
84 | ParsedType::Str(_) 109 | ParsedType::Str(_)
85 | ParsedType::AttrSet(_) 110 | ParsedType::AttrSet(_)
@@ -95,6 +120,6 @@ fn do_thing(parsed_type_node: ParsedType) -> Option<Diagnostic> {
95 None 120 None
96 } 121 }
97 }, 122 },
98 _ => None 123 _ => None,
99 } 124 }
100} 125}