Skip to content

Commit

Permalink
update: improve static check
Browse files Browse the repository at this point in the history
  • Loading branch information
sivchari committed Mar 24, 2023
1 parent d45ed89 commit 70e6ad2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.17
uses: actions/setup-go@v1
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: 1.17
go-version: '1.20'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Restore cache
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand All @@ -38,8 +38,8 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43.0
version: v1.52.1
11 changes: 1 addition & 10 deletions containedctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
return
}
for _, field := range structTyp.Fields.List {
selectorExpr, ok := field.Type.(*ast.SelectorExpr)
if !ok {
continue
}
xname, ok := selectorExpr.X.(*ast.Ident)
if !ok {
continue
}
selname := selectorExpr.Sel.Name
if xname.Name+"."+selname == "context.Context" {
if pass.TypesInfo.TypeOf(field.Type).String() == "context.Context" {
pass.Reportf(field.Pos(), "found a struct that contains a context.Context field")
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// flags for Analyzer.Flag.
// If you would like to specify flags for your plugin, you can put them via 'ldflags' as below.
// $ go build -buildmode=plugin -ldflags "-X 'main.flags=-opt val'" containedctx/plugin/containedctx
// $ go build -buildmode=plugin -ldflags "-X 'main.flags=-opt val'" containedctx/plugin/containedctx
var flags string

// AnalyzerPlugin provides analyzers as a plugin.
Expand Down
7 changes: 7 additions & 0 deletions testdata/src/a/b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package a

import xcontext "context"

type namedng struct {
ctx xcontext.Context // want "found a struct that contains a context.Context field"
}

0 comments on commit 70e6ad2

Please sign in to comment.