Skip to content

Commit

Permalink
ci: add reviewdog (zeromicro#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Sep 29, 2021
1 parent 80e3407 commit 65905b9
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 86 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: reviewdog
on: [pull_request]
jobs:
staticcheck:
name: runner / staticcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-staticcheck@v1
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Report all results.
filter_mode: nofilter
# Exit with 1 when it find at least one finding.
fail_on_error: true
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1019,-SA1029,-SA5008
8 changes: 4 additions & 4 deletions core/fx/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ func assetEqual(t *testing.T, except, data interface{}) {

func TestStream_AnyMach(t *testing.T) {
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item interface{}) bool {
return 4 == item.(int)
return item.(int) == 4
}))
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item interface{}) bool {
return 0 == item.(int)
return item.(int) == 0
}))
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item interface{}) bool {
return 2 == item.(int)
return item.(int) == 2
}))
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item interface{}) bool {
return 2 == item.(int)
return item.(int) == 2
}))
}

Expand Down
1 change: 0 additions & 1 deletion core/logx/rotatelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type (
done chan lang.PlaceholderType
rule RotateRule
compress bool
keepDays int
// can't use threading.RoutineGroup because of cycle import
waitGroup sync.WaitGroup
closeOnce sync.Once
Expand Down
4 changes: 3 additions & 1 deletion core/stat/internal/cpu_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

func TestRefreshCpu(t *testing.T) {
assert.True(t, RefreshCpu() >= 0)
assert.NotPanics(t, func() {
RefreshCpu()
})
}

func BenchmarkRefreshCpu(b *testing.B) {
Expand Down
6 changes: 2 additions & 4 deletions core/syncx/donechan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ func TestDoneChanDone(t *testing.T) {

waitGroup.Add(1)
go func() {
select {
case <-doneChan.Done():
waitGroup.Done()
}
<-doneChan.Done()
waitGroup.Done()
}()

for i := 0; i < 5; i++ {
Expand Down
2 changes: 0 additions & 2 deletions core/syncx/spinlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ func TestSpinLockRace(t *testing.T) {
var wait sync.WaitGroup
wait.Add(1)
go func() {
lock.Lock()
lock.Unlock()
wait.Done()
}()
time.Sleep(time.Millisecond * 100)
Expand Down
3 changes: 2 additions & 1 deletion rest/handler/authhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func TestAuthHandlerFailed(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
handler := Authorize("B63F477D-BBA3-4E52-96D3-C0034C27694A", WithUnauthorizedCallback(
func(w http.ResponseWriter, r *http.Request, err error) {
w.Header().Set("X-Test", "test")
assert.NotNil(t, err)
w.Header().Set("X-Test", err.Error())
w.WriteHeader(http.StatusUnauthorized)
_, err = w.Write([]byte("content"))
assert.Nil(t, err)
Expand Down
3 changes: 1 addition & 2 deletions rest/handler/contentsecurityhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ func TestContentSecurityHandler_UnsignedCallback_WrongTime(t *testing.T) {
})
handler := contentSecurityHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))

var reader io.Reader
reader = strings.NewReader("hello")
reader := strings.NewReader("hello")
setting := requestSettings{
method: http.MethodPost,
url: "http://localhost/a/b?c=d&e=f",
Expand Down
5 changes: 2 additions & 3 deletions tools/goctl/api/gogen/genroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
}
middleware := g.GetAnnotation("middleware")
if len(middleware) > 0 {
for _, item := range strings.Split(middleware, ",") {
groupedRoutes.middlewares = append(groupedRoutes.middlewares, item)
}
groupedRoutes.middlewares = append(groupedRoutes.middlewares,
strings.Split(middleware, ",")...)
}
routes = append(routes, groupedRoutes)
}
Expand Down
6 changes: 0 additions & 6 deletions tools/goctl/api/gogen/gensvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ func genServiceContext(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpe
return err
}

authNames := getAuths(api)
var auths []string
for _, item := range authNames {
auths = append(auths, fmt.Sprintf("%s config.AuthConfig", item))
}

var middlewareStr string
var middlewareAssignment string
middlewares := getMiddleware(api)
Expand Down
6 changes: 1 addition & 5 deletions tools/goctl/api/javagen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ func JavaCommand(c *cli.Context) error {
return err
}

packetName := api.Service.Name
if strings.HasSuffix(packetName, "-api") {
packetName = packetName[:len(packetName)-4]
}

packetName := strings.TrimSuffix(api.Service.Name, "-api")
logx.Must(util.MkdirIfNotExist(dir))
logx.Must(genPacket(dir, packetName, api))
logx.Must(genComponents(dir, packetName, api))
Expand Down
5 changes: 1 addition & 4 deletions tools/goctl/api/javagen/genpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ func processUri(route spec.Route) string {
}
}
}
result := builder.String()
if strings.HasSuffix(result, " + \"") {
result = result[:len(result)-4]
}
result := strings.TrimSuffix(builder.String(), " + \"")
if strings.HasPrefix(result, "/") {
result = strings.TrimPrefix(result, "/")
result = "\"" + result
Expand Down
3 changes: 0 additions & 3 deletions tools/goctl/api/parser/g4/ast/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sort"

"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
"github.com/tal-tech/go-zero/tools/goctl/api/util"
)

type (
Expand Down Expand Up @@ -155,8 +154,6 @@ func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) interface{} {
var st TypeStruct
st.Name = v.newExprWithToken(ctx.GetStructName())

if util.UnExport(ctx.GetStructName().GetText()) {
}
if ctx.GetStructToken() != nil {
structExpr := v.newExprWithToken(ctx.GetStructToken())
structTokenText := ctx.GetStructToken().GetText()
Expand Down
6 changes: 0 additions & 6 deletions tools/goctl/api/parser/g4/gen/api/apiparser_parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tools/goctl/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/logrusorgru/aurora"
"github.com/tal-tech/go-zero/tools/goctl/util"
ctlutil "github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -128,7 +127,7 @@ func generateDockerfile(goFile string, port int, args ...string) error {
}
defer out.Close()

text, err := ctlutil.LoadTemplate(category, dockerTemplateFile, dockerTemplate)
text, err := util.LoadTemplate(category, dockerTemplateFile, dockerTemplate)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions tools/goctl/model/sql/builderx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func RawFieldNames(in interface{}, postgresSql ...bool) []string {
fi := typ.Field(i)
if tagv := fi.Tag.Get(dbTag); tagv != "" {
if pg {
out = append(out, fmt.Sprintf("%s", tagv))
out = append(out, tagv)
} else {
out = append(out, fmt.Sprintf("`%s`", tagv))
}
} else {
if pg {
out = append(out, fmt.Sprintf("%s", fi.Name))
out = append(out, fi.Name)
} else {
out = append(out, fmt.Sprintf("`%s`", fi.Name))
}
Expand Down
22 changes: 0 additions & 22 deletions tools/goctl/model/sql/gen/split.go

This file was deleted.

10 changes: 0 additions & 10 deletions tools/goctl/model/sql/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ import (
// ErrNotFound is the alias of sql.ErrNoRows
var ErrNotFound = sql.ErrNoRows

func desensitize(datasource string) string {
// remove account
pos := strings.LastIndex(datasource, "@")
if 0 <= pos && pos+1 < len(datasource) {
datasource = datasource[pos+1:]
}

return datasource
}

func escape(input string) string {
var b strings.Builder

Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/rpc/generator/genpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto
_, err = execx.Run(command, "")
if err != nil {
if strings.Contains(err.Error(), googleProtocGenGoErr) {
return errors.New(`Unsupported plugin protoc-gen-go which installed from the following source:
return errors.New(`unsupported plugin protoc-gen-go which installed from the following source:
google.golang.org/protobuf/cmd/protoc-gen-go,
github.com/protocolbuffers/protobuf-go/cmd/protoc-gen-go;
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/util/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

func TestReadLink(t *testing.T) {
dir, err := ioutil.TempDir("", "go-zero")
assert.Nil(t, err)
symLink := filepath.Join(dir, "test")
pwd, err := os.Getwd()
assertError(err, t)
Expand Down
9 changes: 4 additions & 5 deletions tools/goctl/util/templatex.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const regularPerm = 0o666

// DefaultTemplate is a tool to provides the text/template operations
type DefaultTemplate struct {
name string
text string
goFmt bool
savePath string
name string
text string
goFmt bool
}

// With returns a instance of DefaultTemplate
Expand Down Expand Up @@ -70,7 +69,7 @@ func (t *DefaultTemplate) Execute(data interface{}) (*bytes.Buffer, error) {

formatOutput, err := goformat.Source(buf.Bytes())
if err != nil {
return nil, errorx.Wrap(err, "go format error:", string(buf.Bytes()))
return nil, errorx.Wrap(err, "go format error:", buf.String())
}

buf.Reset()
Expand Down
2 changes: 1 addition & 1 deletion zrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestDepositServer_Deposit(t *testing.T) {
2000.00,
nil,
codes.DeadlineExceeded,
fmt.Sprintf("context deadline exceeded"),
"context deadline exceeded",
},
}

Expand Down
2 changes: 1 addition & 1 deletion zrpc/internal/serverinterceptors/tracinginterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func StreamTracingInterceptor(serviceName string) grpc.StreamServerInterceptor {
return handler(srv, ss)
}

ctx, span := trace.StartServerSpan(ctx, carrier, serviceName, info.FullMethod)
_, span := trace.StartServerSpan(ctx, carrier, serviceName, info.FullMethod)
defer span.Finish()
return handler(srv, ss)
}
Expand Down

0 comments on commit 65905b9

Please sign in to comment.