Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable linter: maintidx #177

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ run:
issues-exit-code: 2
skip-dirs:
- "hack"
# External code from containerd/containerd
- "pkg/docker"

linters:
enable-all: true
Expand Down Expand Up @@ -47,9 +49,6 @@ linters:
- nestif # Some nexted if statements are 8 or 9 deep.
- dupl # Check code duplications.
- cyclop # Complex functions are not good.
- maintidx # Too complex code is not good.
# name: push, Cyclomatic Complexity: 35
# name: apply, Cyclomatic Complexity: 51
- gochecknoinits # Init functions cause an import to have side effects,
# and side effects are hard to test,
# reduce readability and increase the complexity of code.
Expand Down Expand Up @@ -170,3 +169,6 @@ issues:
- source: "// .* #\\d+"
linters:
- godox
- path: ignore/.*\.go
linters:
- dupword
7 changes: 5 additions & 2 deletions cmds/demoplugin/accessmethods/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import (
"strings"

"github.com/mandelsoft/filepath/pkg/filepath"

"github.com/open-component-model/ocm/cmds/common"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/runtime"
)

const NAME = "demo"
const VERSION = "v1"
const (
NAME = "demo"
VERSION = "v1"
)

type AccessSpec struct {
runtime.ObjectVersionedType `json:",inline"`
Expand Down
9 changes: 5 additions & 4 deletions cmds/demoplugin/uploaders/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"strings"

"github.com/open-component-model/ocm/cmds/common"
"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/runtime"

"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
)

const NAME = "demo"
const VERSION = "v1"
const (
NAME = "demo"
VERSION = "v1"
)

type TargetSpec struct {
runtime.ObjectVersionedType `json:",inline"`
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (o *CLIOptions) Complete() error {
return errors.Wrapf(err, "attribute %s", s.Name)
}
}
err = ctx.ApplyConfig(spec, "cli")
_ = ctx.ApplyConfig(spec, "cli")
}
return plugincacheattr.Get(o.Context.OCMContext()).RegisterExtensions()
}
Expand All @@ -327,7 +327,7 @@ func NewVersionCommand(ctx clictx.Context) *cobra.Command {
Use: "version",
Aliases: []string{"v"},
Short: "displays the version",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
v := version.Get()
out.Outf(ctx, "%#v\n", v)
},
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocicmds/artefacts/transfer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewAction(ctx clictx.Context, session oci.Session, target string, transferR
}

if ref.IsVersion() && transferRepo {
return nil, errors.Newf("repository names cannot be transferred for for a given target version")
return nil, errors.Newf("repository names cannot be transferred for a given target version")
}
if ref.IsRegistry() {
transferRepo = true
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/common/addconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (o *ResourceConfigAdderCommand) ProcessResourceDescriptions(listkey string,
}
r = string(b)
}
current += "\n---\n" + string(r)
current += "\n---\n" + r
}

source := NewModifiedResourceSpecificationsFile(current, o.ConfigFile, fs)
Expand Down
24 changes: 16 additions & 8 deletions cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/options"
)

var HintOption = options.HintOption
var MediaTypeOption = options.MediatypeOption
var (
HintOption = options.HintOption
MediaTypeOption = options.MediatypeOption
)

var PathOption = flagsets.NewStringOptionType("inputPath", "path field for input")

var CompressOption = flagsets.NewBoolOptionType("inputCompress", "compress option for input")
var ExcludeOption = flagsets.NewStringArrayOptionType("inputExcludes", "excludes (path) for inputs")
var (
CompressOption = flagsets.NewBoolOptionType("inputCompress", "compress option for input")
ExcludeOption = flagsets.NewStringArrayOptionType("inputExcludes", "excludes (path) for inputs")
)

var IncludeOption = flagsets.NewStringArrayOptionType("inputIncludes", "includes (path) for inputs")
var PreserveDirOption = flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs")
var (
IncludeOption = flagsets.NewStringArrayOptionType("inputIncludes", "includes (path) for inputs")
PreserveDirOption = flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs")
)

var FollowSymlinksOption = flagsets.NewBoolOptionType("inputFollowSymlinks", "follow symbolic links during archive creation for inputs")
var VariantsOption = flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs")
var (
FollowSymlinksOption = flagsets.NewBoolOptionType("inputFollowSymlinks", "follow symbolic links during archive creation for inputs")
VariantsOption = flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs")
)

var LibrariesOption = flagsets.NewStringArrayOptionType("inputLibraries", "library path for inputs")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
}

func usage() string {
return file.Usage("The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the the resources file.") + `
return file.Usage("The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the resources file.") + `
- **<code>values</code>** *map[string]any*

This OPTIONAL property describes an additional value binding for the template processing. It will be available
Expand Down
15 changes: 9 additions & 6 deletions cmds/ocm/commands/ocmcmds/common/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ type ContentResourceSpecificationsProvider struct {
options flagsets.ConfigOptions
}

var _ ResourceSpecificationsProvider = (*ContentResourceSpecificationsProvider)(nil)
var _ ResourceSpecifications = (*ContentResourceSpecificationsProvider)(nil)
var (
_ ResourceSpecificationsProvider = (*ContentResourceSpecificationsProvider)(nil)
_ ResourceSpecifications = (*ContentResourceSpecificationsProvider)(nil)
)

func NewContentResourceSpecificationProvider(ctx clictx.Context, name string, adder flagsets.ConfigAdder, deftype string, types ...flagsets.ConfigOptionType) *ContentResourceSpecificationsProvider {
a := &ContentResourceSpecificationsProvider{
Expand Down Expand Up @@ -355,7 +357,8 @@ func (a *ContentResourceSpecificationsProvider) Get() (string, error) {
return "", err
}

r, err := json.Marshal(data)
//nolint:errchkjson // We don't care about this error.
r, _ := json.Marshal(data)
return string(r), nil
}

Expand Down Expand Up @@ -443,12 +446,12 @@ func (o *ResourceAdderCommand) ProcessResourceDescriptions(listkey string, h Res
defer obj.Close()

for _, r := range resources {
ictx := ictx.Section("adding %s...", r.Spec().Info())
isctx := ictx.Section("adding %s...", r.Spec().Info())
mandelsoft marked this conversation as resolved.
Show resolved Hide resolved
if h.RequireInputs() {
if r.input.Input != nil {
var acc ocm.AccessSpec
// Local Blob
blob, hint, berr := r.input.Input.GetBlob(ictx, common.VersionedElementKey(obj), r.path)
blob, hint, berr := r.input.Input.GetBlob(isctx, common.VersionedElementKey(obj), r.path)
if berr != nil {
return errors.Wrapf(berr, "cannot get resource blob for %q(%s)", r.spec.GetName(), r.source)
}
Expand Down Expand Up @@ -479,7 +482,7 @@ func determineResources(printer common.Printer, ctx clictx.Context, ictx inputs.
if err != nil {
return nil, err
}
parsed, err := templ.Execute(string(r))
parsed, err := templ.Execute(r)
if err != nil {
return nil, errors.Wrapf(err, "error during variable substitution")
}
Expand Down
9 changes: 6 additions & 3 deletions cmds/ocm/commands/ocmcmds/references/add/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ type ReferenceResourceSpecificationProvider struct {
*ocmcomm.ResourceMetaDataSpecificationsProvider
}

var _ ocmcomm.ResourceSpecificationsProvider = (*ReferenceResourceSpecificationProvider)(nil)
var _ ocmcomm.ResourceSpecifications = (*ReferenceResourceSpecificationProvider)(nil)
var (
_ ocmcomm.ResourceSpecificationsProvider = (*ReferenceResourceSpecificationProvider)(nil)
_ ocmcomm.ResourceSpecifications = (*ReferenceResourceSpecificationProvider)(nil)
)

func NewReferenceSpecificatonProvider() ocmcomm.ResourceSpecificationsProvider {
a := &ReferenceResourceSpecificationProvider{
Expand Down Expand Up @@ -47,7 +49,8 @@ func (a *ReferenceResourceSpecificationProvider) Get() (string, error) {
return "", err
}

r, err := json.Marshal(data)
//nolint:errchkjson // We don't care about this error.
r, _ := json.Marshal(data)
return string(r), nil
}

Expand Down
Loading