We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example code:
//doc:summary reports that you create mocks in an old-fashioned way //doc:before mockReader := &iomocks.Reader{} //doc:after mockReader := iomocks.NewReader(t) func mockConstructor(m dsl.Matcher) { m.Import("github.com/stretchr/testify/mock") m.Match( `$x := &$y{}`, `$x := $y{}`, `$x = &$y{}`, `$x = $y{}`, ). Where( m["x"].Type.Underlying().Is(`struct{$*_; mock.Mock; $*_}`) || m["x"].Filter(embedsMock), ). Report("Use the mock constructor instead of struct initialization") } func embedsMock(ctx *dsl.VarFilterContext) bool { // copy from here - https://github.com/quasilyte/go-ruleguard/blob/7968289708448cdc8ea2fa21d0db203a75d93994/analyzer/testdata/src/quasigo/rules.go#L11-L31 typ := ctx.Type.Underlying() asPointer := types.AsPointer(typ) if asPointer != nil { typ = asPointer.Elem().Underlying() } asStruct := types.AsStruct(typ) if asStruct == nil { return false } mutexType := ctx.GetType(`github.com/stretchr/testify/mock.Mock`) i := 0 for i < asStruct.NumFields() { field := asStruct.Field(i) if field.Embedded() && types.Identical(field.Type(), mutexType) { return true } i++ } return false }
Before using this rule: ~7m After this rule: ~14m
Are there any way to improve it?
The text was updated successfully, but these errors were encountered:
I have a few questions:
Sorry, something went wrong.
No branches or pull requests
Example code:
Before using this rule: ~7m
After this rule: ~14m
Are there any way to improve it?
The text was updated successfully, but these errors were encountered: