Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump actions/setup-go from 2 to 4 #186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: 1.18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
- uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: 1.18
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: ${{ env.GO_VERSION }}
Expand All @@ -32,7 +32,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17 # TODO(ldez) the binary compiled with go1.17 doesn't work on go1.18
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
Expand All @@ -51,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: ${{ env.GO_VERSION }} # test only the latest go version to speed up CI
Expand All @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: ${{ env.GO_VERSION }} # test only the latest go version to speed up CI
Expand All @@ -83,7 +83,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: ${{ matrix.golang }}
Expand All @@ -107,7 +107,7 @@ jobs:
- name: Unshallow
run: git fetch --prune --unshallow
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: ${{ env.GO_VERSION }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: 1.18
Expand All @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: 1.18
Expand Down
88 changes: 88 additions & 0 deletions go.sum

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions pkg/golinters/goanalysis/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/lint/linter"
libpackages "github.com/golangci/golangci-lint/pkg/packages"
"github.com/golangci/golangci-lint/pkg/result"
)

Expand Down Expand Up @@ -144,6 +145,31 @@ func (lnt *Linter) configure() error {
return nil
}

func buildIssuesFromErrorsForTypecheckMode(errs []error, lintCtx *linter.Context) ([]result.Issue, error) {
var issues []result.Issue
uniqReportedIssues := map[string]bool{}
for _, err := range errs {
itErr, ok := errors.Cause(err).(*IllTypedError)
if !ok {
return nil, err
}
for _, err := range libpackages.ExtractErrors(itErr.Pkg) {
i, perr := parseError(err)
if perr != nil { // failed to parse
if uniqReportedIssues[err.Msg] {
continue
}
uniqReportedIssues[err.Msg] = true
lintCtx.Log.Errorf("typechecking error: %s", err.Msg)
} else {
i.Pkg = itErr.Pkg // to save to cache later
issues = append(issues, *i)
}
}
}
return issues, nil
}

func (lnt *Linter) preRun(lintCtx *linter.Context) error {
if err := analysis.Validate(lnt.analyzers); err != nil {
return errors.Wrap(err, "failed to validate analyzers")
Expand Down
236 changes: 236 additions & 0 deletions pkg/golinters/goanalysis/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package goanalysis

import (
"fmt"
"go/token"
"reflect"
"testing"

"github.com/golangci/golangci-lint/pkg/result"

"github.com/stretchr/testify/assert"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"
)

Expand Down Expand Up @@ -46,3 +51,234 @@ func TestParseError(t *testing.T) {
assert.Equal(t, "msg", i.Text)
}
}

func Test_buildIssues(t *testing.T) {
type args struct {
diags []Diagnostic
linterNameBuilder func(diag *Diagnostic) string
}
tests := []struct {
name string
args args
want []result.Issue
}{
{
name: "No Diagnostics",
args: args{
diags: []Diagnostic{},
linterNameBuilder: func(*Diagnostic) string {
return "some-linter"
},
},
want: []result.Issue(nil),
},
{
name: "Linter Name is Analyzer Name",
args: args{
diags: []Diagnostic{
{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
},
Analyzer: &analysis.Analyzer{
Name: "some-linter",
},
Position: token.Position{},
Pkg: nil,
},
},
linterNameBuilder: func(*Diagnostic) string {
return "some-linter"
},
},
want: []result.Issue{
{
FromLinter: "some-linter",
Text: "failure message",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := buildIssues(tt.args.diags, tt.args.linterNameBuilder); !reflect.DeepEqual(got, tt.want) {
t.Errorf("buildIssues() = %v, want %v", got, tt.want)
}
})
}
}

func Test_buildSingleIssue(t *testing.T) {
type args struct {
diag *Diagnostic
linterName string
}
fakePkg := packages.Package{
Fset: makeFakeFileSet(),
}
tests := []struct {
name string
args args
wantIssue result.Issue
}{
{
name: "Linter Name is Analyzer Name",
args: args{
diag: &Diagnostic{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
},
Analyzer: &analysis.Analyzer{
Name: "some-linter",
},
Position: token.Position{},
Pkg: nil,
},

linterName: "some-linter",
},
wantIssue: result.Issue{
FromLinter: "some-linter",
Text: "failure message",
},
},
{
name: "Linter Name is NOT Analyzer Name",
args: args{
diag: &Diagnostic{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
},
Analyzer: &analysis.Analyzer{
Name: "some-analyzer",
},
Position: token.Position{},
Pkg: nil,
},
linterName: "some-linter",
},
wantIssue: result.Issue{
FromLinter: "some-linter",
Text: "some-analyzer: failure message",
},
},
{
name: "Shows issue when suggested edits exist but has no TextEdits",
args: args{
diag: &Diagnostic{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
SuggestedFixes: []analysis.SuggestedFix{
{
Message: "fix something",
TextEdits: []analysis.TextEdit{},
},
},
},
Analyzer: &analysis.Analyzer{
Name: "some-analyzer",
},
Position: token.Position{},
Pkg: nil,
},
linterName: "some-linter",
},
wantIssue: result.Issue{
FromLinter: "some-linter",
Text: "some-analyzer: failure message",
},
},
{
name: "Replace Whole Line",
args: args{
diag: &Diagnostic{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
SuggestedFixes: []analysis.SuggestedFix{
{
Message: "fix something",
TextEdits: []analysis.TextEdit{
{
Pos: 101,
End: 201,
NewText: []byte("// Some comment to fix\n"),
},
},
},
},
},
Analyzer: &analysis.Analyzer{
Name: "some-analyzer",
},
Position: token.Position{},
Pkg: &fakePkg,
},
linterName: "some-linter",
},
wantIssue: result.Issue{
FromLinter: "some-linter",
Text: "some-analyzer: failure message",
LineRange: &result.Range{
From: 2,
To: 2,
},
Replacement: &result.Replacement{
NeedOnlyDelete: false,
NewLines: []string{
"// Some comment to fix",
},
},
Pkg: &fakePkg,
},
},
{
name: "Excludes Replacement if TextEdit doesn't modify only whole lines",
args: args{
diag: &Diagnostic{
Diagnostic: analysis.Diagnostic{
Message: "failure message",
SuggestedFixes: []analysis.SuggestedFix{
{
Message: "fix something",
TextEdits: []analysis.TextEdit{
{
Pos: 101,
End: 151,
NewText: []byte("// Some comment to fix\n"),
},
},
},
},
},
Analyzer: &analysis.Analyzer{
Name: "some-analyzer",
},
Position: token.Position{},
Pkg: &fakePkg,
},
linterName: "some-linter",
},
wantIssue: result.Issue{
FromLinter: "some-linter",
Text: "some-analyzer: failure message",
Pkg: &fakePkg,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotIssues := buildSingleIssue(tt.args.diag, tt.args.linterName); !reflect.DeepEqual(gotIssues, tt.wantIssue) {
t.Errorf("buildSingleIssue() = %v, want %v", gotIssues, tt.wantIssue)
}
})
}
}

func makeFakeFileSet() *token.FileSet {
fSet := token.NewFileSet()
file := fSet.AddFile("fake.go", 1, 1000)
for i := 100; i < 1000; i += 100 {
file.AddLine(i)
}
return fSet
}
Loading