Skip to content

Commit

Permalink
chore: fix CI ang go1.22 support (#479)
Browse files Browse the repository at this point in the history
* chore: update golangci-lint
* chore: apply go-critic reports
* attempt to fix alias
  • Loading branch information
ldez authored Aug 23, 2024
1 parent 5a36c24 commit 0fe6f58
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{ name: "Check out code into the Go module directory", uses: "actions/checkout@v4" },
{
name: "Set up Go ${{ matrix.go-version }}",
uses: "actions/setup-go@v4",
uses: "actions/setup-go@v5",
with: { "go-version": "${{ matrix.go-version }}" },
id: "go",
},
Expand Down
30 changes: 11 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"run": {
# timeout for analysis, e.g. 30s, 5m, default is 1m
"deadline": "3m",
"timeout": "3m",
},
"fast": false,
"linters": {
"enable": [
"errcheck",
Expand All @@ -22,29 +21,22 @@
"unparam",
"unused",
],
"disable": [
"depguard",
"dupl",
"gocyclo",
"lll",
"prealloc",
],
},
"disable": [
"deadcode", # deprecated
"depguard",
"dupl",
"exhaustivestruct", # deprecated
"gocyclo",
"golint", # deprecated
"ifshort", # deprecated
"interfacer", # deprecated
"lll",
"maligned", # deprecated
"nosnakecase", # deprecated
"prealloc",
"scopelint", # deprecated
"structcheck", # deprecated
"varcheck", # deprecated
],
"linters-settings": {
"gocritic": {
"enabled-checks": [
"commentedOutCode",
],
},
"gosec": {
"excludes": ["G115"]
}
},
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test-release:
@echo "everything is OK"

lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.54.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.60.2
$(GOPATH_DIR)/bin/golangci-lint run ./...
go build -o go-ruleguard ./cmd/ruleguard
./go-ruleguard -debug-imports -rules rules.go ./...
Expand Down
2 changes: 1 addition & 1 deletion internal/xtypes/xtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func typeIdentical(x, y types.Type, p *ifacePair) bool {

case *types.Alias:
// an alias type is identical if the type it's an alias of is identical to it.
return typeIdentical(x.Rhs(), y, p)
return typeIdentical(types.Unalias(x), y, p)

case nil:
// avoid a crash in case of nil type
Expand Down
3 changes: 1 addition & 2 deletions ruleguard/irconv/irconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ func (conv *converter) convertFilterExprImpl(e ast.Expr) ir.FilterExpr {
case *ast.UnaryExpr:
x := conv.convertFilterExpr(e.X)
args := []ir.FilterExpr{x}
switch e.Op {
case token.NOT:
if e.Op == token.NOT {
return ir.FilterExpr{Op: ir.FilterNotOp, Args: args}
}

Expand Down
8 changes: 5 additions & 3 deletions ruleguard/irprint/irprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func (p *printer) printReflectElemNoNewline(key string, v reflect.Value, insideL
}
}

if v.Type().Kind() == reflect.Struct {
switch v.Type().Kind() {
case reflect.Struct:
if !insideList {
p.buf.WriteString(v.Type().String())
}
Expand All @@ -104,7 +105,8 @@ func (p *printer) printReflectElemNoNewline(key string, v reflect.Value, insideL
p.printReflectElem(v.Type().Field(i).Name, v.Field(i), false)
}
p.writef("},")
} else if v.Type().Kind() == reflect.Slice {

case reflect.Slice:
if isCompactSlice(v) {
p.writef("%s{", v.Type())
for j := 0; j < v.Len(); j++ {
Expand All @@ -119,7 +121,7 @@ func (p *printer) printReflectElemNoNewline(key string, v reflect.Value, insideL
p.writef("},")
}

} else {
default:
switch val := v.Interface().(type) {
case int64:
p.writef("int64(%v),", val)
Expand Down
7 changes: 4 additions & 3 deletions ruleguard/quasigo/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,12 @@ func (cl *compiler) compileCall(key funcKey, sig *types.Signature, args []ast.Ex
}

var op opcode
if sig.Results().Len() == 0 {
switch {
case sig.Results().Len() == 0:
op = opVoidCall
} else if typeIsInt(sig.Results().At(0).Type()) {
case typeIsInt(sig.Results().At(0).Type()):
op = opIntCall
} else {
default:
op = opCall
}

Expand Down
4 changes: 2 additions & 2 deletions ruleguard/ruleguard_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ func TestParseFilterFuncError(t *testing.T) {
}

for _, test := range tests {
file := fmt.Sprintf(`
file := `
package gorules
import "github.com/quasilyte/go-ruleguard/dsl"
type Foo struct { X int }
func (foo *Foo) String() string { return "" }
func g(ctx *dsl.VarFilterContext) bool { return false }
` + test.src)
` + test.src
e := NewEngine()
ctx := &LoadContext{
Fset: token.NewFileSet(),
Expand Down

0 comments on commit 0fe6f58

Please sign in to comment.