Skip to content

Commit 990b43f

Browse files
committed
Merge remote-tracking branch 'golangci/master' into add-gomodguard-linter
2 parents a48cc71 + 3fd6db7 commit 990b43f

File tree

1,639 files changed

+173
-554170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,639 files changed

+173
-554170
lines changed

.github/stale.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Number of days of inactivity before an issue becomes stale
2-
daysUntilStale: 180
2+
daysUntilStale: 366
33

44
# Number of days of inactivity before a stale issue is closed
5-
daysUntilClose: 14
5+
daysUntilClose: 30
66

77
# Issues with these labels will never be considered stale
88
exemptLabels:
99
- pinned
1010
- security
11+
- bug
12+
- blocked
13+
- protected
14+
- triaged
1115

1216
# Label to use when marking an issue as stale
1317
staleLabel: stale

.golangci.example.yml

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ linters-settings:
126126
gocyclo:
127127
# minimal code complexity to report, 30 by default (but we recommend 10-20)
128128
min-complexity: 10
129+
godot:
130+
# check all top-level comments, not only declarations
131+
check-all: false
129132
godox:
130133
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
131134
# might be left in the code accidentally and should be resolved before merging

Makefile

+5-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# enable module support across all go commands.
55
export GO111MODULE = on
6-
# opt-in to vendor deps across all go commands.
7-
export GOFLAGS = -mod=vendor
86
# enable consistent Go 1.12/1.13 GOPROXY behavior.
97
export GOPROXY = https://proxy.golang.org
108

@@ -46,25 +44,25 @@ test_linters:
4644

4745
# Maintenance
4846

49-
generate: README.md docs/demo.svg install.sh vendor
47+
generate: README.md docs/demo.svg install.sh
5048
.PHONY: generate
5149

52-
fast_generate: README.md vendor
50+
fast_generate: README.md
5351
.PHONY: fast_generate
5452

5553
maintainer-clean: clean
56-
rm -rf docs/demo.svg README.md install.sh vendor
54+
rm -rf docs/demo.svg README.md install.sh
5755
.PHONY: maintainer-clean
5856

5957
check_generated:
6058
$(MAKE) --always-make generate
61-
git checkout -- vendor/modules.txt go.mod go.sum # can differ between go1.12 and go1.13
59+
git checkout -- go.mod go.sum # can differ between go1.12 and go1.13
6260
git diff --exit-code # check no changes
6361
.PHONY: check_generated
6462

6563
fast_check_generated:
6664
$(MAKE) --always-make fast_generate
67-
git checkout -- vendor/modules.txt go.mod go.sum # can differ between go1.12 and go1.13
65+
git checkout -- go.mod go.sum # can differ between go1.12 and go1.13
6866
git diff --exit-code # check no changes
6967
.PHONY: fast_check_generated
7068

@@ -105,11 +103,3 @@ go.mod: FORCE
105103
go mod tidy
106104
go mod verify
107105
go.sum: go.mod
108-
109-
vendor: go.mod go.sum
110-
go mod vendor
111-
112-
unexport GOFLAGS
113-
vendor_free_build: FORCE
114-
go build -o golangci-lint ./cmd/golangci-lint
115-
.PHONY: vendor_free_build vendor

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ gocognit: Computes and checks the cognitive complexity of functions [fast: true,
217217
goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
218218
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
219219
gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
220+
godot: Check if comments end in a period [fast: true, auto-fix: false]
220221
godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
221222
gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
222223
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
@@ -489,7 +490,7 @@ golangci-lint help linters
489490
- [wsl](https://github.com/bombsimon/wsl) - Whitespace Linter - Forces you to use empty lines!
490491
- [goprintffuncname](https://github.com/jirfag/go-printf-func-name) - Checks that printf-like functions are named with `f` at the end
491492
- [gomnd](https://github.com/tommy-muehle/go-mnd) - An analyzer to detect magic numbers.
492-
- [gomodguard](https://github.com/ryancurrah/gomodguard) - Allow and block list linter for direct Go module dependencies.
493+
- [godot](https://github.com/tetafro/godot) - Check if comments end in a period
493494
494495
## Configuration
495496
@@ -511,7 +512,7 @@ Usage:
511512
golangci-lint run [flags]
512513
513514
Flags:
514-
--out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number")
515+
--out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions (default "colored-line-number")
515516
--print-issued-lines Print lines of code with issue (default true)
516517
--print-linter-name Print linter name in issue line (default true)
517518
--uniq-by-line Make issues output unique by line (default true)
@@ -738,6 +739,9 @@ linters-settings:
738739
gocyclo:
739740
# minimal code complexity to report, 30 by default (but we recommend 10-20)
740741
min-complexity: 10
742+
godot:
743+
# check all top-level comments, not only declarations
744+
check-all: false
741745
godox:
742746
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
743747
# might be left in the code accidentally and should be resolved before merging
@@ -1275,7 +1279,7 @@ Thanks to developers and authors of used linters:
12751279
- [bombsimon](https://github.com/bombsimon)
12761280
- [jirfag](https://github.com/jirfag)
12771281
- [tommy-muehle](https://github.com/tommy-muehle)
1278-
- [ryancurrah](https://github.com/ryancurrah)
1282+
- [tetafro](https://github.com/tetafro)
12791283
12801284
## Changelog
12811285

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
3939
github.com/spf13/pflag v1.0.5
4040
github.com/spf13/viper v1.6.1
4141
github.com/stretchr/testify v1.5.1
42+
github.com/tetafro/godot v0.2.5
4243
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e
4344
github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa
4445
github.com/ultraware/funlen v0.0.2

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
270270
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
271271
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
272272
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
273+
github.com/tetafro/godot v0.2.5 h1:7+EYJM/Z4gYZhBFdRrVm6JTj5ZLw/QI1j4RfEOXJviE=
274+
github.com/tetafro/godot v0.2.5/go.mod h1:pT6/T8+h6//L/LwQcFc4C0xpfy1euZwzS1sHdrFCms0=
273275
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=
274276
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
275277
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=

pkg/commands/run.go

+2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ func (e *Executor) createPrinter() (printers.Printer, error) {
396396
p = printers.NewCodeClimate()
397397
case config.OutFormatJunitXML:
398398
p = printers.NewJunitXML()
399+
case config.OutFormatGithubActions:
400+
p = printers.NewGithub()
399401
default:
400402
return nil, fmt.Errorf("unknown output format %s", format)
401403
}

pkg/config/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
OutFormatCheckstyle = "checkstyle"
1616
OutFormatCodeClimate = "code-climate"
1717
OutFormatJunitXML = "junit-xml"
18+
OutFormatGithubActions = "github-actions"
1819
)
1920

2021
var OutFormats = []string{
@@ -25,6 +26,7 @@ var OutFormats = []string{
2526
OutFormatCheckstyle,
2627
OutFormatCodeClimate,
2728
OutFormatJunitXML,
29+
OutFormatGithubActions,
2830
}
2931

3032
type ExcludePattern struct {
@@ -208,6 +210,7 @@ type LintersSettings struct {
208210
Godox GodoxSettings
209211
Dogsled DogsledSettings
210212
Gocognit GocognitSettings
213+
Godot GodotSettings
211214

212215
Custom map[string]CustomLinterSettings
213216
}
@@ -285,6 +288,10 @@ type WSLSettings struct {
285288
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
286289
}
287290

291+
type GodotSettings struct {
292+
CheckAll bool `mapstructure:"check-all"`
293+
}
294+
288295
//nolint:gomnd
289296
var defaultLintersSettings = LintersSettings{
290297
Lll: LllSettings{

pkg/golinters/godot.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package golinters
2+
3+
import (
4+
"sync"
5+
6+
"github.com/tetafro/godot"
7+
"golang.org/x/tools/go/analysis"
8+
9+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
10+
"github.com/golangci/golangci-lint/pkg/lint/linter"
11+
"github.com/golangci/golangci-lint/pkg/result"
12+
)
13+
14+
const godotName = "godot"
15+
16+
func NewGodot() *goanalysis.Linter {
17+
var mu sync.Mutex
18+
var resIssues []goanalysis.Issue
19+
20+
analyzer := &analysis.Analyzer{
21+
Name: godotName,
22+
Doc: goanalysis.TheOnlyanalyzerDoc,
23+
}
24+
return goanalysis.NewLinter(
25+
godotName,
26+
"Check if comments end in a period",
27+
[]*analysis.Analyzer{analyzer},
28+
nil,
29+
).WithContextSetter(func(lintCtx *linter.Context) {
30+
cfg := lintCtx.Cfg.LintersSettings.Godot
31+
settings := godot.Settings{CheckAll: cfg.CheckAll}
32+
33+
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
34+
var issues []godot.Message
35+
for _, file := range pass.Files {
36+
issues = append(issues, godot.Run(file, pass.Fset, settings)...)
37+
}
38+
39+
if len(issues) == 0 {
40+
return nil, nil
41+
}
42+
43+
res := make([]goanalysis.Issue, len(issues))
44+
for k, i := range issues {
45+
issue := result.Issue{
46+
Pos: i.Pos,
47+
Text: i.Message,
48+
FromLinter: godotName,
49+
Replacement: &result.Replacement{},
50+
}
51+
52+
res[k] = goanalysis.NewIssue(&issue, pass)
53+
}
54+
55+
mu.Lock()
56+
resIssues = append(resIssues, res...)
57+
mu.Unlock()
58+
59+
return nil, nil
60+
}
61+
}).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
62+
return resIssues
63+
}).WithLoadMode(goanalysis.LoadModeSyntax)
64+
}

pkg/lint/lintersdb/manager.go

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
251251
WithPresets(linter.PresetStyle).
252252
WithLoadForGoAnalysis().
253253
WithURL("https://github.com/ryancurrah/gomodguard"),
254+
linter.NewConfig(golinters.NewGodot()).
255+
WithPresets(linter.PresetStyle).
256+
WithURL("https://github.com/tetafro/godot"),
254257
}
255258

256259
isLocalRun := os.Getenv("GOLANGCI_COM_RUN") == ""

pkg/printers/github.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package printers
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/golangci/golangci-lint/pkg/logutils"
8+
"github.com/golangci/golangci-lint/pkg/result"
9+
)
10+
11+
type github struct {
12+
}
13+
14+
// Github output format outputs issues according to Github actions format:
15+
// https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
16+
func NewGithub() Printer {
17+
return &github{}
18+
}
19+
20+
// print each line as: ::error file=app.js,line=10,col=15::Something went wrong
21+
func formatIssueAsGithub(issue *result.Issue) string {
22+
ret := fmt.Sprintf("::error file=%s,line=%d", issue.FilePath(), issue.Line())
23+
if issue.Pos.Column != 0 {
24+
ret += fmt.Sprintf(",col=%d", issue.Pos.Column)
25+
}
26+
27+
ret += fmt.Sprintf("::%s (%s)", issue.Text, issue.FromLinter)
28+
return ret
29+
}
30+
31+
func (g *github) Print(_ context.Context, issues []result.Issue) error {
32+
for ind := range issues {
33+
_, err := fmt.Fprintln(logutils.StdOut, formatIssueAsGithub(&issues[ind]))
34+
if err != nil {
35+
return err
36+
}
37+
}
38+
return nil
39+
}

pkg/printers/github_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package printers
2+
3+
import (
4+
"go/token"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/golangci/golangci-lint/pkg/result"
10+
)
11+
12+
func TestFormatGithubIssue(t *testing.T) {
13+
sampleIssue := result.Issue{
14+
FromLinter: "sample-linter",
15+
Text: "some issue",
16+
Pos: token.Position{
17+
Filename: "path/to/file.go",
18+
Offset: 2,
19+
Line: 10,
20+
Column: 4,
21+
},
22+
}
23+
require.Equal(t, "::error file=path/to/file.go,line=10,col=4::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
24+
25+
sampleIssue.Pos.Column = 0
26+
require.Equal(t, "::error file=path/to/file.go,line=10::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
27+
}

test/testdata/godot.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//args: -Egodot
2+
package testdata
3+
4+
// Godot checks top-level comments // ERROR "Top level comment should end in a period"
5+
func Godot() {
6+
// nothing to do here
7+
}

vendor/github.com/BurntSushi/toml/.gitignore

-5
This file was deleted.

vendor/github.com/BurntSushi/toml/.travis.yml

-15
This file was deleted.

vendor/github.com/BurntSushi/toml/COMPATIBLE

-3
This file was deleted.

vendor/github.com/BurntSushi/toml/COPYING

-21
This file was deleted.

0 commit comments

Comments
 (0)