mirror of
https://github.com/mgechev/revive.git
synced 2024-11-24 08:32:22 +02:00
Add revive linting action and fix linting errors (#455)
This commit is contained in:
parent
0aef3046fa
commit
688024a5ca
25
.github/workflows/lint.yaml
vendored
Normal file
25
.github/workflows/lint.yaml
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
name: Lint
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run Revive Action
|
||||
uses: morphy2k/revive-action@v1.3.3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
@ -1,5 +1,5 @@
|
||||
language: go
|
||||
go: 1.11.x
|
||||
go: 1.14.x
|
||||
node_js: 11.15.0
|
||||
before_install:
|
||||
- openssl aes-256-cbc -K $encrypted_ff954c97a679_key -iv $encrypted_ff954c97a679_iv -in .docs-deploy-key.pem.enc -out .docs-deploy-key -d
|
||||
|
1
go.sum
1
go.sum
@ -95,6 +95,7 @@ golang.org/x/tools v0.0.0-20200725200936-102e7d357031 h1:VtIxiVHWPhnny2ZTi4f9/2d
|
||||
golang.org/x/tools v0.0.0-20200725200936-102e7d357031/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200727233628-55644ead90ce h1:HEwYEPqqa3/M0N2Q6IgtBaf2CaxvmRiVdAhX6LR7uE4=
|
||||
golang.org/x/tools v0.0.0-20200727233628-55644ead90ce/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6 h1:qKpj8TpV+LEhel7H/fR788J+KvhWZ3o3V6N2fU/iuLU=
|
||||
golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200805155214-75c71030ab24 h1:KYaPFhtmIniMIwJjkFkLct9w+TL7RGb7O4BGAHEJVhA=
|
||||
golang.org/x/tools v0.0.0-20200805155214-75c71030ab24/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
|
@ -109,7 +109,7 @@ func (v *cognitiveComplexityVisitor) Visit(n ast.Node) ast.Visitor {
|
||||
return nil // skip visiting binexp sub-tree (already visited by binExpComplexity)
|
||||
case *ast.BranchStmt:
|
||||
if n.Label != nil {
|
||||
v.complexity += 1
|
||||
v.complexity++
|
||||
}
|
||||
}
|
||||
// TODO handle (at least) direct recursion
|
||||
|
@ -28,12 +28,12 @@ func (r *UnconditionalRecursionRule) Name() string {
|
||||
}
|
||||
|
||||
type funcDesc struct {
|
||||
reciverId *ast.Ident
|
||||
reciverID *ast.Ident
|
||||
id *ast.Ident
|
||||
}
|
||||
|
||||
func (fd *funcDesc) equal(other *funcDesc) bool {
|
||||
receiversAreEqual := (fd.reciverId == nil && other.reciverId == nil) || fd.reciverId != nil && other.reciverId != nil && fd.reciverId.Name == other.reciverId.Name
|
||||
receiversAreEqual := (fd.reciverID == nil && other.reciverID == nil) || fd.reciverID != nil && other.reciverID != nil && fd.reciverID.Name == other.reciverID.Name
|
||||
idsAreEqual := (fd.id == nil && other.id == nil) || fd.id.Name == other.id.Name
|
||||
|
||||
return receiversAreEqual && idsAreEqual
|
||||
@ -69,26 +69,26 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor {
|
||||
|
||||
w.currentFunc = &funcStatus{&funcDesc{rec, n.Name}, false}
|
||||
case *ast.CallExpr:
|
||||
var funcId *ast.Ident
|
||||
var funcID *ast.Ident
|
||||
var selector *ast.Ident
|
||||
switch c := n.Fun.(type) {
|
||||
case *ast.Ident:
|
||||
selector = nil
|
||||
funcId = c
|
||||
funcID = c
|
||||
case *ast.SelectorExpr:
|
||||
var ok bool
|
||||
selector, ok = c.X.(*ast.Ident)
|
||||
if !ok { // a.b....Foo()
|
||||
return nil
|
||||
}
|
||||
funcId = c.Sel
|
||||
funcID = c.Sel
|
||||
default:
|
||||
return w
|
||||
}
|
||||
|
||||
if w.currentFunc != nil && // not in a func body
|
||||
!w.currentFunc.seenConditionalExit && // there is a conditional exit in the function
|
||||
w.currentFunc.funcDesc.equal(&funcDesc{selector, funcId}) {
|
||||
w.currentFunc.funcDesc.equal(&funcDesc{selector, funcID}) {
|
||||
w.onFailure(lint.Failure{
|
||||
Category: "logic",
|
||||
Confidence: 1,
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type UnusedReceiverRule struct{}
|
||||
|
||||
// Apply applies the rule to given file.
|
||||
func (_ *UnusedReceiverRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
func (*UnusedReceiverRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
var failures []lint.Failure
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
@ -26,7 +26,7 @@ func (_ *UnusedReceiverRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fai
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (_ *UnusedReceiverRule) Name() string {
|
||||
func (*UnusedReceiverRule) Name() string {
|
||||
return "unused-receiver"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user