Skip to content

Commit

Permalink
chore: fix ci lint issue (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean authored Aug 31, 2023
1 parent d070c7d commit 6ca275b
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 50 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/push-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ jobs:
- name: Lint
run: |
go install mvdan.cc/[email protected]
echo "install done!"
set -e
if [[ -n "$(gofumpt -l -extra .)" ]]; then
echo "gofumpt found formatting issues."
gofumpt -l -extra .
exit 1
fi
test -z "$(gofumpt -l -extra .)"
go vet -stdmethods=false $(go list ./...)
echo "test done!"
go vet -stdmethods=false $(go list ./...)
echo "go vet done!"
3 changes: 2 additions & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package main
import (
"flag"
"fmt"
"github.com/cloudwego/thriftgo/version"
"log"
"os"
"runtime"
"strings"
"time"

"github.com/cloudwego/thriftgo/version"

"github.com/cloudwego/thriftgo/generator"
"github.com/cloudwego/thriftgo/generator/backend"
"github.com/cloudwego/thriftgo/plugin"
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package config

import (
"github.com/cloudwego/thriftgo/pkg/test"
"testing"

"github.com/cloudwego/thriftgo/pkg/test"
)

func TestLoad(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion generator/golang/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ package golang

import (
"fmt"
"github.com/cloudwego/thriftgo/tool/trimmer/trim"
"go/format"
"path/filepath"
"strings"
"text/template"

"github.com/cloudwego/thriftgo/tool/trimmer/trim"

ref_tpl "github.com/cloudwego/thriftgo/generator/golang/templates/ref"
reflection_tpl "github.com/cloudwego/thriftgo/generator/golang/templates/reflection"

Expand Down
40 changes: 20 additions & 20 deletions generator/golang/scope_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ func BuildRefScope(cu *CodeUtils, ast *parser.Thrift) (*Scope, *Scope, error) {
// todo not support now
// half ref
// we will change the fields from scope, we can't use BuildScope() to create scope because that function will put scope into a cache map.
localScope, err := doBuildScope(cu, ast)
if err != nil {
return nil, nil, err
}
refScope, err := doBuildScope(cu, ast)
if err != nil {
return nil, nil, err
}
refScope.setRefImport(thriftRef.Path)
// do not generate service to remote
refScope.services = nil
// grepService(thriftRef.Services, &localScope.services, &refScope.services)
grepStructs(thriftRef.Unions, &localScope.unions, &refScope.unions)
grepStructs(thriftRef.Exceptions, &localScope.exceptions, &refScope.exceptions)
grepStructs(thriftRef.Structs, &localScope.structs, &refScope.structs)
grepConstants(thriftRef.Consts, &localScope.constants, &refScope.constants)
grepTypedefs(thriftRef.Typedefs, &localScope.typedefs, &refScope.typedefs)
grepEnums(thriftRef.Enums, &localScope.enums, &refScope.enums)
// todo clean ref scope import
return localScope, refScope, nil
//localScope, err := doBuildScope(cu, ast)
//if err != nil {
// return nil, nil, err
//}
//refScope, err := doBuildScope(cu, ast)
//if err != nil {
// return nil, nil, err
//}
//refScope.setRefImport(thriftRef.Path)
//// do not generate service to remote
//refScope.services = nil
//// grepService(thriftRef.Services, &localScope.services, &refScope.services)
//grepStructs(thriftRef.Unions, &localScope.unions, &refScope.unions)
//grepStructs(thriftRef.Exceptions, &localScope.exceptions, &refScope.exceptions)
//grepStructs(thriftRef.Structs, &localScope.structs, &refScope.structs)
//grepConstants(thriftRef.Consts, &localScope.constants, &refScope.constants)
//grepTypedefs(thriftRef.Typedefs, &localScope.typedefs, &refScope.typedefs)
//grepEnums(thriftRef.Enums, &localScope.enums, &refScope.enums)
//// todo clean ref scope import
//return localScope, refScope, nil
}

func isContains(sa []string, s string) bool {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"fmt"
"github.com/cloudwego/thriftgo/version"
"os"
"runtime/debug"

Expand All @@ -25,6 +24,7 @@ import (
"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/plugin"
"github.com/cloudwego/thriftgo/semantic"
"github.com/cloudwego/thriftgo/version"
)

var (
Expand Down
1 change: 1 addition & 0 deletions parser/AST.go

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

1 change: 1 addition & 0 deletions parser/thrift.peg.go

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

1 change: 1 addition & 0 deletions plugin/protocol.go

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

1 change: 1 addition & 0 deletions thrift_reflection/descriptor.go

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

1 change: 1 addition & 0 deletions thrift_reflection/descriptor_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package thrift_reflection

import (
"fmt"

"github.com/cloudwego/thriftgo/parser"
)

Expand Down

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

5 changes: 3 additions & 2 deletions tool/trimmer/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package main
import (
"flag"
"fmt"
"github.com/cloudwego/thriftgo/plugin"
"github.com/cloudwego/thriftgo/version"
"os"
"strings"

"github.com/cloudwego/thriftgo/plugin"
"github.com/cloudwego/thriftgo/version"
)

// StringSlice implements the flag.Value interface on string slices
Expand Down
3 changes: 1 addition & 2 deletions tool/trimmer/dirTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// create directory-tree before dump
func createDirTree(sourceDir string, destinationDir string) {
func createDirTree(sourceDir, destinationDir string) {
err := filepath.Walk(sourceDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -38,7 +38,6 @@ func createDirTree(sourceDir string, destinationDir string) {
}
return nil
})

if err != nil {
fmt.Printf("manage output error: %v\n", err)
os.Exit(2)
Expand Down
9 changes: 6 additions & 3 deletions tool/trimmer/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ package dump

import (
"bytes"
"github.com/cloudwego/thriftgo/parser"
"html"
"html/template"
"strings"

"github.com/cloudwego/thriftgo/parser"
)

// DumpIDL Dump the ast to idl string
func DumpIDL(ast *parser.Thrift) (string, error) {
tmpl, _ := template.New("thrift").Funcs(template.FuncMap{"RemoveLastComma": RemoveLastComma,
"JoinQuotes": JoinQuotes, "ReplaceQuotes": ReplaceQuotes}).
tmpl, _ := template.New("thrift").Funcs(template.FuncMap{
"RemoveLastComma": RemoveLastComma,
"JoinQuotes": JoinQuotes, "ReplaceQuotes": ReplaceQuotes,
}).
Parse(IDLTemplate + TypeDefTemplate + AnnotationsTemplate +
ConstantTemplate + EnumTemplate + ConstValueTemplate + FieldTemplate + StructTemplate + UnionTemplate +
ExceptionTemplate + ServiceTemplate + FunctionTemplate + SingleLineFieldTemplate + TypeTemplate +
Expand Down
5 changes: 3 additions & 2 deletions tool/trimmer/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ package dump

import (
"fmt"
"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/pkg/test"
"io/ioutil"
"path/filepath"
"strings"
"testing"

"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/pkg/test"
)

func TestDumpSingle(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions tool/trimmer/dump/field_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ set<{{- template "Type" .ValueType}}>
{{- template "Annotations" .Annotations -}}
{{end}}
`

const TypeDefTemplate = `
{{define "Typedef"}}
{{- if .ReservedComments -}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{- end -}}
{{- "typedef"}} {{template "Type" .Type}} {{.Alias}} {{template "Annotations" .Annotations}}
{{- end -}}
`

const ConstValueTemplate = `
{{define "ConstValue"}}
{{- if .TypedValue.Double}}{{.TypedValue.Double}}{{end}}
Expand All @@ -49,6 +51,7 @@ const ConstValueTemplate = `
{{- if .TypedValue.IsSetMap}}{{template "ConstMap" .TypedValue.Map}}{{end}}
{{- end -}}
`

const ConstListTemplate = `
{{define "ConstList"}}
{{- "[" -}}
Expand All @@ -58,6 +61,7 @@ const ConstListTemplate = `
{{- "]" -}}
{{- end -}}
`

const ConstMapTemplate = `
{{define "ConstMap"}}
{{- "{" -}}
Expand All @@ -67,6 +71,7 @@ const ConstMapTemplate = `
{{- "}" -}}
{{- end -}}
`

const ConstantTemplate = `
{{define "Constant"}}
{{- if .ReservedComments -}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{- end -}}
Expand All @@ -75,6 +80,7 @@ const ConstantTemplate = `
{{- template "Annotations" .Annotations -}}
{{- end -}}
`

const EnumTemplate = `
{{define "Enum"}}
{{- if .ReservedComments -}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{- end -}}
Expand All @@ -86,6 +92,7 @@ const EnumTemplate = `
} {{template "Annotations" .Annotations -}}{{"\n"}}
{{- end -}}
`

const FieldTemplate = `
{{define "Field"}}
{{- if .ReservedComments}}{{" "}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand All @@ -97,6 +104,7 @@ const FieldTemplate = `
{{- template "Annotations" .Annotations -}}
{{- end -}}
`

const StructTemplate = `
{{define "Struct"}}
{{- if .ReservedComments}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand All @@ -107,6 +115,7 @@ const StructTemplate = `
} {{template "Annotations" .Annotations -}}{{"\n"}}
{{- end -}}
`

const UnionTemplate = `
{{define "Union"}}
{{- if .ReservedComments}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand All @@ -117,6 +126,7 @@ const UnionTemplate = `
} {{template "Annotations" .Annotations -}}{{"\n"}}
{{- end -}}
`

const ExceptionTemplate = `
{{define "Exception"}}
{{- if .ReservedComments}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand All @@ -127,6 +137,7 @@ const ExceptionTemplate = `
} {{template "Annotations" .Annotations -}}{{"\n"}}
{{- end -}}
`

const ServiceTemplate = `
{{define "Service"}}
{{- if .ReservedComments}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand All @@ -137,6 +148,7 @@ const ServiceTemplate = `
} {{template "Annotations" .Annotations -}}{{"\n"}}
{{- end -}}
`

const FunctionTemplate = `
{{define "Function"}}
{{- if .ReservedComments}}{{" "}}{{- ReplaceQuotes .ReservedComments -}}{{"\n"}}{{end -}}
Expand Down Expand Up @@ -165,6 +177,7 @@ const SingleLineFieldTemplate = `
{{- template "Annotations" .Annotations -}}
{{- end -}}
`

const AnnotationsTemplate = `
{{define "Annotations"}}
{{- if . -}}
Expand All @@ -183,9 +196,11 @@ const AnnotationsTemplate = `
func RemoveLastComma(s string) string {
return strings.TrimRight(s, ", ")
}

func JoinQuotes(s string) string {
return fmt.Sprintf("%s", "#OUTQUOTES"+s+"#OUTQUOTES")
}

func ReplaceQuotes(s string) string {
out := strings.Replace(s, "\"", "#OUTQUOTES", -1)
return out
Expand Down
12 changes: 6 additions & 6 deletions tool/trimmer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ package main

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/semantic"
"github.com/cloudwego/thriftgo/tool/trimmer/dump"
"github.com/cloudwego/thriftgo/tool/trimmer/trim"
"github.com/cloudwego/thriftgo/version"
"os"
"path/filepath"
"strings"

"github.com/cloudwego/thriftgo/generator"
)
Expand Down Expand Up @@ -101,7 +102,6 @@ func main() {
println("-o should be set as a valid dir to enable -r", err.Error())
os.Exit(2)
}

}
createDirTree(a.Recurse, a.OutputFile)
recurseDump(ast, a.Recurse, a.OutputFile)
Expand All @@ -121,7 +121,7 @@ func main() {
os.Exit(0)
}

func recurseDump(ast *parser.Thrift, sourceDir string, outDir string) {
func recurseDump(ast *parser.Thrift, sourceDir, outDir string) {
if ast == nil {
return
}
Expand All @@ -139,7 +139,7 @@ func recurseDump(ast *parser.Thrift, sourceDir string, outDir string) {
}
}

func writeStringToFile(filename string, content string) error {
func writeStringToFile(filename, content string) error {
file, err := os.Create(filename)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 6ca275b

Please sign in to comment.