Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruleguard: fix nil engine state for bundles #185

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions _test/install/binary_nogopath/expected.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/root/target.go:8:10: exprUnparen: the parentheses around 1 are superfluous (rules.go:21)
/root/target.go:9:10: exprUnparen: the parentheses around 2 are superfluous (rules.go:21)
/root/target.go:11:10: boolComparison: omit bool literal in expression (rules1.go:8)
/root/target.go:12:10: boolExprSimplify: suggestion: b (rules2.go:6)
/root/target.go:15:10: interfaceAddr: taking address of interface-typed value (rules.go:27)
/root/target.go:10:10: exprUnparen: the parentheses around 1 are superfluous (rules.go:23)
/root/target.go:11:10: exprUnparen: the parentheses around 2 are superfluous (rules.go:23)
/root/target.go:13:10: boolComparison: omit bool literal in expression (rules1.go:8)
/root/target.go:14:10: boolExprSimplify: suggestion: b (rules2.go:6)
/root/target.go:17:10: interfaceAddr: taking address of interface-typed value (rules.go:29)
/root/target.go:21:10: sprintStringer: can use foo.String() directly (sub_rules.go:17)
/root/target.go:22:10: sprintStringer: can use fooPtr.String() directly (sub_rules.go:17)
4 changes: 2 additions & 2 deletions _test/install/binary_nogopath/expected2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/root/target.go:8:10: e: add((1), 2)
/root/target.go:9:10: e: add(1, (2))
/root/target.go:10:10: e: add((1), 2)
/root/target.go:11:10: e: add(1, (2))
58 changes: 29 additions & 29 deletions _test/install/binary_nogopath/expected3.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/usr/local/go/src/encoding/gob/decode.go:1086:19: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/decode.go:1182:19: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/decode.go:1086:19: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/decode.go:1182:19: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/enc_helpers.go:66:6: boolComparison: omit bool literal in expression (rules1.go:8)
/usr/local/go/src/encoding/gob/encode.go:691:19: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/stream.go:456:25: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/asn1/marshal_test.go:281:28: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/asn1/marshal_test.go:303:28: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/base32/base32_test.go:99:4: exprUnparen: the parentheses around p.encoded[len(p.encoded)-1] == '=' are superfluous (rules.go:21)
/usr/local/go/src/encoding/gob/encode.go:691:19: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/stream.go:456:25: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/asn1/marshal_test.go:281:28: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/asn1/marshal_test.go:303:28: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/base32/base32_test.go:99:4: exprUnparen: the parentheses around p.encoded[len(p.encoded)-1] == '=' are superfluous (rules.go:23)
/usr/local/go/src/encoding/binary/binary_test.go:447:5: boolComparison: omit bool literal in expression (rules1.go:8)
/usr/local/go/src/encoding/binary/binary_test.go:450:5: boolComparison: omit bool literal in expression (rules1.go:8)
/usr/local/go/src/encoding/gob/codec_test.go:351:6: boolComparison: omit bool literal in expression (rules1.go:8)
/usr/local/go/src/encoding/gob/codec_test.go:1402:23: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/codec_test.go:1415:23: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/encoder_test.go:637:18: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/encoder_test.go:641:17: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/gobencdec_test.go:771:19: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/gobencdec_test.go:777:19: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/example_interface_test.go:65:20: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/example_interface_test.go:76:20: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/bench_test.go:196:23: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/bench_test.go:206:24: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:1180:31: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:1252:41: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:1455:14: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:2027:33: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:2379:24: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:2407:6: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/decode_test.go:2526:12: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/stream_test.go:189:25: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/stream_test.go:305:34: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/stream_test.go:419:22: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/json/tagkey_test.go:105:22: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/xml/marshal_test.go:391:9: interfaceAddr: taking address of interface-typed value (rules.go:27)
/usr/local/go/src/encoding/gob/codec_test.go:1402:23: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/codec_test.go:1415:23: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/encoder_test.go:637:18: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/encoder_test.go:641:17: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/gobencdec_test.go:771:19: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/gobencdec_test.go:777:19: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/example_interface_test.go:65:20: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/gob/example_interface_test.go:76:20: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/bench_test.go:196:23: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/bench_test.go:206:24: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:1180:31: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:1252:41: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:1455:14: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:2027:33: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:2379:24: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:2407:6: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/decode_test.go:2526:12: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/stream_test.go:189:25: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/stream_test.go:305:34: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/stream_test.go:419:22: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/json/tagkey_test.go:105:22: interfaceAddr: taking address of interface-typed value (rules.go:29)
/usr/local/go/src/encoding/xml/marshal_test.go:391:9: interfaceAddr: taking address of interface-typed value (rules.go:29)
2 changes: 2 additions & 0 deletions _test/install/binary_nogopath/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"github.com/quasilyte/go-ruleguard/dsl"
"github.com/quasilyte/go-ruleguard/dsl/types"
testrules "github.com/quasilyte/ruleguard-rules-test"
subtestrules "github.com/quasilyte/ruleguard-rules-test/sub2"
)

func init() {
dsl.ImportRules("", testrules.Bundle)
dsl.ImportRules("", subtestrules.Bundle)
}

func isInterface(ctx *dsl.VarFilterContext) bool {
Expand Down
13 changes: 13 additions & 0 deletions _test/install/binary_nogopath/target.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package target

import "fmt"

func add(x, y int) int {
return x + y
}
Expand All @@ -13,4 +15,15 @@ func test(b bool) {

var eface interface{}
println(&eface)

fooPtr := &Foo{}
foo := Foo{}
println(fmt.Sprint(foo))
println(fmt.Sprint(fooPtr))
println(fmt.Sprint(0)) // Not fmt.Stringer
println(fmt.Sprint(&foo)) // Not addressable
}

type Foo struct{}

func (*Foo) String() string { return "Foo" }
1 change: 1 addition & 0 deletions ruleguard/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (p *rulesParser) importRules(prefix, pkgPath, filename string) (*goRuleSet,
return nil, err
}
config := rulesParserConfig{
state: p.state,
ctx: p.ctx,
importer: p.importer,
prefix: prefix,
Expand Down