Skip to content

Commit 8a478c4

Browse files
committed
Prepare for #164: rename GAS to gosec
1. Rename in a backward compatible way 2. Remove gosec default exclude list because gosec is already disabled by default. 3. Warn about unmatched linter names in //nolint directives 4. Process linter names in //nolint directives in upper case 5. Disable gosec for golangci-lint in .golangci.yml
1 parent 47440bc commit 8a478c4

File tree

29 files changed

+361
-107
lines changed

29 files changed

+361
-107
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ linters:
2525
enable-all: true
2626
disable:
2727
- maligned
28-
- prealloc
28+
- prealloc
29+
- gosec

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ assets:
1414
readme:
1515
go run ./scripts/gen_readme/main.go
1616

17+
gen:
18+
go generate ./...
19+
1720
check_generated:
1821
make readme && git diff --exit-code # check no changes
1922

README.tmpl.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ We compare golangci-lint and gometalinter in default mode, but explicitly enable
166166
$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \
167167
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
168168
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
169-
--enable=interfacer --enable=unconvert --enable=goconst --enable=gas --enable=megacheck
169+
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck
170170
$ gometalinter --deadline=30m --vendor --cyclo-over=30 --dupl-threshold=150 \
171171
--exclude=<defaul golangci-lint excludes> --skip=testdata --skip=builtin \
172172
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
173173
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
174-
--enable=interfacer --enable=unconvert --enable=goconst --enable=gas --enable=megacheck
174+
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck
175175
./...
176176
```
177177

pkg/commands/help.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ func (e *Executor) initHelp() {
3333

3434
func printLinterConfigs(lcs []linter.Config) {
3535
for _, lc := range lcs {
36-
fmt.Fprintf(logutils.StdOut, "%s: %s [fast: %t]\n", color.YellowString(lc.Linter.Name()),
37-
lc.Linter.Desc(), !lc.DoesFullImport)
36+
altNamesStr := ""
37+
if len(lc.AlternativeNames) != 0 {
38+
altNamesStr = fmt.Sprintf(" (%s)", strings.Join(lc.AlternativeNames, ", "))
39+
}
40+
fmt.Fprintf(logutils.StdOut, "%s%s: %s [fast: %t]\n", color.YellowString(lc.Name()),
41+
altNamesStr, lc.Linter.Desc(), !lc.DoesFullImport)
3842
}
3943
}
4044

@@ -58,7 +62,7 @@ func (e Executor) executeLintersHelp(cmd *cobra.Command, args []string) {
5862
linters := e.DBManager.GetAllLinterConfigsForPreset(p)
5963
linterNames := []string{}
6064
for _, lc := range linters {
61-
linterNames = append(linterNames, lc.Linter.Name())
65+
linterNames = append(linterNames, lc.Name())
6266
}
6367
fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", "))
6468
}

pkg/commands/linters.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func (e *Executor) initLinters() {
2020
}
2121

2222
func IsLinterInConfigsList(name string, linters []linter.Config) bool {
23-
for _, linter := range linters {
24-
if linter.Linter.Name() == name {
23+
for _, lc := range linters {
24+
if lc.Name() == name {
2525
return true
2626
}
2727
}
@@ -40,7 +40,7 @@ func (e *Executor) executeLinters(cmd *cobra.Command, args []string) {
4040

4141
var disabledLCs []linter.Config
4242
for _, lc := range e.DBManager.GetAllSupportedLinterConfigs() {
43-
if !IsLinterInConfigsList(lc.Linter.Name(), enabledLCs) {
43+
if !IsLinterInConfigsList(lc.Name(), enabledLCs) {
4444
disabledLCs = append(disabledLCs, lc)
4545
}
4646
}

pkg/commands/run.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ func fixSlicesFlags(fs *pflag.FlagSet) {
238238
func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan result.Issue, error) {
239239
e.cfg.Run.Args = args
240240

241-
linters, err := e.EnabledLintersSet.Get()
241+
enabledLinters, err := e.EnabledLintersSet.Get()
242242
if err != nil {
243243
return nil, err
244244
}
245245

246246
for _, lc := range e.DBManager.GetAllSupportedLinterConfigs() {
247247
isEnabled := false
248-
for _, linter := range linters {
249-
if linter.Linter.Name() == lc.Linter.Name() {
248+
for _, enabledLC := range enabledLinters {
249+
if enabledLC.Name() == lc.Name() {
250250
isEnabled = true
251251
break
252252
}
253253
}
254-
e.reportData.AddLinter(lc.Linter.Name(), isEnabled, lc.EnabledByDefault)
254+
e.reportData.AddLinter(lc.Name(), isEnabled, lc.EnabledByDefault)
255255
}
256256

257-
lintCtx, err := lint.LoadContext(linters, e.cfg, e.log.Child("load"))
257+
lintCtx, err := lint.LoadContext(enabledLinters, e.cfg, e.log.Child("load"))
258258
if err != nil {
259259
return nil, errors.Wrap(err, "context loading failed")
260260
}
@@ -264,7 +264,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan resul
264264
return nil, err
265265
}
266266

267-
return runner.Run(ctx, linters, lintCtx), nil
267+
return runner.Run(ctx, enabledLinters, lintCtx), nil
268268
}
269269

270270
func (e *Executor) setOutputToDevNull() (savedStdout, savedStderr *os.File) {

pkg/config/config.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,6 @@ var DefaultExcludePatterns = []ExcludePattern{
4444
Linter: "golint",
4545
Why: "False positive when tests are defined in package 'test'",
4646
},
47-
{
48-
Pattern: "Use of unsafe calls should be audited",
49-
Linter: "gas",
50-
Why: "Too many false-positives on 'unsafe' usage",
51-
},
52-
{
53-
Pattern: "Subprocess launch(ed with variable|ing should be audited)",
54-
Linter: "gas",
55-
Why: "Too many false-positives for parametrized shell calls",
56-
},
57-
{
58-
Pattern: "G104",
59-
Linter: "gas",
60-
Why: "Duplicated errcheck checks",
61-
},
62-
{
63-
Pattern: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)",
64-
Linter: "gas",
65-
Why: "Too many issues in popular repos",
66-
},
67-
{
68-
Pattern: "Potential file inclusion via variable",
69-
Linter: "gas",
70-
Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'",
71-
},
7247
{
7348
Pattern: "(possible misuse of unsafe.Pointer|should have signature)",
7449
Linter: "govet",

pkg/golinters/gas.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
type Gas struct{}
17+
type Gosec struct{}
1818

19-
func (Gas) Name() string {
20-
return "gas"
19+
func (Gosec) Name() string {
20+
return "gosec"
2121
}
2222

23-
func (Gas) Desc() string {
23+
func (Gosec) Desc() string {
2424
return "Inspects source code for security problems"
2525
}
2626

27-
func (lint Gas) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
27+
func (lint Gosec) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
2828
gasConfig := gas.NewConfig()
2929
enabledRules := rules.Generate()
3030
logger := log.New(ioutil.Discard, "", 0)
@@ -45,7 +45,7 @@ func (lint Gas) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
4545
if err != nil {
4646
r = &result.Range{}
4747
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
48-
lintCtx.Log.Warnf("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
48+
lintCtx.Log.Warnf("Can't convert gosec line number %q of %v to int: %s", i.Line, i, err)
4949
continue
5050
}
5151
line = r.From

pkg/golinters/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var replacePatterns = []replacePattern{
5656
{`^(\S+) arg list ends with redundant newline$`, "`${1}` arg list ends with redundant newline"},
5757
{`^(\S+) composite literal uses unkeyed fields$`, "`${1}` composite literal uses unkeyed fields"},
5858

59-
// gas
59+
// gosec
6060
{`^Blacklisted import (\S+): weak cryptographic primitive$`,
6161
"Blacklisted import `${1}`: weak cryptographic primitive"},
6262
{`^TLS InsecureSkipVerify set true.$`, "TLS `InsecureSkipVerify` set true."},

pkg/lint/linter/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Config struct {
1616
NeedsSSARepr bool
1717
InPresets []string
1818
Speed int // more value means faster execution of linter
19+
AlternativeNames []string
1920

2021
OriginalURL string // URL of original (not forked) repo, needed for autogenerated README
2122
}
@@ -46,6 +47,11 @@ func (lc Config) WithURL(url string) Config {
4647
return lc
4748
}
4849

50+
func (lc Config) WithAlternativeNames(names ...string) Config {
51+
lc.AlternativeNames = names
52+
return lc
53+
}
54+
4955
func (lc Config) NeedsProgramLoading() bool {
5056
return lc.DoesFullImport
5157
}
@@ -58,6 +64,14 @@ func (lc Config) GetSpeed() int {
5864
return lc.Speed
5965
}
6066

67+
func (lc Config) AllNames() []string {
68+
return append([]string{lc.Name()}, lc.AlternativeNames...)
69+
}
70+
71+
func (lc Config) Name() string {
72+
return lc.Linter.Name()
73+
}
74+
6175
func NewConfig(linter Linter) *Config {
6276
return &Config{
6377
Linter: linter,

0 commit comments

Comments
 (0)