Skip to content

Commit

Permalink
usage: add string exception for attrpaths
Browse files Browse the repository at this point in the history
Fixes Github issue #91
  • Loading branch information
astro committed Dec 17, 2024
1 parent be32f41 commit 47a0ded
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/dead_code_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,24 @@ fn let_partially_shadowed_by_attrset() {
assert_eq!(1, results.len());
assert_eq!(results[0].binding.name.to_string(), "dead");
}

#[test]
fn let_args_splice() {
let results = run("
{ config, ... }:
\"${config.bar}\"
");
assert_eq!(0, results.len());
}

#[test]
fn let_args_string_splice() {
let results = run("
{ config, ... }: {
\"${config.bar}\" = 42;
}
");
assert_eq!(0, results.len());
}
8 changes: 6 additions & 2 deletions src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ pub fn find(name: &Ident, node: &SyntaxNode<NixLanguage>) -> bool {
ident.syntax().text() == name.syntax().text()
} else if node.kind() == SyntaxKind::NODE_ATTRPATH {
// Don't search for idents in keys, they introduce new scopes
// anyway. Except for `${...}`
// anyway. Except for `${...}` and `"..."` which do not
// introduce new scopes in attrsets that are not declared
// `rec`.
node.children().any(|node|
node.kind() == SyntaxKind::NODE_DYNAMIC &&
(node.kind() == SyntaxKind::NODE_DYNAMIC ||
node.kind() == SyntaxKind::NODE_STRING
) &&
find(name, &node)
)
} else {
Expand Down

0 comments on commit 47a0ded

Please sign in to comment.