1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! `shadow-variable` rule.
use super::*;
#[test]
fn test_shadow_variable() {
let diags = lint_source(
r#"
pipeline default(task) {
let x = 1
if true {
let x = 2
log(x)
}
log(x)
}
"#,
);
assert!(
has_rule(&diags, "shadow-variable"),
"expected shadow-variable warning, got: {diags:?}"
);
}
#[test]
fn test_no_shadow_same_scope() {
// Re-declaration in the same scope is not shadowing (it may be a
// parser error, but the linter only checks outer-scope shadows).
let diags = lint_source(
r#"
pipeline default(task) {
let x = 1
log(x)
}
"#,
);
assert!(
!has_rule(&diags, "shadow-variable"),
"same-scope should not trigger shadow-variable: {diags:?}"
);
}