cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.14k stars 294 forks source link

CI: start enforcing a subset of staticcheck #3335

Open uhthomas opened 3 months ago

uhthomas commented 3 months ago

Whilst working on CUE, I've noticed a lot of static check messages in my editor. Would it be worth adding something like golangci-lint?

❯ go run honnef.co/go/tools/cmd/staticcheck@latest ./...
cmd/cue/cmd/add.go:176:8: cue.Build is deprecated: use [Context.BuildInstances]. The use of [Instance] is being phased out.  (SA1019)
cmd/cue/cmd/common.go:746:15: cue.Build is deprecated: use [Context.BuildInstances]. The use of [Instance] is being phased out.  (SA1019)
cmd/cue/cmd/common.go:802:10: cue.Merge is deprecated: do not use.  (SA1019)
cmd/cue/cmd/common.go:808:17: r.Build is deprecated: use [Context.BuildInstance]. The use of [Instance] is being phased out.  (SA1019)
cmd/cue/cmd/common.go:817:9: inst.Build is deprecated: use [Context.BuildInstance]  (SA1019)
cmd/cue/cmd/custom.go:66:14: tools.Lookup is deprecated: use [Value.LookupPath]  (SA1019)
cmd/cue/cmd/custom.go:89:7: tools.Lookup is deprecated: use [Value.LookupPath]  (SA1019)
cmd/cue/cmd/custom.go:96:32: tools.Lookup is deprecated: use [Value.LookupPath]  (SA1019)
cmd/cue/cmd/custom.go:116:3: the surrounding loop is unconditionally terminated (SA4004)
cmd/cue/cmd/custom.go:194:5: v.Lookup is deprecated: use [Value.LookupPath]. At some point before v1.0.0, this method will be removed to be reused eventually for looking up a selector.  (SA1019)
cmd/cue/cmd/custom.go:198:14: v.Lookup is deprecated: use [Value.LookupPath]. At some point before v1.0.0, this method will be removed to be reused eventually for looking up a selector.  (SA1019)
cmd/cue/cmd/custom.go:216:16: v.Lookup is deprecated: use [Value.LookupPath]. At some point before v1.0.0, this method will be removed to be reused eventually for looking up a selector.  (SA1019)
cmd/cue/cmd/custom.go:221:17: v.Lookup is deprecated: use [Value.LookupPath]. At some point before v1.0.0, this method will be removed to be reused eventually for looking up a selector.  (SA1019)
cmd/cue/cmd/get_go.go:304:9: types.NewSignature has been deprecated since Go 1.18: Use [NewSignatureType] instead which allows for type parameters.  (SA1019)
cmd/cue/cmd/modpublish.go:241:13: modzip.Create is deprecated: this will be removed in a future API iteration that reduces dependence on zip archives.  (SA1019)
cmd/cue/cmd/orphans.go:239:12: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
cue/build/import.go:107:11: empty branch (SA9003)
cue/build_test.go:259:7: p.AddFile is deprecated: use AddSyntax or wait for this to be renamed using a new signature.  (SA1019)
cue/format/import.go:28:6: func sortImports is unused (U1000)
cue/format/import.go:51:6: func setRelativePos is unused (U1000)
cue/format/import.go:63:6: func hasDoc is unused (U1000)
cue/format/import.go:72:6: func importPath is unused (U1000)
cue/format/import.go:80:6: func importName is unused (U1000)
cue/format/import.go:88:6: func importComment is unused (U1000)
cue/format/import.go:98:6: func collapse is unused (U1000)
cue/format/import.go:110:6: type posSpan is unused (U1000)
cue/format/import.go:115:6: func sortSpecs is unused (U1000)
cue/format/import.go:151:6: type byImportSpec is unused (U1000)
cue/format/import.go:153:23: func byImportSpec.Len is unused (U1000)
cue/format/import.go:154:23: func byImportSpec.Swap is unused (U1000)
cue/format/import.go:155:23: func byImportSpec.Less is unused (U1000)
cue/instance.go:168:23: func (*Instance).setError is unused (U1000)
cue/instance.go:173:23: func (*Instance).eval is unused (U1000)
cue/interpreter/wasm/call.go:78:2: should use 'return u == 1' instead of 'if u == 1 { return true }; return false' (S1008)
cue/interpreter/wasm/wasm_test.go:96:6: func copyWasmFiles is unused (U1000)
cue/interpreter/wasm/wasm_test.go:108:6: func copyFile is unused (U1000)
cue/interpreter/wasm/wasm_test.go:116:6: func check is unused (U1000)
cue/interpreter/wasm/wasm_test.go:129:6: func loadDir is unused (U1000)
cue/interpreter/wasm/wasm_test.go:135:6: func dirInstance is unused (U1000)
cue/interpreter/wasm/wasm_test.go:142:4: inst.AddFile is deprecated: use AddSyntax or wait for this to be renamed using a new signature.  (SA1019)
cue/interpreter/wasm/wasm_test.go:155:6: func loadFile is unused (U1000)
cue/interpreter/wasm/wasm_test.go:159:6: func must is unused (U1000)
cue/load/loader_common.go:175:3: redundant return statement (S1023)
cue/marshal.go:65:7: p.AddFile is deprecated: use AddSyntax or wait for this to be renamed using a new signature.  (SA1019)
cue/parser/parser.go:529:21: p.file.Base is deprecated: this method just returns the (deprecated) second argument passed to NewFile.  (SA1019)
cue/types.go:806:6: func hasDisjunction is unused (U1000)
cue/types.go:828:6: func stripNonDefaults is unused (U1000)
cue/types_test.go:3392:9: identical expressions on the left and right side of the '&&' operator (SA4000)
encoding/gocode/gocodec/codec.go:49:15: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/gocode/gocodec/codec_test.go:104:10: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/json/json.go:100:20: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/json/json.go:115:8: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/openapi/build.go:133:17: (*cue.Runtime)(r).Build is deprecated: use [Context.BuildInstance]. The use of [Instance] is being phased out.  (SA1019)
encoding/openapi/build.go:133:19: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/openapi/build.go:239:2: empty branch (SA9003)
encoding/openapi/build.go:421:17: v.Reference is deprecated: use [Value.ReferencePath]  (SA1019)
encoding/openapi/build.go:798:14: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/openapi/build.go:900:17: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/openapi/crd.go:116:11: v.Reference is deprecated: use [Value.ReferencePath]  (SA1019)
encoding/openapi/crd.go:131:18: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/openapi/crd.go:143:18: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/openapi/decode_test.go:60:10: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/openapi/decode_test.go:68:16: json.Decode is deprecated: use Extract and build using cue.Context.BuildExpr.  (SA1019)
encoding/openapi/decode_test.go:70:16: yaml.Decode is deprecated: use Extract and build the File with cue.Context.BuildFile.  (SA1019)
encoding/openapi/decode_test.go:101:17: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/openapi/openapi.go:151:6: i.IsDefinition is deprecated: use i.Selector().IsDefinition()  (SA1019)
encoding/openapi/openapi_test.go:274:14: cue.Build is deprecated: use [Context.BuildInstances]. The use of [Instance] is being phased out.  (SA1019)
encoding/openapi/openapi_test.go:313:8: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/openapi/openapi_test.go:314:15: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/openapi/openapi_test.go:332:8: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/openapi/openapi_test.go:333:15: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/jsonpb/decoder.go:128:9: schema.Template is deprecated: use [Value.LookupPath] in combination with using optional selectors.  (SA1019)
encoding/protobuf/jsonpb/decoder.go:175:14: schema.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/protobuf/jsonpb/decoder_test.go:39:7: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/protobuf/jsonpb/decoder_test.go:50:18: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/jsonpb/decoder_test.go:112:8: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/protobuf/jsonpb/decoder_test.go:113:15: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/jsonpb/encoder_test.go:35:7: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/protobuf/jsonpb/encoder_test.go:46:18: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/jsonpb/encoder_test.go:64:17: r.CompileFile is deprecated: use [Context.BuildFile]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/pbinternal/attribute.go:92:11: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/protobuf/pbinternal/attribute.go:119:11: v.Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/protobuf/textproto/decoder.go:169:12: i.Value().Elem is deprecated: use [Value.LookupPath] in combination with "AnyString" or "AnyIndex".  (SA1019)
encoding/protobuf/textproto/decoder_test.go:35:7: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/protobuf/textproto/decoder_test.go:49:18: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/textproto/encoder_test.go:33:7: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/protobuf/textproto/encoder_test.go:43:18: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
encoding/protobuf/util.go:78:14: strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.  (SA1019)
encoding/yaml/yaml_test.go:101:8: cue.Runtime is deprecated: use [Context].  (SA1019)
encoding/yaml/yaml_test.go:131:14: r.Compile is deprecated: use [Context] with methods like [Context.CompileString] or [Context.CompileBytes]. The use of [Instance] is being phased out.  (SA1019)
internal/ci/checks/commit.go:54:10: error strings should not be capitalized (ST1005)
internal/core/adt/composite.go:565:2: empty branch (SA9003)
internal/core/adt/constraints.go:47:23: func (*nodeContext).insertListEllipsis is unused (U1000)
internal/core/adt/dev.go:77:24: func combinedFlags.ignore is unused (U1000)
internal/core/adt/disjunct2.go:584:6: func isPartialNode is unused (U1000)
internal/core/adt/disjunct2.go:585:2: should use 'return d.node.status == finalized' instead of 'if d.node.status == finalized { return true }; return false' (S1008)
internal/core/adt/disjunct2.go:741:3: empty branch (SA9003)
internal/core/adt/errors.go:132:6: func isIncomplete is unused (U1000)
internal/core/adt/eval.go:57:5: var structSentinel is unused (U1000)
internal/core/adt/eval.go:1546:2: field index is unused (U1000)
internal/core/adt/eval.go:2217:2: should use 'return len(n.exprs) < len(exprs)' instead of 'if len(n.exprs) < len(exprs) { return true }; return false' (S1008)
internal/core/adt/eval.go:2471:17: type assertion to the same type: m.Src already has type ast.Expr (S1040)
internal/core/adt/eval_test.go:124:4: empty branch (SA9003)
internal/core/adt/eval_test.go:235:2: should merge variable declaration with assignment on next line (S1021)
internal/core/adt/export_test.go:94:3: this value of ci is never used (SA4006)
internal/core/adt/fields.go:534:2: empty branch (SA9003)
internal/core/adt/fields.go:600:4: empty branch (SA9003)
internal/core/adt/overlay.go:226:3: should replace loop with d.disjunctions = append(d.disjunctions, n.disjunctions...) (S1011)
internal/core/adt/overlay.go:343:2: empty branch (SA9003)
internal/core/adt/overlay.go:362:4: empty branch (SA9003)
internal/core/adt/sched.go:112:23: func (*taskContext).newTask is unused (U1000)
internal/core/adt/sched.go:139:21: func schedState.done is unused (U1000)
internal/core/adt/sched.go:390:3: empty branch (SA9003)
internal/core/adt/sched.go:599:2: field blockStack is unused (U1000)
internal/core/adt/sched_test.go:186:3: field err is unused (U1000)
internal/core/adt/states.go:173:2: const leftOfMaxCoreCondition is unused (U1000)
internal/core/adt/states.go:175:2: const finalStateKnown is unused (U1000)
internal/core/adt/states.go:177:2: const preValidation is unused (U1000)
internal/core/adt/states.go:209:2: const scalarConjunct is unused (U1000)
internal/core/adt/tasks.go:193:6: func processFinalizeDisjunctions is unused (U1000)
internal/core/adt/unify.go:429:2: redundant return statement (S1023)
internal/core/adt/unify.go:459:2: empty branch (SA9003)
internal/core/compile/builtin.go:27:2: var stringParam is unused (U1000)
internal/core/compile/compile.go:126:20: func (*compiler).reset is unused (U1000)
internal/core/runtime/build.go:103:12: p.AddFile is deprecated: use AddSyntax or wait for this to be renamed using a new signature.  (SA1019)
internal/core/subsume/structural.go:21:20: func (*subsumer).subsumes is unused (U1000)
internal/core/subsume/structural.go:40:20: func (*subsumer).conjunct is unused (U1000)
internal/core/subsume/structural.go:44:20: func (*subsumer).c is unused (U1000)
internal/core/subsume/structural.go:48:6: func isBottomConjunct is unused (U1000)
internal/core/subsume/structural.go:53:20: func (*subsumer).node is unused (U1000)
internal/core/subsume/structural.go:60:20: func (*subsumer).structural is unused (U1000)
internal/core/subsume/structural.go:178:20: func (*subsumer).structLit is unused (U1000)
internal/core/subsume/structural.go:225:6: type collatedDecls is unused (U1000)
internal/core/subsume/structural.go:236:6: func newCollatedDecls is unused (U1000)
internal/core/subsume/structural.go:240:6: type field is unused (U1000)
internal/core/subsume/structural.go:245:25: func (*collatedDecls).collate is unused (U1000)
internal/core/subsume/vertex.go:435:6: identical expressions on the left and right side of the '||' operator (SA4000)
internal/diff/diff.go:113:13: v.Struct is deprecated: use [Value.Fields].  (SA1019)
internal/diff/diff.go:134:13: es.x.Struct is deprecated: use [Value.Fields].  (SA1019)
internal/diff/diff.go:147:13: es.y.Struct is deprecated: use [Value.Fields].  (SA1019)
internal/diff/diff.go:207:49: cue.FieldInfo is deprecated: only used by deprecated functions.  (SA1019)
internal/diff/diff.go:210:10: cue.FieldInfo is deprecated: only used by deprecated functions.  (SA1019)
internal/diff/diff.go:216:11: x.Struct is deprecated: use [Value.Fields].  (SA1019)
internal/diff/diff.go:217:11: y.Struct is deprecated: use [Value.Fields].  (SA1019)
internal/diff/diff.go:246:13: cue.FieldInfo is deprecated: only used by deprecated functions.  (SA1019)
internal/envflag/flag.go:89:5: error var InvalidError should have name of the form ErrFoo (ST1012)
internal/golangorgx/gopls/cache/methodsets/methodsets.go:139:3: empty branch (SA9003)
internal/golangorgx/gopls/cache/view.go:949:11: empty branch (SA9003)
internal/golangorgx/gopls/cache/view.go:1245:5: var modFlagRegexp is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:287:2: var internalMu is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:288:2: var internalConnections is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:696:22: func (*connection).semanticTokens is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:705:22: func (*connection).diagnoseFiles is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:735:19: func (*cmdFile).locationSpan is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:742:19: func (*cmdFile).rangeSpan is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:752:19: func (*cmdFile).offsetSpan is unused (U1000)
internal/golangorgx/gopls/cmd/cmd.go:769:6: func offsetPoint is unused (U1000)
internal/golangorgx/gopls/cmd/span.go:75:6: func sortSpans is unused (U1000)
internal/golangorgx/gopls/cmd/span.go:82:6: func compare is unused (U1000)
internal/golangorgx/gopls/cmd/span.go:95:6: func comparePoint is unused (U1000)
internal/golangorgx/gopls/cuelang/format.go:34:2: this value of ctx is never used (SA4006)
internal/golangorgx/gopls/debug/serve.go:311:20: func (*Instance).getView is unused (U1000)
internal/golangorgx/gopls/golang/format.go:105:6: type importFix is unused (U1000)
internal/golangorgx/gopls/golang/format.go:114:6: func allImportsFixes is unused (U1000)
internal/golangorgx/gopls/golang/format.go:129:6: func computeImportEdits is unused (U1000)
internal/golangorgx/gopls/golang/snapshot.go:105:6: type unit is unused (U1000)
internal/golangorgx/gopls/protocol/tsdocument_changes.go:41:14: error strings should not be capitalized (ST1005)
internal/golangorgx/gopls/server/code_action.go:14:6: func documentChanges is unused (U1000)
internal/golangorgx/gopls/server/diagnostics.go:452:3: assignment to nil map (SA5000)
internal/golangorgx/gopls/server/general.go:614:2: this value of ctx is never used (SA4006)
internal/golangorgx/gopls/server/server.go:111:2: field ongoingProfileMu is unused (U1000)
internal/golangorgx/gopls/server/server.go:112:2: field ongoingProfile is unused (U1000)
internal/golangorgx/gopls/server/server.go:158:2: this value of ctx is never used (SA4006)
internal/golangorgx/gopls/settings/settings.go:646:11: error strings should not be capitalized (ST1005)
internal/golangorgx/gopls/settings/settings.go:783:17: error strings should not end with punctuation or newlines (ST1005)
internal/golangorgx/gopls/test/integration/fake/editor.go:272:3: unnecessary nil check around range (S1031)
internal/golangorgx/telemetry/internal/upload/upload.go:57:2: empty branch (SA9003)
internal/golangorgx/tools/analysisinternal/extractdoc.go:98:14: error strings should not be capitalized (ST1005)
internal/golangorgx/tools/diff/lcs/old.go:191:21: func (*editGraph).bdone is unused (U1000)
internal/golangorgx/tools/diff/lcs/old.go:202:6: func backward is unused (U1000)
internal/golangorgx/tools/event/core/event.go:32:6: type eventLabelMap is unused (U1000)
internal/golangorgx/tools/event/label/label.go:105:11: reflect.StringHeader has been deprecated since Go 1.21 and an alternative has been available since Go 1.20: Use unsafe.String or unsafe.StringData instead.  (SA1019)
internal/golangorgx/tools/event/label/label.go:119:11: reflect.StringHeader has been deprecated since Go 1.21 and an alternative has been available since Go 1.20: Use unsafe.String or unsafe.StringData instead.  (SA1019)
internal/golangorgx/tools/gcimporter/gcimporter.go:262:6: func deref is unused (U1000)
internal/golangorgx/tools/gcimporter/iexport.go:326:2: field out is unused (U1000)
internal/golangorgx/tools/gcimporter/iimport.go:32:21: func (*intReader).int64 is unused (U1000)
internal/golangorgx/tools/gcimporter/unified_no.go:10:7: const unifiedIR is unused (U1000)
internal/golangorgx/tools/gcimporter/ureader_yes.go:563:65: types.NewSignature has been deprecated since Go 1.18: Use [NewSignatureType] instead which allows for type parameters.  (SA1019)
internal/golangorgx/tools/goroot/importcfg.go:60:5: this value of err is never used (SA4006)
internal/golangorgx/tools/goroot/importcfg.go:60:11: Errorf doesn't have side effects and its return value is ignored (SA4017)
internal/golangorgx/tools/imports/fix.go:18:2: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
internal/golangorgx/tools/imports/fix.go:1264:2: field walked is unused (U1000)
internal/golangorgx/tools/jsonrpc2_v2/conn.go:360:11: empty branch (SA9003)
internal/golangorgx/tools/jsonrpc2_v2/conn.go:514:12: empty branch (SA9003)
internal/golangorgx/tools/jsonrpc2_v2/jsonrpc2.go:115:17: func (*async).isDone is unused (U1000)
internal/golangorgx/tools/jsonrpc2_v2/serve.go:168:10: empty branch (SA9003)
internal/golangorgx/tools/jsonrpc2_v2/serve.go:182:10: empty branch (SA9003)
internal/golangorgx/tools/jsonrpc2_v2/serve_go116.go:17:6: func isErrClosed is unused (U1000)
internal/golangorgx/tools/pkgbits/decoder.go:283:5: error var overflow should have name of the form errFoo (ST1012)
internal/golangorgx/tools/refactor/inline/inline.go:1357:26: type assertion to the same type: internalastutil.CloneNode(arg.expr) already has type ast.Expr (S1040)
internal/golangorgx/tools/refactor/inline/util.go:25:6: func clone is unused (U1000)
internal/mod/modload/tidy.go:712:2: should use 'return ctx.Err() == nil' instead of 'if ctx.Err() != nil { return false }; return true' (S1008)
internal/pkg/types.go:72:2: should use 'return ot&^adt.HasDynamic != 0' instead of 'if ot&^adt.HasDynamic != 0 { return true }; return false' (S1008)
internal/registrytest/registry.go:477:9: modzip.Create is deprecated: this will be removed in a future API iteration that reduces dependence on zip archives.  (SA1019)
internal/third_party/yaml/apic.go:52:6: func yaml_reader_read_handler is unused (U1000)
internal/third_party/yaml/apic.go:67:6: func yaml_parser_set_input_reader is unused (U1000)
internal/third_party/yaml/apic.go:76:6: func yaml_parser_set_encoding is unused (U1000)
internal/third_party/yaml/apic.go:84:6: func yaml_emitter_initialize is unused (U1000)
internal/third_party/yaml/apic.go:94:6: func yaml_emitter_delete is unused (U1000)
internal/third_party/yaml/apic.go:99:6: func yaml_string_write_handler is unused (U1000)
internal/third_party/yaml/apic.go:106:6: func yaml_writer_write_handler is unused (U1000)
internal/third_party/yaml/apic.go:112:6: func yaml_emitter_set_output_string is unused (U1000)
internal/third_party/yaml/apic.go:121:6: func yaml_emitter_set_output_writer is unused (U1000)
internal/third_party/yaml/apic.go:130:6: func yaml_emitter_set_encoding is unused (U1000)
internal/third_party/yaml/apic.go:138:6: func yaml_emitter_set_canonical is unused (U1000)
internal/third_party/yaml/apic.go:143:6: func yaml_emitter_set_indent is unused (U1000)
internal/third_party/yaml/apic.go:151:6: func yaml_emitter_set_width is unused (U1000)
internal/third_party/yaml/apic.go:159:6: func yaml_emitter_set_unicode is unused (U1000)
internal/third_party/yaml/apic.go:164:6: func yaml_emitter_set_break is unused (U1000)
internal/third_party/yaml/apic.go:255:6: func yaml_stream_start_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:263:6: func yaml_stream_end_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:270:6: func yaml_document_start_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:285:6: func yaml_document_end_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:317:6: func yaml_scalar_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:331:6: func yaml_sequence_start_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:343:6: func yaml_sequence_end_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:351:6: func yaml_mapping_start_event_initialize is unused (U1000)
internal/third_party/yaml/apic.go:362:6: func yaml_mapping_end_event_initialize is unused (U1000)
internal/third_party/yaml/decode.go:367:19: func (*decoder).ident is unused (U1000)
internal/third_party/yaml/decode.go:724:53: should omit comparison to bool constant, can be simplified to n.implicit (S1002)
internal/third_party/yaml/decode_test.go:18:5: var unmarshalIntTest is unused (U1000)
internal/third_party/yaml/decode_test.go:717:6: type inlineB is unused (U1000)
internal/third_party/yaml/decode_test.go:722:6: type inlineC is unused (U1000)
internal/third_party/yaml/decode_test.go:850:6: type errReader is unused (U1000)
internal/third_party/yaml/decode_test.go:852:18: func errReader.Read is unused (U1000)
internal/third_party/yaml/readerc.go:101:2: empty branch (SA9003)
internal/third_party/yaml/resolve.go:65:6: func longTag is unused (U1000)
internal/third_party/yaml/resolve.go:199:6: func encodeBase64 is unused (U1000)
internal/third_party/yaml/scannerc.go:485:6: func cache is unused (U1000)
internal/third_party/yaml/scannerc.go:573:6: func yaml_parser_scan is unused (U1000)
internal/third_party/yaml/scannerc.go:619:6: func trace is unused (U1000)
internal/third_party/yaml/scannerc.go:1201:9: empty branch (SA9003)
internal/third_party/yaml/scannerc.go:1676:2: should use 'return yaml_parser_scan_version_directive_number(parser, start_mark, minor)' instead of 'if !yaml_parser_scan_version_directive_number(parser, start_mark, minor) { return false }; return true' (S1008)
internal/third_party/yaml/yaml.go:25:2: field strict is unused (U1000)
internal/third_party/yaml/yamlh.go:32:6: type yaml_break_t is unused (U1000)
internal/third_party/yaml/yamlh.go:37:2: const yaml_ANY_BREAK is unused (U1000)
internal/third_party/yaml/yamlh.go:39:2: const yaml_CR_BREAK is unused (U1000)
internal/third_party/yaml/yamlh.go:40:2: const yaml_LN_BREAK is unused (U1000)
internal/third_party/yaml/yamlh.go:41:2: const yaml_CRLN_BREAK is unused (U1000)
internal/third_party/yaml/yamlh.go:76:2: const yaml_ANY_SCALAR_STYLE is unused (U1000)
internal/third_party/yaml/yamlh.go:85:6: type yaml_sequence_style_t is unused (U1000)
internal/third_party/yaml/yamlh.go:90:2: const yaml_ANY_SEQUENCE_STYLE is unused (U1000)
internal/third_party/yaml/yamlh.go:96:6: type yaml_mapping_style_t is unused (U1000)
internal/third_party/yaml/yamlh.go:101:2: const yaml_ANY_MAPPING_STYLE is unused (U1000)
internal/third_party/yaml/yamlh.go:302:24: func (*yaml_event_t).scalar_style is unused (U1000)
internal/third_party/yaml/yamlh.go:303:24: func (*yaml_event_t).sequence_style is unused (U1000)
internal/third_party/yaml/yamlh.go:304:24: func (*yaml_event_t).mapping_style is unused (U1000)
internal/third_party/yaml/yamlh.go:323:2: const yaml_DEFAULT_SCALAR_TAG is unused (U1000)
internal/third_party/yaml/yamlh.go:324:2: const yaml_DEFAULT_SEQUENCE_TAG is unused (U1000)
internal/third_party/yaml/yamlh.go:325:2: const yaml_DEFAULT_MAPPING_TAG is unused (U1000)
internal/third_party/yaml/yamlh.go:328:6: type yaml_node_type_t is unused (U1000)
internal/third_party/yaml/yamlh.go:333:2: const yaml_NO_NODE is unused (U1000)
internal/third_party/yaml/yamlh.go:335:2: const yaml_SCALAR_NODE is unused (U1000)
internal/third_party/yaml/yamlh.go:336:2: const yaml_SEQUENCE_NODE is unused (U1000)
internal/third_party/yaml/yamlh.go:337:2: const yaml_MAPPING_NODE is unused (U1000)
internal/third_party/yaml/yamlh.go:341:6: type yaml_node_item_t is unused (U1000)
internal/third_party/yaml/yamlh.go:344:6: type yaml_node_pair_t is unused (U1000)
internal/third_party/yaml/yamlh.go:350:6: type yaml_node_t is unused (U1000)
internal/third_party/yaml/yamlh.go:384:6: type yaml_document_t is unused (U1000)
internal/third_party/yaml/yamlh.go:517:6: type yaml_alias_data_t is unused (U1000)
internal/third_party/yaml/yamlh.go:555:2: field input_reader is unused (U1000)
internal/third_party/yaml/yamlh.go:608:2: field aliases is unused (U1000)
internal/third_party/yaml/yamlh.go:610:2: field document is unused (U1000)
internal/third_party/yaml/yamlh.go:630:6: type yaml_write_handler_t is unused (U1000)
internal/third_party/yaml/yamlh.go:632:6: type yaml_emitter_state_t is unused (U1000)
internal/third_party/yaml/yamlh.go:637:2: const yaml_EMIT_STREAM_START_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:639:2: const yaml_EMIT_FIRST_DOCUMENT_START_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:640:2: const yaml_EMIT_DOCUMENT_START_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:641:2: const yaml_EMIT_DOCUMENT_CONTENT_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:642:2: const yaml_EMIT_DOCUMENT_END_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:643:2: const yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:644:2: const yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:645:2: const yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:646:2: const yaml_EMIT_FLOW_MAPPING_KEY_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:647:2: const yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:648:2: const yaml_EMIT_FLOW_MAPPING_VALUE_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:649:2: const yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:650:2: const yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:651:2: const yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:652:2: const yaml_EMIT_BLOCK_MAPPING_KEY_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:653:2: const yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:654:2: const yaml_EMIT_BLOCK_MAPPING_VALUE_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:655:2: const yaml_EMIT_END_STATE is unused (U1000)
internal/third_party/yaml/yamlh.go:662:6: type yaml_emitter_t is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:12:2: const output_buffer_size is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:16:2: const output_raw_buffer_size is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:19:2: const initial_stack_size is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:20:2: const initial_queue_size is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:21:2: const initial_string_size is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:58:6: func is_ascii is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:63:6: func is_printable is unused (U1000)
internal/third_party/yaml/yamlprivateh.go:128:6: func is_spacez is unused (U1000)
internal/value/value.go:30:40: cue.Runtime is deprecated: use [Context].  (SA1019)
internal/value/value.go:31:11: cue.Runtime is deprecated: use [Context].  (SA1019)
internal/value/value.go:34:28: cue.Runtime is deprecated: use [Context].  (SA1019)
internal/value/value.go:35:27: cue.Runtime is deprecated: use [Context].  (SA1019)
internal/vcs/vcs_test.go:140:2: this value of err is never used (SA4006)
mod/modregistry/client_test.go:368:9: modzip.Create is deprecated: this will be removed in a future API iteration that reduces dependence on zip archives.  (SA1019)
pkg/encoding/json/manual.go:100:8: cue.Runtime is deprecated: use [Context].  (SA1019)
exit status 1
mvdan commented 3 months ago

We indeed want to move towards making staticcheck happy. We already enforce vet, but we don't enforce staticcheck yet, due to all the deprecation warnings (https://github.com/cue-lang/cue/issues/2480).

We are moving in that direction, it just won't happen overnight due to the amount of work required. I think we can continue using #2480 as a tracking issue for that work. I've given it a slightly better title too.

uhthomas commented 3 months ago

Thanks for pointing out that other issue 😄 I did look, and think I even read it but didn't feel they were entirely the same. Are there plans to enforce static check in CI? Would #2480 also cover the other static check suggestions like unused functions and code simplifications? It would be great if gofumpt could be involved in this somewhere too.

mvdan commented 3 months ago

Yes we do intend to enforce staticcheck in CI - there isn't a tracking issue for it as https://github.com/cue-lang/cue/issues/2480 is a fairly big blocker for that. Although we could start by enforcing staticcheck in CI minus the deprecation warnings - that's something I've thought about before, but haven't looked into yet.

Looking at staticcheck -checks inherit,-SA1019 ./..., there are two vendored sets of packages which cause a significant amount of the warnings:

In both of the cases above, trying to fix all the warnings now is not particularly interesting, as much of the code will go away. So I think it makes sense to start the staticcheck push in earnest once they're gone. But by all means, if you see warnings that are easy to fix, send patches and I'll review and merge :)

As for gofumpt - I would agree, but it's lower priority, at least right now. Enforcing staticcheck feels more urgent. Plus, we don't enforce gofmt nor cue fmt yet, so that's step one!

uhthomas commented 3 months ago

I agree, linting stuff in third_party/ is probably not worthwhile. It should be fairly easy to exclude that. Even filtering out third_party, golangorgx and deprecated, there are around 80 suggestions (52 of which are unused).

❯ go run honnef.co/go/tools/cmd/staticcheck@latest ./...
cmd/cue/cmd/custom.go:116:3: the surrounding loop is unconditionally terminated (SA4004)
cue/build/import.go:107:11: empty branch (SA9003)
cue/format/import.go:28:6: func sortImports is unused (U1000)
cue/format/import.go:51:6: func setRelativePos is unused (U1000)
cue/format/import.go:63:6: func hasDoc is unused (U1000)
cue/format/import.go:72:6: func importPath is unused (U1000)
cue/format/import.go:80:6: func importName is unused (U1000)
cue/format/import.go:88:6: func importComment is unused (U1000)
cue/format/import.go:98:6: func collapse is unused (U1000)
cue/format/import.go:110:6: type posSpan is unused (U1000)
cue/format/import.go:115:6: func sortSpecs is unused (U1000)
cue/format/import.go:151:6: type byImportSpec is unused (U1000)
cue/format/import.go:153:23: func byImportSpec.Len is unused (U1000)
cue/format/import.go:154:23: func byImportSpec.Swap is unused (U1000)
cue/format/import.go:155:23: func byImportSpec.Less is unused (U1000)
cue/instance.go:168:23: func (*Instance).setError is unused (U1000)
cue/instance.go:173:23: func (*Instance).eval is unused (U1000)
cue/interpreter/wasm/call.go:78:2: should use 'return u == 1' instead of 'if u == 1 { return true }; return false' (S1008)
cue/interpreter/wasm/wasm_test.go:96:6: func copyWasmFiles is unused (U1000)
cue/interpreter/wasm/wasm_test.go:108:6: func copyFile is unused (U1000)
cue/interpreter/wasm/wasm_test.go:116:6: func check is unused (U1000)
cue/interpreter/wasm/wasm_test.go:129:6: func loadDir is unused (U1000)
cue/interpreter/wasm/wasm_test.go:135:6: func dirInstance is unused (U1000)
cue/interpreter/wasm/wasm_test.go:155:6: func loadFile is unused (U1000)
cue/interpreter/wasm/wasm_test.go:159:6: func must is unused (U1000)
cue/load/loader_common.go:175:3: redundant return statement (S1023)
cue/types.go:806:6: func hasDisjunction is unused (U1000)
cue/types.go:828:6: func stripNonDefaults is unused (U1000)
cue/types_test.go:3392:9: identical expressions on the left and right side of the '&&' operator (SA4000)
encoding/openapi/build.go:239:2: empty branch (SA9003)
internal/ci/checks/commit.go:54:10: error strings should not be capitalized (ST1005)
internal/core/adt/composite.go:565:2: empty branch (SA9003)
internal/core/adt/constraints.go:47:23: func (*nodeContext).insertListEllipsis is unused (U1000)
internal/core/adt/dev.go:77:24: func combinedFlags.ignore is unused (U1000)
internal/core/adt/disjunct2.go:584:6: func isPartialNode is unused (U1000)
internal/core/adt/disjunct2.go:585:2: should use 'return d.node.status == finalized' instead of 'if d.node.status == finalized { return true }; return false' (S1008)
internal/core/adt/disjunct2.go:741:3: empty branch (SA9003)
internal/core/adt/errors.go:132:6: func isIncomplete is unused (U1000)
internal/core/adt/eval.go:57:5: var structSentinel is unused (U1000)
internal/core/adt/eval.go:1546:2: field index is unused (U1000)
internal/core/adt/eval.go:2217:2: should use 'return len(n.exprs) < len(exprs)' instead of 'if len(n.exprs) < len(exprs) { return true }; return false' (S1008)
internal/core/adt/eval.go:2471:17: type assertion to the same type: m.Src already has type ast.Expr (S1040)
internal/core/adt/eval_test.go:124:4: empty branch (SA9003)
internal/core/adt/eval_test.go:235:2: should merge variable declaration with assignment on next line (S1021)
internal/core/adt/export_test.go:94:3: this value of ci is never used (SA4006)
internal/core/adt/fields.go:534:2: empty branch (SA9003)
internal/core/adt/fields.go:600:4: empty branch (SA9003)
internal/core/adt/overlay.go:226:3: should replace loop with d.disjunctions = append(d.disjunctions, n.disjunctions...) (S1011)
internal/core/adt/overlay.go:343:2: empty branch (SA9003)
internal/core/adt/overlay.go:362:4: empty branch (SA9003)
internal/core/adt/sched.go:112:23: func (*taskContext).newTask is unused (U1000)
internal/core/adt/sched.go:139:21: func schedState.done is unused (U1000)
internal/core/adt/sched.go:390:3: empty branch (SA9003)
internal/core/adt/sched.go:599:2: field blockStack is unused (U1000)
internal/core/adt/sched_test.go:186:3: field err is unused (U1000)
internal/core/adt/states.go:173:2: const leftOfMaxCoreCondition is unused (U1000)
internal/core/adt/states.go:175:2: const finalStateKnown is unused (U1000)
internal/core/adt/states.go:177:2: const preValidation is unused (U1000)
internal/core/adt/states.go:209:2: const scalarConjunct is unused (U1000)
internal/core/adt/tasks.go:193:6: func processFinalizeDisjunctions is unused (U1000)
internal/core/adt/unify.go:429:2: redundant return statement (S1023)
internal/core/adt/unify.go:459:2: empty branch (SA9003)
internal/core/compile/builtin.go:27:2: var stringParam is unused (U1000)
internal/core/compile/compile.go:126:20: func (*compiler).reset is unused (U1000)
internal/core/subsume/structural.go:21:20: func (*subsumer).subsumes is unused (U1000)
internal/core/subsume/structural.go:40:20: func (*subsumer).conjunct is unused (U1000)
internal/core/subsume/structural.go:44:20: func (*subsumer).c is unused (U1000)
internal/core/subsume/structural.go:48:6: func isBottomConjunct is unused (U1000)
internal/core/subsume/structural.go:53:20: func (*subsumer).node is unused (U1000)
internal/core/subsume/structural.go:60:20: func (*subsumer).structural is unused (U1000)
internal/core/subsume/structural.go:178:20: func (*subsumer).structLit is unused (U1000)
internal/core/subsume/structural.go:225:6: type collatedDecls is unused (U1000)
internal/core/subsume/structural.go:236:6: func newCollatedDecls is unused (U1000)
internal/core/subsume/structural.go:240:6: type field is unused (U1000)
internal/core/subsume/structural.go:245:25: func (*collatedDecls).collate is unused (U1000)
internal/core/subsume/vertex.go:435:6: identical expressions on the left and right side of the '||' operator (SA4000)
internal/envflag/flag.go:89:5: error var InvalidError should have name of the form ErrFoo (ST1012)
internal/mod/modload/tidy.go:712:2: should use 'return ctx.Err() == nil' instead of 'if ctx.Err() != nil { return false }; return true' (S1008)
internal/pkg/types.go:72:2: should use 'return ot&^adt.HasDynamic != 0' instead of 'if ot&^adt.HasDynamic != 0 { return true }; return false' (S1008)
internal/vcs/vcs_test.go:140:2: this value of err is never used (SA4006)
exit status 1

Would it make sense for this to be the tracking issue for:

mvdan commented 3 months ago

Sure. Let's use it just to enforce a subset of staticcheck (minus SA1019 for the deprecation warnings, as that's https://github.com/cue-lang/cue/issues/2480, and minus third_party and golangorgx). I don't think it's worthwhile to use golangci-lint for this purpose - staticcheck on its own is basically what we want on top of vet and gofmt or gofumpt.

I don't think we should aim to enforce gofumpt just yet. We need to enforce gofmt and cue fmt first. Enforcing gofumpt is also a sweeping change that will likely cause plenty of merge conflicts, so I'd want to coordinate with everyone if we wanted to attempt it.

mvdan commented 2 months ago

internal/third_party is now gone since https://review.gerrithub.io/c/cue-lang/cue/+/1199541, so that's one chunk we no longer need to worry about.

uhthomas commented 2 months ago

Fantastic! I'm happy to apply some static check fixes if you like.

mvdan commented 2 months ago

Sounds good. Just give me five minutes as I'm about to merge some I did this morning.

mvdan commented 1 month ago

Even filtering out third_party, golangorgx and deprecated, there are around 80 suggestions (52 of which are unused).

With third_party now gone, and after chipping away at some more of these, we are down to 53 non-deprecation warnings:

$ staticcheck -checks inherit,-SA1019 ./... |& grep -v /golangorgx/ | wc -l
53
mvdan commented 1 month ago

Fixing a few more in this stack: https://review.gerrithub.io/c/cue-lang/cue/+/1202602