Skip to content

Commit 2127a1e

Browse files
committed
Add some documentation for exported functions
Also, make some function not exposed, when not needed.
1 parent 0a85fdc commit 2127a1e

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

ginkgo_linter.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func checkExpression(pass *analysis.Pass, exprSuppress types.Suppress, actualArg
167167
return checkLengthMatcher(assertionExp, pass, handler, oldExpr)
168168
} else {
169169
if nilable, compOp := getNilableFromComparison(actualArg); nilable != nil {
170-
if IsExprError(pass, nilable) {
170+
if isExprError(pass, nilable) {
171171
if exprSuppress.Err {
172172
return true
173173
}
@@ -177,7 +177,7 @@ func checkExpression(pass *analysis.Pass, exprSuppress types.Suppress, actualArg
177177

178178
return checkNilMatcher(assertionExp, pass, nilable, handler, compOp == token.NEQ, oldExpr)
179179

180-
} else if IsExprError(pass, actualArg) {
180+
} else if isExprError(pass, actualArg) {
181181
return bool(exprSuppress.Err) || checkNilError(pass, assertionExp, handler, actualArg, oldExpr)
182182

183183
} else {
@@ -521,26 +521,26 @@ func handleEqualNilMatcher(matcher *ast.CallExpr, pass *analysis.Pass, exp *ast.
521521
return
522522
}
523523

524-
newFuncName, isError := handleNilComparisonErr(pass, exp, nilable)
524+
newFuncName, isItError := handleNilComparisonErr(pass, exp, nilable)
525525

526526
handler.ReplaceFunction(exp.Args[0].(*ast.CallExpr), ast.NewIdent(newFuncName))
527527
exp.Args[0].(*ast.CallExpr).Args = nil
528528

529-
reportNilAssertion(pass, exp, handler, nilable, notEqual, oldExp, isError)
529+
reportNilAssertion(pass, exp, handler, nilable, notEqual, oldExp, isItError)
530530
}
531531

532532
func handleNilBeBoolMatcher(pass *analysis.Pass, exp *ast.CallExpr, handler gomegahandler.Handler, nilable ast.Expr, notEqual bool, oldExp string) {
533-
newFuncName, isError := handleNilComparisonErr(pass, exp, nilable)
533+
newFuncName, isItError := handleNilComparisonErr(pass, exp, nilable)
534534
handler.ReplaceFunction(exp.Args[0].(*ast.CallExpr), ast.NewIdent(newFuncName))
535535
exp.Args[0].(*ast.CallExpr).Args = nil
536536

537-
reportNilAssertion(pass, exp, handler, nilable, notEqual, oldExp, isError)
537+
reportNilAssertion(pass, exp, handler, nilable, notEqual, oldExp, isItError)
538538
}
539539

540540
func handleNilComparisonErr(pass *analysis.Pass, exp *ast.CallExpr, nilable ast.Expr) (string, bool) {
541541
newFuncName := beNil
542-
isError := IsExprError(pass, nilable)
543-
if isError {
542+
isItError := isExprError(pass, nilable)
543+
if isItError {
544544
if _, ok := nilable.(*ast.CallExpr); ok {
545545
newFuncName = succeed
546546
} else {
@@ -549,7 +549,7 @@ func handleNilComparisonErr(pass *analysis.Pass, exp *ast.CallExpr, nilable ast.
549549
}
550550
}
551551

552-
return newFuncName, isError
552+
return newFuncName, isItError
553553
}
554554
func isAssertionFunc(name string) bool {
555555
switch name {
@@ -565,7 +565,7 @@ func reportLengthAssertion(pass *analysis.Pass, expr *ast.CallExpr, handler gome
565565
report(pass, expr, wrongLengthWarningTemplate, oldExpr)
566566
}
567567

568-
func reportNilAssertion(pass *analysis.Pass, expr *ast.CallExpr, handler gomegahandler.Handler, nilable ast.Expr, notEqual bool, oldExpr string, isError bool) {
568+
func reportNilAssertion(pass *analysis.Pass, expr *ast.CallExpr, handler gomegahandler.Handler, nilable ast.Expr, notEqual bool, oldExpr string, isItError bool) {
569569
changed := replaceNilActualArg(expr.Fun.(*ast.SelectorExpr).X.(*ast.CallExpr), handler, nilable)
570570
if !changed {
571571
return
@@ -575,7 +575,7 @@ func reportNilAssertion(pass *analysis.Pass, expr *ast.CallExpr, handler gomegah
575575
reverseAssertionFuncLogic(expr)
576576
}
577577
template := wrongNilWarningTemplate
578-
if isError {
578+
if isItError {
579579
template = wrongErrWarningTemplate
580580
}
581581

@@ -636,22 +636,22 @@ func init() {
636636
errorType = gotypes.Universe.Lookup("error").Type().Underlying().(*gotypes.Interface)
637637
}
638638

639-
func IsError(t gotypes.Type) bool {
639+
func isError(t gotypes.Type) bool {
640640
return gotypes.Implements(t, errorType)
641641
}
642642

643-
func IsExprError(pass *analysis.Pass, expr ast.Expr) bool {
643+
func isExprError(pass *analysis.Pass, expr ast.Expr) bool {
644644
actualArgType := pass.TypesInfo.TypeOf(expr)
645645
switch t := actualArgType.(type) {
646646
case *gotypes.Named:
647-
if IsError(actualArgType) {
647+
if isError(actualArgType) {
648648
return true
649649
}
650650
case *gotypes.Tuple:
651651
if t.Len() > 0 {
652652
switch t0 := t.At(0).Type().(type) {
653653
case *gotypes.Named, *gotypes.Pointer:
654-
if IsError(t0) {
654+
if isError(t0) {
655655
return true
656656
}
657657
}

gomegahandler/handler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package gomegahandler
33
import "go/ast"
44

55
// Handler provide different handling, depend on the way gomega was imported, whether
6-
// in imported with "." name, custome name or without any name.
6+
// in imported with "." name, custom name or without any name.
77
type Handler interface {
8+
// GetActualFuncName returns the name of the gomega function, e.g. `Expect`
89
GetActualFuncName(*ast.CallExpr) (string, bool)
10+
// ReplaceFunction replaces the function with another one, for fix suggestions
911
ReplaceFunction(*ast.CallExpr, *ast.Ident)
1012
}
1113

@@ -31,9 +33,9 @@ func GetGomegaHandler(file *ast.File) Handler {
3133

3234
// dotHandler is used when importing gomega with dot; i.e.
3335
// import . "github.com/onsi/gomega"
34-
//
3536
type dotHandler struct{}
3637

38+
// GetActualFuncName returns the name of the gomega function, e.g. `Expect`
3739
func (dotHandler) GetActualFuncName(expr *ast.CallExpr) (string, bool) {
3840
actualFunc, ok := expr.Fun.(*ast.Ident)
3941
if !ok {
@@ -43,6 +45,7 @@ func (dotHandler) GetActualFuncName(expr *ast.CallExpr) (string, bool) {
4345
return actualFunc.Name, true
4446
}
4547

48+
// ReplaceFunction replaces the function with another one, for fix suggestions
4649
func (dotHandler) ReplaceFunction(caller *ast.CallExpr, newExpr *ast.Ident) {
4750
caller.Fun = newExpr
4851
}
@@ -52,9 +55,9 @@ func (dotHandler) ReplaceFunction(caller *ast.CallExpr, newExpr *ast.Ident) {
5255
//
5356
// or with a custom name; e.g.
5457
// import customname "github.com/onsi/gomega"
55-
//
5658
type nameHandler string
5759

60+
// GetActualFuncName returns the name of the gomega function, e.g. `Expect`
5861
func (g nameHandler) GetActualFuncName(expr *ast.CallExpr) (string, bool) {
5962
selector, ok := expr.Fun.(*ast.SelectorExpr)
6063
if !ok {
@@ -73,6 +76,7 @@ func (g nameHandler) GetActualFuncName(expr *ast.CallExpr) (string, bool) {
7376
return selector.Sel.Name, true
7477
}
7578

79+
// ReplaceFunction replaces the function with another one, for fix suggestions
7680
func (nameHandler) ReplaceFunction(caller *ast.CallExpr, newExpr *ast.Ident) {
7781
caller.Fun.(*ast.SelectorExpr).Sel = newExpr
7882
}

0 commit comments

Comments
 (0)