Skip to content

Commit 91eb849

Browse files
authored
Update linter configuration and fix linting issues (#3694)
1 parent 4411458 commit 91eb849

30 files changed

Lines changed: 94 additions & 90 deletions

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
version: "2"
12
linters:
23
enable:
34
- errorlint
5+
- errcheck
6+
- staticcheck
7+

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ depend:
7070

7171
lint:
7272
ifneq ($(GOOS),windows)
73-
@if [ "`golangci-lint run ./... | grep -v ".pb.go" | tee /dev/stderr`" ]; then \
74-
echo "^ - lint errors!" && echo && exit 1; \
75-
fi
73+
@golangci-lint run ./... || (echo "^ - lint errors!" && echo && exit 1)
7674
endif
7775

7876
test:

cmd/goa/gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (g *Generator) Run() ([]string, error) {
226226
// Remove deletes the package files.
227227
func (g *Generator) Remove() {
228228
if g.tmpDir != "" {
229-
os.RemoveAll(g.tmpDir)
229+
_ = os.RemoveAll(g.tmpDir)
230230
g.tmpDir = ""
231231
}
232232
}
@@ -237,7 +237,7 @@ func (g *Generator) runGoCmd(args ...string) error {
237237
return fmt.Errorf(`failed to find a go compiler, looked in "%s"`, os.Getenv("PATH"))
238238
}
239239
if g.DesignVersion > 2 {
240-
os.Setenv("GO111MODULE", "on")
240+
_ = os.Setenv("GO111MODULE", "on")
241241
}
242242
c := exec.Cmd{
243243
Path: gobin,

codegen/file.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ func finalizeGoSource(path string) error {
165165
if err := format.Node(w, fset, file); err != nil {
166166
return err
167167
}
168-
w.Close()
168+
if err := w.Close(); err != nil {
169+
return err
170+
}
169171

170172
// Format code using goimport standard
171173
bs, err := os.ReadFile(path)

codegen/go_transform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func transformObject(source, target *expr.AttributeExpr, sourceVar, targetVar st
197197
assign = ":="
198198
}
199199
name := ta.TargetCtx.Scope.Name(target, ta.TargetCtx.Pkg(target), ta.TargetCtx.Pointer, ta.TargetCtx.UseDefault)
200-
buffer.WriteString(fmt.Sprintf("%s %s %s%s{%s}\n", targetVar, assign, deref, name, initCode))
200+
fmt.Fprintf(buffer, "%s %s %s%s{%s}\n", targetVar, assign, deref, name, initCode)
201201
buffer.WriteString(postInitCode)
202202

203203
// iterate through attributes to initialize rest of the struct fields and

codegen/service/convert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func objRecursive() *expr.UserTypeExpr {
308308
},
309309
TypeName: "objRecursiveT",
310310
}
311-
obj := res.AttributeExpr.Type.(*expr.Object)
311+
obj := res.Type.(*expr.Object)
312312
*obj = append(*obj, &expr.NamedAttributeExpr{
313313
Name: "Rec",
314314
Attribute: &expr.AttributeExpr{Type: res}})

codegen/service/service_data.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,11 @@ func collectUnionMethods(att *expr.AttributeExpr, scope *codegen.NameScope, loc
10181018

10191019
// buildErrorInitData creates the data needed to generate code around endpoint error return values.
10201020
func buildErrorInitData(er *expr.ErrorExpr, scope *codegen.NameScope) *ErrorInitData {
1021-
_, temporary := er.AttributeExpr.Meta["goa:error:temporary"]
1022-
_, timeout := er.AttributeExpr.Meta["goa:error:timeout"]
1023-
_, fault := er.AttributeExpr.Meta["goa:error:fault"]
1021+
_, temporary := er.Meta["goa:error:temporary"]
1022+
_, timeout := er.Meta["goa:error:timeout"]
1023+
_, fault := er.Meta["goa:error:fault"]
10241024
var pkg string
1025-
if ut, ok := er.AttributeExpr.Type.(expr.UserType); ok {
1025+
if ut, ok := er.Type.(expr.UserType); ok {
10261026
pkg = codegen.UserTypeLocation(ut).PackageName()
10271027
}
10281028
return &ErrorInitData{
@@ -1098,7 +1098,7 @@ func buildMethodData(m *expr.MethodExpr, scope *codegen.NameScope) *MethodData {
10981098
errorLocs = make(map[string]*codegen.Location, len(m.Errors))
10991099
for i, er := range m.Errors {
11001100
errors[i] = buildErrorInitData(er, scope)
1101-
errorLocs[er.Name] = codegen.UserTypeLocation(er.AttributeExpr.Type)
1101+
errorLocs[er.Name] = codegen.UserTypeLocation(er.Type)
11021102
}
11031103
}
11041104
for _, req := range m.Requirements {
@@ -1638,7 +1638,7 @@ func buildProjectedType(projected, att *expr.AttributeExpr, viewspkg string, sco
16381638
func buildViews(rt *expr.ResultTypeExpr, viewScope *codegen.NameScope) []*ViewData {
16391639
views := make([]*ViewData, len(rt.Views))
16401640
for i, view := range rt.Views {
1641-
vatt := expr.AsObject(view.AttributeExpr.Type)
1641+
vatt := expr.AsObject(view.Type)
16421642
attrs := make([]string, len(*vatt))
16431643
for j, nat := range *vatt {
16441644
attrs[j] = nat.Name
@@ -2072,7 +2072,7 @@ func buildConstructorCode(src, tgt *expr.AttributeExpr, sourceVar, targetVar str
20722072
finit := "new" + targetCtx.Scope.Name(nat.Attribute, "", targetCtx.Pointer, targetCtx.UseDefault)
20732073
if view != "" {
20742074
v := ""
2075-
if vatt := rt.View(view).AttributeExpr.Find(nat.Name); vatt != nil {
2075+
if vatt := rt.View(view).Find(nat.Name); vatt != nil {
20762076
if attv, ok := vatt.Meta.Last(expr.ViewMetaKey); ok && attv != expr.DefaultView {
20772077
// view is explicitly set for the result type on the attribute
20782078
v = attv

codegen/testing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func sectionCodeWithPrefix(t *testing.T, section *SectionTemplate, prefix string
6666
func FormatTestCode(t *testing.T, code string) string {
6767
t.Helper()
6868
tmp := CreateTempFile(t, code)
69-
defer os.Remove(tmp)
69+
defer func() { _ = os.Remove(tmp) }()
7070
require.NoError(t, finalizeGoSource(tmp))
7171
content, err := os.ReadFile(tmp)
7272
require.NoError(t, err)
@@ -81,7 +81,7 @@ func CreateTempFile(t *testing.T, content string) string {
8181
require.NoError(t, err)
8282
_, err = f.WriteString(content)
8383
if err != nil {
84-
os.Remove(f.Name())
84+
require.NoError(t, os.Remove(f.Name()))
8585
t.Fatal(err)
8686
}
8787
require.NoError(t, f.Close())

dsl/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ func Body(args ...any) {
914914
}
915915
kind = "Request"
916916
case *expr.HTTPErrorExpr:
917-
ref = e.ErrorExpr.AttributeExpr
917+
ref = e.AttributeExpr
918918
setter = func(att *expr.AttributeExpr) {
919919
if e.Response == nil {
920920
e.Response = &expr.HTTPResponseExpr{}

dsl/result_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestView(t *testing.T) {
8484
found = true
8585
for _, attr := range c.expectedViewAttrs[view] {
8686
found2 := false
87-
for _, attr2 := range *v.AttributeExpr.Type.(*expr.Object) {
87+
for _, attr2 := range *v.Type.(*expr.Object) {
8888
if attr2.Name == attr {
8989
found2 = true
9090
break

0 commit comments

Comments
 (0)