diff --git a/linter/internal/variables/find_variables.go b/linter/internal/variables/find_variables.go index cfdef8ed..64b1862d 100644 --- a/linter/internal/variables/find_variables.go +++ b/linter/internal/variables/find_variables.go @@ -67,6 +67,9 @@ func findVariablesInObject(node *ast.DesugaredObject, info *common.VariableInfo, for _, local := range node.Locals { findVariables(local.Body, info, scopeInside) } + for _, assert := range node.Asserts { + findVariables(assert, info, scopeInside) + } for _, field := range node.Fields { findVariables(field.Body, info, scopeInside) findVariables(field.Name, info, scopeOutside) diff --git a/linter/testdata/local_used_in_assertion.jsonnet b/linter/testdata/local_used_in_assertion.jsonnet new file mode 100644 index 00000000..f5799045 --- /dev/null +++ b/linter/testdata/local_used_in_assertion.jsonnet @@ -0,0 +1,6 @@ +{ + local input = [1,2,3], + local knownItems = [1,2], + local unknownItems = std.filter(function(i) !(i in knownItems), input), + assert unknownItems == [] : "unexpected items: %s" % std.join(",",unknownItems) +} \ No newline at end of file diff --git a/linter/testdata/local_used_in_assertion.linter.golden b/linter/testdata/local_used_in_assertion.linter.golden new file mode 100644 index 00000000..e69de29b diff --git a/testdata/local_in_object_assertion.linter.golden b/testdata/local_in_object_assertion.linter.golden index 8e110cfd..e69de29b 100644 --- a/testdata/local_in_object_assertion.linter.golden +++ b/testdata/local_in_object_assertion.linter.golden @@ -1,5 +0,0 @@ -../testdata/local_in_object_assertion:1:9-15 Unused variable: x - -{ local x = 42, assert x == 42 } - -