Skip to content

Commit 5bd945b

Browse files
alecalvopjvsqzj
authored andcommitted
Check sp_braces in more AST nodes
1 parent 8b18048 commit 5bd945b

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

src/analysis/parsing/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ impl TreeElement for ParenExpressionContent {
177177
}
178178
fn evaluate_rules(&self, acc: &mut Vec<DMLStyleError>, rules: &CurrentRules, _aux: AuxParams) {
179179
rules.indent_paren_expr.check(acc, IndentParenExprArgs::from_paren_expression(self));
180+
rules.nsp_inparen.check(acc, NspInparenArgs::from_paren_expression(self));
180181
}
181182
}
182183

src/analysis/parsing/statement.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ impl TreeElement for SwitchContent {
11191119
{
11201120
rules.indent_closing_brace.check(acc, IndentClosingBraceArgs::from_switch_content(self, aux.depth));
11211121
rules.indent_paren_expr.check(acc, IndentParenExprArgs::from_switch(self));
1122+
rules.sp_brace.check(acc, SpBracesArgs::from_switch(self));
11221123
}
11231124
}
11241125

src/analysis/parsing/structure.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ impl TreeElement for Instantiation {
607607
tok, file, ReferenceKind::Template));
608608
accumulator.extend(refs);
609609
}
610+
fn evaluate_rules(&self, acc: &mut Vec<DMLStyleError>, rules: &CurrentRules, _aux: AuxParams) {
611+
rules.nsp_inparen.check(acc, NspInparenArgs::from_instantiation(self));
612+
rules.sp_punct.check(acc, SpPunctArgs::from_instantiation(self));
613+
}
610614
}
611615

612616
fn parse_instantiation(context: &ParseContext, stream: &mut FileParser<'_>, _file_info: &FileInfo)
@@ -838,6 +842,9 @@ impl TreeElement for CompositeObjectContent {
838842
errors
839843
}
840844
fn references<'a>(&self, _accumulator: &mut Vec<Reference>, _file: FileSpec<'a>) {}
845+
fn evaluate_rules(&self, acc: &mut Vec<DMLStyleError>, rules: &CurrentRules, _aux: AuxParams) {
846+
rules.nsp_inparen.check(acc, NspInparenArgs::from_composite_obj_content(self));
847+
}
841848
}
842849

843850
#[derive(Debug, Clone, PartialEq)]

src/lint/rules/spacing.rs

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ use crate::lint::{rules::{Rule, RuleType},
99
DMLStyleError};
1010
use crate::analysis::parsing::tree::{LeafToken, TreeElement, ZeroRange};
1111
use crate::analysis::parsing::expression::{BinaryExpressionContent,
12-
FunctionCallContent, IndexContent,
12+
FunctionCallContent,
13+
IndexContent,
14+
ParenExpressionContent,
1315
PostUnaryExpressionContent,
1416
TertiaryExpressionContent,
1517
UnaryExpressionContent};
16-
use crate::analysis::parsing::statement::{AfterContent, CompoundContent, ExpressionStmtContent,
17-
ForContent, IfContent, VariableDeclContent,
18+
use crate::analysis::parsing::statement::{AfterContent,
19+
CompoundContent,
20+
ExpressionStmtContent,
21+
ForContent,
22+
IfContent,
23+
SwitchContent,
24+
VariableDeclContent,
1825
WhileContent};
19-
use crate::analysis::parsing::structure::{MethodContent,
26+
use crate::analysis::parsing::structure::{CompositeObjectContent,
27+
Instantiation,
28+
MethodContent,
2029
ObjectStatementsContent};
2130

2231
use crate::span::{ZeroIndexed, Range};
@@ -205,6 +214,17 @@ impl SpBracesArgs {
205214
rbrace: node.rbrace.range(),
206215
})
207216
}
217+
pub fn from_switch(node: &SwitchContent) -> Option<SpBracesArgs> {
218+
if node.cases.is_empty() {
219+
return None;
220+
}
221+
Some(SpBracesArgs {
222+
body_start: node.cases.first().unwrap().range(),
223+
body_end: node.cases.last().unwrap().range(),
224+
lbrace: node.lbrace.range(),
225+
rbrace: node.rbrace.range(),
226+
})
227+
}
208228
}
209229

210230
impl SpBracesRule {
@@ -453,6 +473,34 @@ impl SpPunctArgs {
453473
after_range_list,
454474
})
455475
}
476+
pub fn from_instantiation(node: &Instantiation) -> Option<SpPunctArgs> {
477+
if let Instantiation::Many(_, templates_list, _) = node {
478+
let mut before_range_list = vec![];
479+
let mut punct_range_list = vec![];
480+
let mut after_range_list = vec![];
481+
let mut iterator = templates_list.iter().peekable();
482+
483+
while let Some((template_name, comma)) = iterator.next() {
484+
if let Some(comma_token) = comma {
485+
before_range_list.push(template_name.range());
486+
punct_range_list.push(comma_token.range());
487+
if let Some((next_template_name, _)) = iterator.peek() {
488+
after_range_list.push(Some(next_template_name.range()));
489+
} else {
490+
after_range_list.push(None);
491+
}
492+
}
493+
}
494+
495+
Some(SpPunctArgs {
496+
before_range_list,
497+
punct_range_list,
498+
after_range_list,
499+
})
500+
} else {
501+
None
502+
}
503+
}
456504
}
457505

458506
impl SpPunctRule {
@@ -587,6 +635,41 @@ impl NspInparenArgs {
587635
closing: node.rparen.range(),
588636
})
589637
}
638+
pub fn from_composite_obj_content(node: &CompositeObjectContent)
639+
-> Option<NspInparenArgs> {
640+
if node.dimensions.is_empty() {
641+
return None;
642+
}
643+
let dimension = node.dimensions.first().unwrap();
644+
Some(NspInparenArgs {
645+
opening: dimension.0.range(),
646+
content_start: dimension.1.range(),
647+
content_end: dimension.3.range(),
648+
closing: dimension.4.range(),
649+
})
650+
}
651+
pub fn from_instantiation(node: &Instantiation)
652+
-> Option<NspInparenArgs> {
653+
if let Instantiation::Many(lparen, templates, rparen) = node {
654+
Some(NspInparenArgs {
655+
opening: lparen.range(),
656+
content_start: templates.range(),
657+
content_end: templates.range(),
658+
closing: rparen.range(),
659+
})
660+
} else {
661+
None
662+
}
663+
}
664+
pub fn from_paren_expression(node: &ParenExpressionContent)
665+
-> Option<NspInparenArgs> {
666+
Some(NspInparenArgs {
667+
opening: node.lparen.range(),
668+
content_start: node.expr.range(),
669+
content_end: node.expr.range(),
670+
closing: node.rparen.range(),
671+
})
672+
}
590673
pub fn from_function_call(node: &FunctionCallContent)
591674
-> Option<NspInparenArgs> {
592675
let content_start_range;

0 commit comments

Comments
 (0)