Skip to content

Commit a6b91cc

Browse files
committed
Fix #124: support unparam linter
1. Support unparam linter and fix found issues 2. Replace forked mvdan.cc/lint and mvdan.cc/interfacer with the upstream ones 3. Minimize forked megacheck: move the most of it's code to this repo 4. Use golang.org/x/tools/go/ssa import path instead of custom fork paths 5. In golang.org/x/tools/go/{ssa,callgraph} use changed code from honnef.co/go/tools 6. Add megacheck.check-unexported option: it found some issues in the repo, fixed them all
1 parent 70193b9 commit a6b91cc

Some content is hidden

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

97 files changed

+1842
-442
lines changed

Diff for: .golangci.example.yml

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ run:
3636
- ".*\\.my\\.go$"
3737
- lib/bad.go
3838

39+
3940
# output configuration options
4041
output:
4142
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
@@ -47,6 +48,7 @@ output:
4748
# print linter name in the end of issue text, default is true
4849
print-linter-name: true
4950

51+
5052
# all available settings of specific linters
5153
linters-settings:
5254
errcheck:
@@ -107,6 +109,23 @@ linters-settings:
107109
lll:
108110
# max line length, lines longer will be reported. Default is 120. '\t' is counted as 1 character.
109111
line-length: 120
112+
unused:
113+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
114+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
115+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
116+
# with golangci-lint call it on a directory with the changed file.
117+
check-exported: false
118+
unparam:
119+
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
120+
# and rta for programs with main packages. Default is cha.
121+
algo: cha
122+
123+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
124+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
125+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
126+
# with golangci-lint call it on a directory with the changed file.
127+
check-exported: false
128+
110129

111130
linters:
112131
enable:
@@ -121,6 +140,7 @@ linters:
121140
- unused
122141
fast: false
123142

143+
124144
issues:
125145
# List of regexps of issue texts to exclude, empty list by default.
126146
# But independently from this option we use default exclude patterns,

Diff for: Gopkg.lock

+41-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Gopkg.toml

+11-36
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
21-
#
22-
# [prune]
23-
# non-go = false
24-
# go-tests = true
25-
# unused-packages = true
26-
27-
281
[[constraint]]
292
name = "github.com/golangci/revgrep"
303
branch = "master"
@@ -52,9 +25,9 @@
5225
source = "github.com/golangci/dupl"
5326

5427
[[constraint]]
55-
name = "mvdan.cc/interfacer"
28+
name = "mvdan.cc/unparam"
5629
branch = "master"
57-
source = "github.com/golangci/interfacer"
30+
source = "github.com/golangci/unparam"
5831

5932
[[constraint]]
6033
name = "github.com/GoASTScanner/gas"
@@ -73,10 +46,6 @@
7346
branch = "master"
7447
name = "github.com/mitchellh/go-ps"
7548

76-
[[constraint]]
77-
branch = "master"
78-
name = "github.com/golangci/go-tools"
79-
8049
[[constraint]]
8150
branch = "master"
8251
name = "github.com/golangci/unconvert"
@@ -109,10 +78,16 @@
10978
branch = "master"
11079
name = "github.com/golangci/ineffassign"
11180

112-
[[override]]
81+
[[constraint]]
11382
branch = "master"
114-
name = "github.com/golangci/lint"
83+
name = "github.com/OpenPeeDeeP/depguard"
11584

11685
[[constraint]]
11786
branch = "master"
118-
name = "github.com/OpenPeeDeeP/depguard"
87+
name = "golang.org/x/tools"
88+
source = "github.com/golangci/tools"
89+
90+
[[constraint]]
91+
branch = "master"
92+
name = "honnef.co/go/tools"
93+
source = "github.com/golangci/go-tools"

Diff for: README.md

+22
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ megacheck: 3 sub-linters in one: unused, gosimple and staticcheck [fast: false]
122122
depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: false]
123123
misspell: Finds commonly misspelled English words in comments [fast: true]
124124
lll: Reports long lines [fast: true]
125+
unparam: Reports unused function parameters [fast: false]
125126
```
126127

127128
Pass `-E/--enable` to enable linter and `-D/--disable` to disable:
@@ -229,6 +230,7 @@ golangci-lint linters
229230
- [depguard](https://github.com/OpenPeeDeeP/depguard) - Go linter that checks if package imports are in a list of acceptable packages
230231
- [misspell](https://github.com/client9/misspell) - Finds commonly misspelled English words in comments
231232
- [lll](https://github.com/walle/lll) - Reports long lines
233+
- [unparam](https://github.com/mvdan/unparam) - Reports unused function parameters
232234

233235
# Configuration
234236
The config file has lower priority than command-line options. If the same bool/string/int option is provided on the command-line
@@ -363,6 +365,7 @@ run:
363365
- ".*\\.my\\.go$"
364366
- lib/bad.go
365367

368+
366369
# output configuration options
367370
output:
368371
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
@@ -374,6 +377,7 @@ output:
374377
# print linter name in the end of issue text, default is true
375378
print-linter-name: true
376379

380+
377381
# all available settings of specific linters
378382
linters-settings:
379383
errcheck:
@@ -434,6 +438,23 @@ linters-settings:
434438
lll:
435439
# max line length, lines longer will be reported. Default is 120. '\t' is counted as 1 character.
436440
line-length: 120
441+
unused:
442+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
443+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
444+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
445+
# with golangci-lint call it on a directory with the changed file.
446+
check-exported: false
447+
unparam:
448+
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
449+
# and rta for programs with main packages. Default is cha.
450+
algo: cha
451+
452+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
453+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
454+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
455+
# with golangci-lint call it on a directory with the changed file.
456+
check-exported: false
457+
437458

438459
linters:
439460
enable:
@@ -448,6 +469,7 @@ linters:
448469
- unused
449470
fast: false
450471

472+
451473
issues:
452474
# List of regexps of issue texts to exclude, empty list by default.
453475
# But independently from this option we use default exclude patterns,

Diff for: pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan resul
237237
e.reportData.AddLinter(lc.Linter.Name(), isEnabled, lc.EnabledByDefault)
238238
}
239239

240-
lintCtx, err := lint.LoadContext(ctx, linters, e.cfg, e.log.Child("load"))
240+
lintCtx, err := lint.LoadContext(linters, e.cfg, e.log.Child("load"))
241241
if err != nil {
242242
return nil, err
243243
}

Diff for: pkg/config/config.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"time"
55
)
66

7-
type OutFormat string
8-
97
const (
108
OutFormatJSON = "json"
119
OutFormatLineNumber = "line-number"
@@ -158,7 +156,12 @@ type LintersSettings struct {
158156
Misspell struct {
159157
Locale string
160158
}
161-
Lll LllSettings
159+
Unused struct {
160+
CheckExported bool `mapstructure:"check-exported"`
161+
}
162+
163+
Lll LllSettings
164+
Unparam UnparamSettings
162165
}
163166

164167
type LllSettings struct {
@@ -169,6 +172,14 @@ var defaultLintersSettings = LintersSettings{
169172
Lll: LllSettings{
170173
LineLength: 120,
171174
},
175+
Unparam: UnparamSettings{
176+
Algo: "cha",
177+
},
178+
}
179+
180+
type UnparamSettings struct {
181+
CheckExported bool `mapstructure:"check-exported"`
182+
Algo string
172183
}
173184

174185
type Linters struct {

Diff for: pkg/golinters/govet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func runGoCommand(ctx context.Context, log logutils.Log, args ...string) error {
216216
return nil
217217
}
218218

219-
func (g Govet) runOnSourcePackages(ctx context.Context, lintCtx *linter.Context) ([]govetAPI.Issue, error) {
219+
func (g Govet) runOnSourcePackages(_ context.Context, lintCtx *linter.Context) ([]govetAPI.Issue, error) {
220220
// TODO: check .S asm files: govet can do it if pass dirs
221221
var govetIssues []govetAPI.Issue
222222
for _, pkg := range lintCtx.Program.InitialPackages() {

0 commit comments

Comments
 (0)