Skip to content

Commit 4116288

Browse files
committed
Ensure all tokens within non-unit import clause are ignored
1 parent 5324d11 commit 4116288

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

core/src/rules/ignore_non_unit_import_clauses.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use itertools::Itertools;
2+
13
use crate::prelude::*;
24

35
use crate::prelude::KeywordKind::*;
@@ -24,12 +26,18 @@ impl TokenIgnorer for IgnoreNonUnitImportClauses {
2426
lines
2527
.iter()
2628
.filter(|line| line.get_line_type() == LogicalLineType::ImportClause)
27-
.for_each(|line| {
28-
line.get_tokens().iter().for_each(|token| {
29-
token_marker.mark(*token);
30-
})
31-
});
29+
.for_each(|line| self.ignore_clause_line(line, token_marker));
30+
};
31+
}
32+
}
33+
impl IgnoreNonUnitImportClauses {
34+
fn ignore_clause_line(&self, line: &LogicalLine, token_marker: &mut TokenMarker) {
35+
let Some((&start, &end)) = line.get_tokens().iter().minmax().into_option() else {
36+
return;
3237
};
38+
for token in start..=end {
39+
token_marker.mark(token);
40+
}
3341
}
3442
}
3543

@@ -138,7 +146,25 @@ mod tests {
138146
uses a,b,c;
139147
"
140148
)
141-
}
149+
},
150+
containing_conditional_directives = {
151+
indoc::concatdoc!(
152+
stringify!($typ),
153+
"
154+
foo;
155+
uses a, {$ifdef A}, b {$endif};
156+
(a,b,c);
157+
"
158+
),
159+
indoc::concatdoc!(
160+
stringify!($typ),
161+
"
162+
foo;
163+
uses a, {$ifdef A}, b {$endif};
164+
(a, b, c);
165+
"
166+
)
167+
},
142168
);
143169
}
144170
};

0 commit comments

Comments
 (0)