Repository: mgechev/revive (go)

Issue:
Add golint package name MixedCaps rule
**Is your feature request related to a problem? Please describe.**
I have been using revive as a "drop-in replacement for golint" but recently noticed revive did not detect an issue I remembered golint used to raise. golint has a rule to check for MixedCaps package names, added in https://github.com/golang/lint/pull/285 and implemented in https://github.com/golang/lint/blob/83fdc39ff7b56453e3793356bcff3070b9b96445/lint.go#L561-L563

**Describe the solution you'd like**
It would be great to have revive's var-naming rule also perform a check for MixedCaps package names.

**Describe alternatives you've considered**
I've considered re-enabling golint and running it alongside revive but that would result in duplicate linter suggestions.

**Additional context**
PR to follow.

Pull request description:
add golint's package name MixedCaps rule
This adds the implementation of golint's package name MixedCaps check from https://github.com/golang/lint/pull/285 as well as the [same testdata file used in golint, pkg-caps.go](https://github.com/golang/lint/blob/master/testdata/pkg-caps.go). Slightly improves "drop-in replacement for golint" story for golint's `lintNames()` rules.

Closes #796

Patch:
diff --git a/go.mod b/go.mod
index b5409b5..ce13764 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.19
 
 require (
 	github.com/BurntSushi/toml v1.2.1
-	github.com/chavacava/garif v0.0.0-20221024190013-b3ef35877348
+	github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8
 	github.com/fatih/color v1.14.1
 	github.com/fatih/structtag v1.2.0
 	github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
diff --git a/go.sum b/go.sum
index 278f230..7bb8a1d 100644
--- a/go.sum
+++ b/go.sum
@@ -6,6 +6,8 @@ github.com/chavacava/garif v0.0.0-20220630083739-93517212f375 h1:E7LT642ysztPWE0
 github.com/chavacava/garif v0.0.0-20220630083739-93517212f375/go.mod h1:4m1Rv7xfuwWPNKXlThldNuJvutYM6J95wNuuVmn55To=
 github.com/chavacava/garif v0.0.0-20221024190013-b3ef35877348 h1:cy5GCEZLUCshCGCRRUjxHrDUqkB4l5cuUt3ShEckQEo=
 github.com/chavacava/garif v0.0.0-20221024190013-b3ef35877348/go.mod h1:f/miWtG3SSuTxKsNK3o58H1xl+XV6ZIfbC6p7lPPB8U=
+github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 h1:W9o46d2kbNL06lq7UNDPV0zYLzkrde/bjIqO02eoll0=
+github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8/go.mod h1:gakxgyXaaPkxvLw1XQxNGK4I37ys9iBRzNUx/B7pUCo=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -44,6 +46,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
diff --git a/rule/var-naming.go b/rule/var-naming.go
index 3c0c19c..fa4a188 100644
--- a/rule/var-naming.go
+++ b/rule/var-naming.go
@@ -4,12 +4,15 @@ import (
 	"fmt"
 	"go/ast"
 	"go/token"
+	"regexp"
 	"strings"
 	"sync"
 
 	"github.com/mgechev/revive/lint"
 )
 
+var anyCapsRE = regexp.MustCompile(`[A-Z]`)
+
 // VarNamingRule lints given else constructs.
 type VarNamingRule struct {
 	configured bool
@@ -60,6 +63,14 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
 			Category:   "naming",
 		})
 	}
+	if anyCapsRE.MatchString(walker.fileAst.Name.Name) {
+		walker.onFailure(lint.Failure{
+			Failure:    fmt.Sprintf("don't use MixedCaps in package name; %s should be %s", walker.fileAst.Name.Name, strings.ToLower(walker.fileAst.Name.Name)),
+			Confidence: 1,
+			Node:       walker.fileAst.Name,
+			Category:   "naming",
+		})
+	}
 
 	ast.Walk(&walker, fileAst)
 


Test patch:
diff --git a/testdata/golint/pkg-caps.go b/testdata/golint/pkg-caps.go
new file mode 100644
index 0000000..e8ca0b7
--- /dev/null
+++ b/testdata/golint/pkg-caps.go
@@ -0,0 +1,4 @@
+// MixedCaps package name
+
+// Package PkgName ...
+package PkgName // MATCH /don't use MixedCaps in package name; PkgName should be pkgname/