Skip to content

Commit 529618c

Browse files
committed
fix linter issues
1 parent 845eb92 commit 529618c

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ jobs:
3333

3434
- name: Run Unit tests
3535
run: |
36-
go test -race -covermode atomic -coverprofile=covprofile ./...
37-
- name: Install goveralls
38-
run: go get github.com/mattn/goveralls
39-
- name: Send coverage
40-
env:
41-
COVERALLS_TOKEN: ${{ secrets.github_token }}
42-
run: goveralls -coverprofile=covprofile -service=github
36+
go test -race ./...
4337
4438
- name: Check it's own cyclomatic complexity
4539
run: go run ./cmd/cyclop/ ./pkg/analyzer/

.golangci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
run:
2-
skip-dirs:
3-
- pkg/analyzer/testdata
1+
issues.exclude-dirs:
2+
- pkg/analyzer/testdata
43

54
linters-settings:
65
golint:
@@ -18,9 +17,10 @@ linters:
1817
- prealloc
1918
- dupl
2019
- wsl
20+
- depguard
21+
- nilnil
22+
- exhaustruct
2123
- nlreturn
22-
- goerr113
23-
- exhaustivestruct
2424
- paralleltest
2525
- testpackage
2626
- gomnd

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Cyclop calculates cyclomatic complexities of functions in Go source code.
22
// Simple usage:
33
//
4-
// cyclop .
4+
// cyclop .
55
//
66
// Read more about usage in https://github.com/bkielbasa/cyclop/blob/master/README.md
77
package main

pkg/analyzer/analyzer.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ var (
1919
skipTests bool
2020
)
2121

22+
const (
23+
defaultMaxComplexity = 10
24+
)
25+
2226
//nolint:gochecknoinits
2327
func init() {
24-
flagSet.IntVar(&maxComplexity, "maxComplexity", 10, "max complexity the function can have")
28+
flagSet.IntVar(&maxComplexity, "maxComplexity", defaultMaxComplexity, "max complexity the function can have")
2529
flagSet.Float64Var(&packageAverage, "packageAverage", 0, "max average complexity in package")
2630
flagSet.BoolVar(&skipTests, "skipTests", false, "should the linter execute on test files as well")
2731
}
@@ -40,9 +44,9 @@ func run(pass *analysis.Pass) (interface{}, error) {
4044
var pkgName string
4145
var pkgPos token.Pos
4246

43-
for _, f := range pass.Files {
44-
ast.Inspect(f, func(node ast.Node) bool {
45-
f, ok := node.(*ast.FuncDecl)
47+
for _, file := range pass.Files {
48+
ast.Inspect(file, func(node ast.Node) bool {
49+
funcDecl, ok := node.(*ast.FuncDecl)
4650
if !ok {
4751
if node == nil {
4852
return true
@@ -55,15 +59,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
5559
return true
5660
}
5761

58-
if skipTests && testFunc(f) {
62+
if skipTests && testFunc(funcDecl) {
5963
return true
6064
}
6165

6266
count++
63-
comp := complexity(f)
67+
comp := complexity(funcDecl)
6468
sum += float64(comp)
6569
if comp > maxComplexity {
66-
pass.Reportf(node.Pos(), "calculated cyclomatic complexity for function %s is %d, max is %d", f.Name.Name, comp, maxComplexity)
70+
pass.Reportf(node.Pos(), "calculated cyclomatic complexity for function %s is %d, max is %d", file.Name.Name, comp, maxComplexity)
6771
}
6872

6973
return true

pkg/analyzer/analyzer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ import (
99
)
1010

1111
func TestAll(t *testing.T) {
12-
wd, err := os.Getwd()
12+
path, err := os.Getwd()
1313
if err != nil {
1414
t.Fatalf("Failed to get wd: %s", err)
1515
}
1616

1717
skipTests = false
1818

19-
testdata := filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata")
19+
testdata := filepath.Join(filepath.Dir(filepath.Dir(path)), "testdata")
2020
analysistest.Run(t, testdata, NewAnalyzer(), "p")
2121
}
2222

2323
func TestIfTestFunctionsAreSkipped(t *testing.T) {
24-
wd, err := os.Getwd()
24+
path, err := os.Getwd()
2525
if err != nil {
2626
t.Fatalf("Failed to get wd: %s", err)
2727
}
2828

2929
skipTests = true
3030

31-
testdata := filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata")
31+
testdata := filepath.Join(filepath.Dir(filepath.Dir(path)), "testdata")
3232
analysistest.Run(t, testdata, NewAnalyzer(), "tests")
3333
}
3434

3535
func TestAverageComplexityOfAPackage(t *testing.T) {
36-
wd, err := os.Getwd()
36+
path, err := os.Getwd()
3737
if err != nil {
3838
t.Fatalf("Failed to get wd: %s", err)
3939
}
4040

4141
skipTests = false
4242
packageAverage = 5
4343

44-
testdata := filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata")
44+
testdata := filepath.Join(filepath.Dir(filepath.Dir(path)), "testdata")
4545
analysistest.Run(t, testdata, NewAnalyzer(), "avg")
4646
}

0 commit comments

Comments
 (0)