Skip to content
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
2 changes: 2 additions & 0 deletions cmd/constable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/nnutter/constable/internal/analysis/methodical"
"github.com/nnutter/constable/internal/analysis/nonmutating"
"github.com/nnutter/constable/internal/analysis/predicates"
"github.com/nnutter/constable/internal/analysis/sumtype"
"github.com/nnutter/constable/internal/analysis/testify"
"github.com/nnutter/constable/internal/driver"
)
Expand All @@ -24,5 +25,6 @@ func main() {
testify.Analyzer,
complexity.Analyzer,
errcheck.Analyzer,
sumtype.Analyzer,
)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/nnutter/constable
go 1.27.3

require (
github.com/alecthomas/go-check-sumtype v0.5.0
github.com/kisielk/errcheck v1.30.0
github.com/stretchr/testify v1.12.1
golang.org/x/tools v0.52.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/alecthomas/go-check-sumtype v0.5.0 h1:yIFGZYGU5xv64lXp0llRhji/d/kDfS6AaqOI+wAxTqM=
github.com/alecthomas/go-check-sumtype v0.5.0/go.mod h1:z2jV5/4nQ3XRzKG7PMrJ46DE2NtdnMjQA/fzfzWH81Q=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kisielk/errcheck v1.30.0 h1:ZIxNDAfAd4larXHTceoZP/dYPAB90dHg1OYhA2sVh5k=
Expand Down
16 changes: 16 additions & 0 deletions internal/analysis/sumtype/sumtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Package sumtype adapts the go-check-sumtype analyzer to constable.
//
// constable embeds the analyzer from another module instead of reimplementing
// it, so this package holds the places where constable's own policy differs
// from the upstream default.
package sumtype

import (
gochecksumtype "github.com/alecthomas/go-check-sumtype"

"github.com/nnutter/constable/internal/generated"
)

// Analyzer reports a type switch over a sum type that omits a variant. It is
// the upstream analyzer with constable's generated-file policy applied.
var Analyzer = generated.Skip(gochecksumtype.Analyzer)
13 changes: 13 additions & 0 deletions internal/analysis/sumtype/sumtype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sumtype_test

import (
"testing"

"golang.org/x/tools/go/analysis/analysistest"

"github.com/nnutter/constable/internal/analysis/sumtype"
)

func TestAnalyzer(t *testing.T) {
analysistest.Run(t, analysistest.TestData(), sumtype.Analyzer, "st")
}
19 changes: 19 additions & 0 deletions internal/analysis/sumtype/testdata/src/st/st.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// want package:`sumTypeFact\{Shape \[Circle Square\]\}`
package st

//sumtype:decl
type Shape interface{ shape() }

type Circle struct{}

func (*Circle) shape() {}

type Square struct{}

func (*Square) shape() {}

func F(s Shape) {
switch s.(type) { // want `missing cases for Square`
case *Circle:
}
}
9 changes: 9 additions & 0 deletions internal/analysis/sumtype/testdata/src/st/zz_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading