-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move ginkgo containers logic to the handler
Cleanup the linter code by moving the ginkgo related logic (check for focus containers, and avoid test polution check), to the ginkgo linter package, in order to get cleaner main linter code.
- Loading branch information
Showing
7 changed files
with
382 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ginkgohandler | ||
|
||
import ( | ||
"go/ast" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/nunnatsa/ginkgolinter/types" | ||
) | ||
|
||
// dotHandler is used when importing ginkgo with dot; i.e. | ||
// import . "github.com/onsi/ginkgo" | ||
type dotHandler struct{} | ||
|
||
func (h dotHandler) HandleGinkgoSpecs(expr ast.Expr, config types.Config, pass *analysis.Pass) bool { | ||
return handleGinkgoSpecs(expr, config, pass, h) | ||
} | ||
|
||
func (h dotHandler) getFocusContainerName(exp *ast.CallExpr) (bool, *ast.Ident) { | ||
if fun, ok := exp.Fun.(*ast.Ident); ok { | ||
return isFocusContainer(fun.Name), fun | ||
} | ||
return false, nil | ||
} | ||
|
||
func (h dotHandler) isWrapContainer(exp *ast.CallExpr) bool { | ||
if fun, ok := exp.Fun.(*ast.Ident); ok { | ||
return isWrapContainer(fun.Name) | ||
} | ||
return false | ||
} | ||
|
||
func (h dotHandler) isFocusSpec(exp ast.Expr) bool { | ||
id, ok := exp.(*ast.Ident) | ||
return ok && id.Name == focusSpec | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ginkgohandler | ||
|
||
const ( // container names | ||
describe = "Describe" | ||
pdescribe = "PDescribe" | ||
xdescribe = "XDescribe" | ||
fdescribe = "FDescribe" | ||
|
||
when = "When" | ||
pwhen = "PWhen" | ||
xwhen = "XWhen" | ||
fwhen = "FWhen" | ||
|
||
contextContainer = "Context" | ||
pcontext = "PContext" | ||
xcontext = "XContext" | ||
fcontext = "FContext" | ||
|
||
it = "It" | ||
pit = "PIt" | ||
xit = "XIt" | ||
fit = "FIt" | ||
|
||
describeTable = "DescribeTable" | ||
pdescribeTable = "PDescribeTable" | ||
xdescribeTable = "XDescribeTable" | ||
fdescribeTable = "FDescribeTable" | ||
|
||
entry = "Entry" | ||
pentry = "PEntry" | ||
xentry = "XEntry" | ||
fentry = "FEntry" | ||
) | ||
|
||
func isFocusContainer(name string) bool { | ||
switch name { | ||
case fdescribe, fcontext, fwhen, fit, fdescribeTable, fentry: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func isContainer(name string) bool { | ||
switch name { | ||
case it, when, contextContainer, describe, describeTable, entry, | ||
pit, pwhen, pcontext, pdescribe, pdescribeTable, pentry, | ||
xit, xwhen, xcontext, xdescribe, xdescribeTable, xentry: | ||
return true | ||
} | ||
return isFocusContainer(name) | ||
} | ||
|
||
func isWrapContainer(name string) bool { | ||
switch name { | ||
case when, contextContainer, describe, | ||
fwhen, fcontext, fdescribe, | ||
pwhen, pcontext, pdescribe, | ||
xwhen, xcontext, xdescribe: | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.