Skip to content

Commit 37f6d48

Browse files
authored
Merge pull request #14 from sonatard/update
Update golang.org/x/tools
2 parents b3b4659 + fde5406 commit 37f6d48

File tree

8 files changed

+59
-52
lines changed

8 files changed

+59
-52
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
go: [ '1.14', '1.13' ]
9+
go: [ '1.20', '1.19' ]
1010
name: Go ${{ matrix.go }} test
1111
steps:
1212
- name: Checkout repository
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v3
1414
- name: Setup Go
15-
uses: actions/setup-go@v2
15+
uses: actions/setup-go@v3
1616
with:
1717
go-version: ${{ matrix.go }}
1818
- name: Install GolangCI-Lint
19-
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
19+
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2
2020
- run: make test_coverage
2121
- name: Upload code coverage to codecov
22-
if: matrix.go == '1.14'
23-
uses: codecov/codecov-action@v1
22+
if: matrix.go == '1.20'
23+
uses: codecov/codecov-action@v3
2424
with:
2525
file: ./coverage.out
2626
- run: make lint

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
- name: Unshallow
1515
run: git fetch --prune --unshallow
1616
- name: Set up Go
17-
uses: actions/setup-go@v2
17+
uses: actions/setup-go@v3
1818
with:
1919
go-version: 1.x
2020
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v1
21+
uses: goreleaser/goreleaser-action@v4
2222
with:
2323
version: latest
2424
args: release --rm-dist

.golangci.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
run:
2-
3-
linters-settings:
4-
govet:
2+
linters-settings:
3+
govet:
4+
enable-all: true
5+
linters:
56
enable-all: true
6-
7-
linters:
8-
enable-all: true
9-
disable:
10-
- gochecknoglobals
11-
- gomnd
12-
- gocognit
13-
- nestif
14-
15-
issues:
16-
exclude-rules:
17-
- path: reqwithoutctx/ssa.go
18-
text: "Consider preallocating `exts`"
19-
linters:
20-
- prealloc
7+
disable:
8+
- gochecknoglobals
9+
- gomnd
10+
- gocognit
11+
- nestif
12+
- nilnil
13+
- paralleltest
14+
- varnamelen

go.mod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module github.com/sonatard/noctx
22

3-
go 1.16
3+
go 1.20
44

55
require (
66
github.com/gostaticanalysis/analysisutil v0.7.1
7-
golang.org/x/tools v0.1.4
7+
golang.org/x/tools v0.7.0
8+
)
9+
10+
require (
11+
github.com/gostaticanalysis/comment v1.4.2 // indirect
12+
golang.org/x/mod v0.9.0 // indirect
13+
golang.org/x/sys v0.6.0 // indirect
814
)

go.sum

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,24 @@ github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg
2020
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
2121
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
2222
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
23-
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
2423
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2524
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
2625
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
2726
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
28-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
29-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
27+
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
28+
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
3029
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3130
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3231
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
33-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
3432
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3533
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
36-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
34+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
3735
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3836
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3937
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
40-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4138
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
42-
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
43-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
44-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
39+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
40+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4641
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4742
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
4843
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
@@ -51,10 +46,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
5146
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
5247
golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU=
5348
golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU=
54-
golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs=
55-
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
49+
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
50+
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
5651
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5752
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5853
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
59-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
6054
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

ngfunc/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ngfunc
22

33
import (
4+
"fmt"
45
"go/types"
56

67
"github.com/gostaticanalysis/analysisutil"
@@ -34,8 +35,11 @@ func Run(pass *analysis.Pass) (interface{}, error) {
3435
func ngCalledFuncs(pass *analysis.Pass, ngFuncs []*types.Func) []*Report {
3536
var reports []*Report
3637

37-
srcFuncs := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA).SrcFuncs
38-
for _, sf := range srcFuncs {
38+
ssa, ok := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA)
39+
if !ok {
40+
panic(fmt.Sprintf("%T is not *buildssa.SSA", pass.ResultOf[buildssa.Analyzer]))
41+
}
42+
for _, sf := range ssa.SrcFuncs {
3943
for _, b := range sf.Blocks {
4044
for _, instr := range b.Instrs {
4145
for _, ngFunc := range ngFuncs {

noctx.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
package noctx
22

33
import (
4+
"fmt"
45
"github.com/sonatard/noctx/ngfunc"
56
"github.com/sonatard/noctx/reqwithoutctx"
67
"golang.org/x/tools/go/analysis"
78
"golang.org/x/tools/go/analysis/passes/buildssa"
89
)
910

1011
var Analyzer = &analysis.Analyzer{
11-
Name: "noctx",
12-
Doc: Doc,
13-
Run: run,
12+
Name: "noctx",
13+
Doc: Doc,
14+
Run: run,
15+
RunDespiteErrors: false,
1416
Requires: []*analysis.Analyzer{
1517
buildssa.Analyzer,
1618
},
19+
ResultType: nil,
20+
FactTypes: nil,
1721
}
1822

1923
const Doc = "noctx finds sending http request without context.Context"
2024

2125
func run(pass *analysis.Pass) (interface{}, error) {
2226
if _, err := ngfunc.Run(pass); err != nil {
23-
return nil, err
27+
return nil, fmt.Errorf("run: %w", err)
2428
}
2529

2630
if _, err := reqwithoutctx.Run(pass); err != nil {
27-
return nil, err
31+
return nil, fmt.Errorf("run: %w", err)
2832
}
2933

3034
return nil, nil

reqwithoutctx/ssa.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package reqwithoutctx
22

33
import (
4+
"fmt"
45
"go/types"
56

67
"github.com/gostaticanalysis/analysisutil"
@@ -10,6 +11,7 @@ import (
1011
"golang.org/x/tools/go/ssa"
1112
)
1213

14+
//nolint:govet
1315
type Analyzer struct {
1416
Funcs []*ssa.Function
1517
newRequestType types.Type
@@ -20,10 +22,13 @@ func NewAnalyzer(pass *analysis.Pass) *Analyzer {
2022
newRequestType := analysisutil.TypeOf(pass, "net/http", "NewRequest")
2123
requestType := analysisutil.TypeOf(pass, "net/http", "*Request")
2224

23-
srcFuncs := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA).SrcFuncs
25+
ssa, ok := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA)
26+
if !ok {
27+
panic(fmt.Sprintf("%T is not *buildssa.SSA", pass.ResultOf[buildssa.Analyzer]))
28+
}
2429

2530
return &Analyzer{
26-
Funcs: srcFuncs,
31+
Funcs: ssa.SrcFuncs,
2732
newRequestType: newRequestType,
2833
requestType: requestType,
2934
}
@@ -88,14 +93,14 @@ func (a *Analyzer) usedReqs() map[string]*ssa.Extract {
8893
}
8994

9095
func (a *Analyzer) usedReqByCall(call *ssa.Call) []*ssa.Extract {
91-
var exts []*ssa.Extract
96+
args := call.Common().Args
97+
exts := make([]*ssa.Extract, 0, len(args))
9298

9399
// skip net/http.Request method call
94100
if call.Common().Signature().Recv() != nil && types.Identical(call.Value().Type(), a.requestType) {
95101
return exts
96102
}
97103

98-
args := call.Common().Args
99104
if len(args) == 0 {
100105
return exts
101106
}

0 commit comments

Comments
 (0)