Skip to content

Commit 5ea922d

Browse files
committed
fix: fix lint errors
1 parent cf60945 commit 5ea922d

33 files changed

+174
-328
lines changed

.golangci.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ linters:
8484
#- gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false]
8585
#- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
8686
#- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
87-
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
87+
#- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
8888
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
8989
#- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
9090
#- godot # Check if comments end in a period [fast: true, auto-fix: true]
9191
#- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
92-
- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
92+
#- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
9393
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
9494
#- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
9595
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
@@ -106,7 +106,7 @@ linters:
106106
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
107107
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
108108
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
109-
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
109+
#- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
110110
#- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
111111
- nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
112112
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
@@ -117,21 +117,21 @@ linters:
117117
- nosnakecase # nosnakecase is a linter that detects snake case of variable naming and function name. [fast: true, auto-fix: false]
118118
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
119119
#- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test [fast: false, auto-fix: false]
120-
- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
120+
#- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
121121
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
122122
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
123123
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
124124
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
125125
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
126126
- structcheck # Finds unused struct fields [fast: false, auto-fix: false]
127127
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
128-
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
128+
#- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
129129
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
130-
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
130+
#- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
131131
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
132132
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
133133
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
134-
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
134+
#- unparam # Reports unused function parameters [fast: false, auto-fix: false]
135135
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
136136
#- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
137137
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,24 @@ $(foreach p,$(EXAMPLES),$(eval $(call examples,$(p))))
5555
## Run go mod tidy recursive
5656
.PHONY: lint
5757
lint:
58-
# @golangci-lint run
58+
@golangci-lint run
5959
@for name in example/*/; do\
6060
if [ $$name != "example/node_modules/" ]; then \
6161
echo "-------- $${name} ------------";\
6262
sh -c "cd $$(pwd)/$${name} && golangci-lint run";\
6363
fi \
6464
done
6565

66+
.PHONY: lint.fix
67+
lint.fix:
68+
@golangci-lint run --fix
69+
@for name in example/*/; do\
70+
if [ $$name != "example/node_modules/" ]; then \
71+
echo "-------- $${name} ------------";\
72+
sh -c "cd $$(pwd)/$${name} && golangci-lint run --fix";\
73+
fi \
74+
done
75+
6676
## Run go mod tidy recursive
6777
.PHONY: gomod
6878
gomod:

build.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"go/format"
7-
"io/ioutil"
87
"os"
98
"path"
109
"path/filepath"
@@ -20,7 +19,7 @@ import (
2019
func deriveCommonJSMapping(conf *config.Config) {
2120
replacer := strings.NewReplacer(".", "_", "/", "_", "-", "_")
2221
for _, mapping := range conf.Mappings {
23-
mapping.TypeScriptModule = replacer.Replace(mapping.GoPackage) //strings.Replace(strings.Replace(mapping.GoPackage, ".", "_", -1), "/", "_", -1)
22+
mapping.TypeScriptModule = replacer.Replace(mapping.GoPackage)
2423
}
2524
}
2625

@@ -59,8 +58,7 @@ func getPathForTarget(gomod config.Namespace, goPath string, target *config.Targ
5958
}
6059
}
6160

62-
func Build(conf *config.Config, goPath string) {
63-
61+
func Build(conf *config.Config, goPath string) { //nolint:maintidx
6462
deriveCommonJSMapping(conf)
6563

6664
mappedTypeScript := map[string]map[string]*code{}
@@ -125,7 +123,7 @@ func Build(conf *config.Config, goPath string) {
125123

126124
pkgName, services, structs, scalars, constantTypes, err := Read(goPaths, conf.Module, packageName, target.Services, missingTypes, missingConstants)
127125
if err != nil {
128-
_, _ = fmt.Fprintln(os.Stderr, "\t an error occured while trying to understand your code: ", err)
126+
_, _ = fmt.Fprintln(os.Stderr, "\t an error occurred while trying to understand your code: ", err)
129127
os.Exit(2)
130128
}
131129

@@ -179,7 +177,7 @@ func Build(conf *config.Config, goPath string) {
179177
)
180178

181179
// write code into file for debugging
182-
writeErr := ioutil.WriteFile(filename, []byte(code), 0644)
180+
writeErr := os.WriteFile(filename, []byte(code), 0644)
183181
if writeErr != nil {
184182
_, _ = fmt.Fprintln(os.Stderr, " could not write go source to file", writeErr)
185183
os.Exit(5)
@@ -189,7 +187,7 @@ func Build(conf *config.Config, goPath string) {
189187
os.Exit(5)
190188
}
191189

192-
writeErr := ioutil.WriteFile(filename, codeBytes, 0644)
190+
writeErr := os.WriteFile(filename, codeBytes, 0644)
193191
if writeErr != nil {
194192
_, _ = fmt.Fprintln(os.Stderr, " could not write go source to file", writeErr)
195193
os.Exit(5)
@@ -238,9 +236,7 @@ func Build(conf *config.Config, goPath string) {
238236

239237
_, _ = fmt.Fprintln(os.Stderr, "building structs for go package", goPackage, "to ts module", mapping.TypeScriptModule, "in file", mapping.Out)
240238
moduleCode := newCode(" ")
241-
structIndent := -1
242-
243-
structIndent = -3
239+
structIndent := -3
244240

245241
commonJSImports(conf, moduleCode, mapping.Out)
246242

@@ -251,7 +247,6 @@ func Build(conf *config.Config, goPath string) {
251247
}
252248
sort.Strings(structNames)
253249
for _, structName := range structNames {
254-
255250
structCode, ok := mappedStructsMap[structName]
256251
if ok {
257252
moduleCode.app(structCode.ind(structIndent).l("").string())
@@ -264,7 +259,6 @@ func Build(conf *config.Config, goPath string) {
264259
_, _ = fmt.Fprintln(os.Stderr, " failed to update code in", mapping.Out, updateErr)
265260
}
266261
}
267-
268262
}
269263

270264
func updateCode(file string, code string) error {
@@ -281,10 +275,10 @@ func updateCode(file string, code string) error {
281275
if errMkdirAll != nil {
282276
return errMkdirAll
283277
}
284-
oldCode, _ := ioutil.ReadFile(file)
278+
oldCode, _ := os.ReadFile(file)
285279
if string(oldCode) != code {
286280
fmt.Println(" writing file", file)
287-
return ioutil.WriteFile(file, []byte(code), 0644)
281+
return os.WriteFile(file, []byte(code), 0644)
288282
}
289283
fmt.Println(" update file not necessary - unchanged", file)
290284
return nil

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99

1010
"github.com/pkg/errors"
@@ -31,7 +31,7 @@ func NewClient() Client {
3131
return &bufferedClient{client: defaultHttpFactory(), handle: getHandleForEncoding(EncodingMsgpack), headers: nil}
3232
}
3333

34-
func NewClientWithHttpClient(client *http.Client) Client {
34+
func NewClientWithHttpClient(client *http.Client) Client { //nolint:stylecheck
3535
if client != nil {
3636
return &bufferedClient{client: client, handle: getHandleForEncoding(EncodingMsgpack), headers: nil}
3737
} else {
@@ -43,7 +43,7 @@ func newRequest(ctx context.Context, url string, contentType string, buffer *byt
4343
if buffer == nil {
4444
buffer = &bytes.Buffer{}
4545
}
46-
request, errRequest := http.NewRequestWithContext(ctx, "POST", url, buffer)
46+
request, errRequest := http.NewRequestWithContext(ctx, http.MethodPost, url, buffer)
4747
if errRequest != nil {
4848
return nil, errors.Wrap(errRequest, "could not create a request")
4949
}
@@ -71,7 +71,7 @@ func (c *bufferedClient) SetClientEncoding(encoding ClientEncoding) {
7171
c.handle = getHandleForEncoding(encoding)
7272
}
7373

74-
func (c *bufferedClient) SetTransportHttpClient(client *http.Client) {
74+
func (c *bufferedClient) SetTransportHttpClient(client *http.Client) { //nolint:stylecheck
7575
c.client = client
7676
}
7777

@@ -105,7 +105,7 @@ func (c *bufferedClient) Call(ctx context.Context, url string, endpoint string,
105105
// Check status
106106
if resp.StatusCode != http.StatusOK {
107107
var msg string
108-
if value, err := ioutil.ReadAll(resp.Body); err != nil {
108+
if value, err := io.ReadAll(resp.Body); err != nil {
109109
msg = "failed to read response body: " + err.Error()
110110
} else {
111111
msg = string(value)

cmd/gotsrpc/gotsrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func usage() {
1919
fmt.Println(os.Args[0], " path/to/build-config.yml")
2020
flag.PrintDefaults()
2121
}
22-
func main() {
2322

23+
func main() {
2424
flagDebug := flag.Bool("debug", false, "debug")
2525

2626
flag.Parse()

config/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package config
22

33
import (
44
"errors"
5-
"io/ioutil"
65
"os"
76
"path"
87
"path/filepath"
@@ -65,7 +64,7 @@ type Config struct {
6564
}
6665

6766
func LoadConfigFile(file string) (conf *Config, err error) {
68-
yamlBytes, readErr := ioutil.ReadFile(file)
67+
yamlBytes, readErr := os.ReadFile(file)
6968
if readErr != nil {
7069
return nil, errors.New("could not read config file: " + readErr.Error())
7170
}
@@ -81,7 +80,7 @@ func LoadConfigFile(file string) (conf *Config, err error) {
8180
}
8281
conf.Module.Path = absPath
8382

84-
if data, err := ioutil.ReadFile(path.Join(absPath, "go.mod")); err != nil && !os.IsNotExist(err) {
83+
if data, err := os.ReadFile(path.Join(absPath, "go.mod")); err != nil && !os.IsNotExist(err) {
8584
return nil, err
8685
} else if err == nil {
8786
modFile, err := modfile.Parse(path.Join(absPath, "go.mod"), data, nil)

config/config_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func TestLoadConfig(t *testing.T) {
6666
if demoTarget.Services["/service/demo"] != "Service" {
6767
t.Fatal("first service is wrong")
6868
}
69-
7069
}
7170

7271
func TestLoadConfigFile_GomodAbsolute(t *testing.T) {

error.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ type Error struct {
2121
// NewError returns a new instance
2222
func NewError(err error) *Error {
2323
// check if already transformed
24-
if v, ok := err.(*Error); ok {
24+
if v, ok := err.(*Error); ok { //nolint:errorlint
2525
return v
2626
}
2727

2828
// skip *withStack error type
29-
if _, ok := err.(interface {
29+
if _, ok := err.(interface { //nolint:errorlint
3030
StackTrace() errors.StackTrace
3131
}); ok && errors.Unwrap(err) != nil {
3232
err = errors.Unwrap(err)
@@ -87,7 +87,7 @@ func (e *Error) Format(s fmt.State, verb rune) {
8787
}
8888
fallthrough
8989
case 's', 'q':
90-
io.WriteString(s, e.Error())
90+
_, _ = io.WriteString(s, e.Error())
9191
}
9292
}
9393

example/basic/service/gorpc_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/basic/service/gotsrpc_gen.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)