Skip to content

Commit

Permalink
fix: typo and lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and bkielbasa committed Feb 16, 2021
1 parent f557288 commit 2b4177f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Flags:
-memprofile string
write memory profile to this file
-packageAverage float
max avarage complexity in package
max average complexity in package
-skipTests
should the linter execute on test files as well
-source
Expand All @@ -54,5 +54,5 @@ Flags:

Important parameters are:
* `-maxComplexity int` - the max complexity calculated for a single function. `10` by default
* `-packageAvarage float64` - the average cyclomatic complexity for a package. If the value is higher than `0` it will reaise an error if the average will be higher. `0` default.
* `-packageAverage float64` - the average cyclomatic complexity for a package. If the value is higher than `0` it will reaise an error if the average will be higher. `0` default.
* `-skipTests bool` - should checks be executed in tests files. `false` by default
25 changes: 14 additions & 11 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ import (
"golang.org/x/tools/go/analysis"
)

//nolint:gochecknoglobals
var flagSet flag.FlagSet

//nolint:gochecknoglobals
var (
flagSet flag.FlagSet
maxComplexity int
packageAverage float64
skipTests bool
)

var maxComplexity int
var packageAverage float64
var skipTests bool
//nolint:gochecknoinits
func init() {
flagSet.IntVar(&maxComplexity, "maxComplexity", 10, "max complexity the function can have")
flagSet.Float64Var(&packageAverage, "packageAverage", 0, "max average complexity in package")
flagSet.BoolVar(&skipTests, "skipTests", false, "should the linter execute on test files as well")
}

func NewAnalyzer() *analysis.Analyzer {
return &analysis.Analyzer{
Expand All @@ -26,12 +35,6 @@ func NewAnalyzer() *analysis.Analyzer {
}
}

func init() {
flagSet.IntVar(&maxComplexity, "maxComplexity", 10, "max complexity the function can have")
flagSet.Float64Var(&packageAverage, "packageAverage", 0, "max avarage complexity in package")
flagSet.BoolVar(&skipTests, "skipTests", false, "should the linter execute on test files as well")
}

func run(pass *analysis.Pass) (interface{}, error) {
var sum, count float64
var pkgName string
Expand Down Expand Up @@ -70,7 +73,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
if packageAverage > 0 {
avg := sum / count
if avg > packageAverage {
pass.Reportf(pkgPos, "the avarage complexity for the package %s is %f, max is %f", pkgName, avg, packageAverage)
pass.Reportf(pkgPos, "the average complexity for the package %s is %f, max is %f", pkgName, avg, packageAverage)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestIfTestFunctionsAreSkipped(t *testing.T) {
analysistest.Run(t, testdata, NewAnalyzer(), "tests")
}

func TestAvarageComplexityOfAPackage(t *testing.T) {
func TestAverageComplexityOfAPackage(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get wd: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion testdata/src/avg/tests_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package avg // want "the avarage complexity for the package avg"
package avg // want "the average complexity for the package avg"

func complexityIs10() {
i := 1
Expand Down

0 comments on commit 2b4177f

Please sign in to comment.