Skip to content

Commit e472b01

Browse files
alecalvopjvsqzj
authored andcommitted
Check sp_braces in more AST nodes
1 parent d4e1aab commit e472b01

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(IndentParenExprArgs::from_paren_expression(self), acc);
180+
rules.nsp_inparen.check( NspInparenArgs::from_paren_expression(self), acc);
180181
}
181182
}
182183

src/analysis/parsing/statement.rs

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

src/analysis/parsing/structure.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ impl TreeElement for Instantiation {
624624
tok, file, ReferenceKind::Template));
625625
accumulator.extend(refs);
626626
}
627+
fn evaluate_rules(&self, acc: &mut Vec<DMLStyleError>, rules: &CurrentRules, _aux: AuxParams) {
628+
rules.nsp_inparen.check(NspInparenArgs::from_instantiation(self), acc);
629+
rules.sp_punct.check(SpPunctArgs::from_instantiation(self), acc);
630+
}
627631
}
628632

629633
fn parse_instantiation(context: &ParseContext, stream: &mut FileParser<'_>, _file_info: &FileInfo)
@@ -855,6 +859,9 @@ impl TreeElement for CompositeObjectContent {
855859
errors
856860
}
857861
fn references<'a>(&self, _accumulator: &mut Vec<Reference>, _file: FileSpec<'a>) {}
862+
fn evaluate_rules(&self, acc: &mut Vec<DMLStyleError>, rules: &CurrentRules, _aux: AuxParams) {
863+
rules.nsp_inparen.check(NspInparenArgs::from_composite_obj_content(self), acc);
864+
}
858865
}
859866

860867
#[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};
@@ -206,6 +215,17 @@ impl SpBracesArgs {
206215
rbrace: node.rbrace.range(),
207216
})
208217
}
218+
pub fn from_switch(node: &SwitchContent) -> Option<SpBracesArgs> {
219+
if node.cases.is_empty() {
220+
return None;
221+
}
222+
Some(SpBracesArgs {
223+
body_start: node.cases.first().unwrap().range(),
224+
body_end: node.cases.last().unwrap().range(),
225+
lbrace: node.lbrace.range(),
226+
rbrace: node.rbrace.range(),
227+
})
228+
}
209229
}
210230

211231
impl SpBracesRule {
@@ -465,6 +485,34 @@ impl SpPunctArgs {
465485
after_range_list,
466486
})
467487
}
488+
pub fn from_instantiation(node: &Instantiation) -> Option<SpPunctArgs> {
489+
if let Instantiation::Many(_, templates_list, _) = node {
490+
let mut before_range_list = vec![];
491+
let mut punct_range_list = vec![];
492+
let mut after_range_list = vec![];
493+
let mut iterator = templates_list.iter().peekable();
494+
495+
while let Some((template_name, comma)) = iterator.next() {
496+
if let Some(comma_token) = comma {
497+
before_range_list.push(template_name.range());
498+
punct_range_list.push(comma_token.range());
499+
if let Some((next_template_name, _)) = iterator.peek() {
500+
after_range_list.push(Some(next_template_name.range()));
501+
} else {
502+
after_range_list.push(None);
503+
}
504+
}
505+
}
506+
507+
Some(SpPunctArgs {
508+
before_range_list,
509+
punct_range_list,
510+
after_range_list,
511+
})
512+
} else {
513+
None
514+
}
515+
}
468516
}
469517

470518
impl SpPunctRule {
@@ -600,6 +648,41 @@ impl NspInparenArgs {
600648
closing: node.rparen.range(),
601649
})
602650
}
651+
pub fn from_composite_obj_content(node: &CompositeObjectContent)
652+
-> Option<NspInparenArgs> {
653+
if node.dimensions.is_empty() {
654+
return None;
655+
}
656+
let dimension = node.dimensions.first().unwrap();
657+
Some(NspInparenArgs {
658+
opening: dimension.0.range(),
659+
content_start: dimension.1.range(),
660+
content_end: dimension.3.range(),
661+
closing: dimension.4.range(),
662+
})
663+
}
664+
pub fn from_instantiation(node: &Instantiation)
665+
-> Option<NspInparenArgs> {
666+
if let Instantiation::Many(lparen, templates, rparen) = node {
667+
Some(NspInparenArgs {
668+
opening: lparen.range(),
669+
content_start: templates.range(),
670+
content_end: templates.range(),
671+
closing: rparen.range(),
672+
})
673+
} else {
674+
None
675+
}
676+
}
677+
pub fn from_paren_expression(node: &ParenExpressionContent)
678+
-> Option<NspInparenArgs> {
679+
Some(NspInparenArgs {
680+
opening: node.lparen.range(),
681+
content_start: node.expr.range(),
682+
content_end: node.expr.range(),
683+
closing: node.rparen.range(),
684+
})
685+
}
603686
pub fn from_function_call(node: &FunctionCallContent)
604687
-> Option<NspInparenArgs> {
605688
let content_start_range;

0 commit comments

Comments
 (0)