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 @@ -8,6 +8,7 @@ import (
"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/analysis/testifylint"
"github.com/nnutter/constable/internal/driver"
)

Expand All @@ -26,5 +27,6 @@ func main() {
complexity.Analyzer,
errcheck.Analyzer,
sumtype.Analyzer,
testifylint.Analyzer,
)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.27.3
require (
github.com/alecthomas/go-check-sumtype v0.5.0
github.com/kisielk/errcheck v1.30.0
github.com/nnutter/testifylint v0.0.1
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
Expand Up @@ -4,6 +4,8 @@ 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=
github.com/kisielk/errcheck v1.30.0/go.mod h1:uiCAInmFuyOje4VDdbQSP9mgqf5gORYSXrDf19XilsI=
github.com/nnutter/testifylint v0.0.1 h1:QhFq2HgC7LxnaG5Z1Gi4aYN42y+fywfMY+e9xTYe0WM=
github.com/nnutter/testifylint v0.0.1/go.mod h1:DvNLVJQrA3YfswHJxaGzitfYt2gxFzlIs29buaH8sP4=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Package assert is a stub of github.com/stretchr/testify/assert that holds
// the calls the testdata makes. analysistest loads testdata in GOPATH mode, so
// the testdata cannot import the real module.
package assert

// TestingT is the part of testing.T that the assertions use.
type TestingT interface {
Errorf(format string, args ...any)
}

// True asserts that value is true.
func True(t TestingT, value bool, msgAndArgs ...any) bool { return value }

// NotEqual asserts that expected and actual are not equal.
func NotEqual(t TestingT, expected, actual any, msgAndArgs ...any) bool { return true }
11 changes: 11 additions & 0 deletions internal/analysis/testifylint/testdata/src/t/t.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package t

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCompare(t *testing.T) {
assert.True(t, 1 != 2) // want `compares: use assert.NotEqual`
}
13 changes: 13 additions & 0 deletions internal/analysis/testifylint/testdata/src/t/zz_generated.go

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

16 changes: 16 additions & 0 deletions internal/analysis/testifylint/testifylint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Package testifylint adapts the testifylint 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 testifylint

import (
"github.com/nnutter/testifylint/analyzer"

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

// Analyzer reports tests that misuse testify. It is the upstream analyzer with
// constable's generated-file policy applied.
var Analyzer = generated.Skip(analyzer.New())
13 changes: 13 additions & 0 deletions internal/analysis/testifylint/testifylint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testifylint_test

import (
"testing"

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

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

func TestAnalyzer(t *testing.T) {
analysistest.Run(t, analysistest.TestData(), testifylint.Analyzer, "t")
}
Loading