Skip to content

Commit e0c6a9e

Browse files
authored
Fix linter: using a local in an assertion. (#723)
1 parent 04f3751 commit e0c6a9e

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Diff for: linter/internal/variables/find_variables.go

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func findVariablesInObject(node *ast.DesugaredObject, info *common.VariableInfo,
6767
for _, local := range node.Locals {
6868
findVariables(local.Body, info, scopeInside)
6969
}
70+
for _, assert := range node.Asserts {
71+
findVariables(assert, info, scopeInside)
72+
}
7073
for _, field := range node.Fields {
7174
findVariables(field.Body, info, scopeInside)
7275
findVariables(field.Name, info, scopeOutside)

Diff for: linter/testdata/local_used_in_assertion.jsonnet

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
local input = [1,2,3],
3+
local knownItems = [1,2],
4+
local unknownItems = std.filter(function(i) !(i in knownItems), input),
5+
assert unknownItems == [] : "unexpected items: %s" % std.join(",",unknownItems)
6+
}

Diff for: linter/testdata/local_used_in_assertion.linter.golden

Whitespace-only changes.

Diff for: testdata/local_in_object_assertion.linter.golden

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
../testdata/local_in_object_assertion:1:9-15 Unused variable: x
2-
3-
{ local x = 42, assert x == 42 }
4-
5-

0 commit comments

Comments
 (0)