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

chore: update linting configuration #627

Merged
merged 7 commits into from
May 21, 2024
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
9 changes: 0 additions & 9 deletions .github/workflows/scan-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,3 @@ jobs:
uses: pre-commit/action@f7acafac0271bdd064cdfa1b13f17b4350e565ed #
with:
extra_args: --all-files --verbose # pre-commit run --all-files --verbose

- name: Run Revive Action by pulling pre-built image
uses: docker://morphy/revive-action:v2@sha256:087d4e61077087755711ab7e9fae3cc899b7bb07ff8f6a30c3dfb240b1620ae8
with:
config: revive.toml
# Exclude patterns, separated by semicolons (optional)
exclude: "src/cmd/viper.go;src/config/lang/lang.go"
# Path pattern (default: ./...)
path: "./src/..."
42 changes: 42 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,45 @@ linters:
- goimports
- gosec
- govet
- staticcheck
- nilerr
- revive

linters-settings:
govet:
enable-all: true
disable:
- shadow
- fieldalignment
- unusedwrite
nolintlint:
require-specific: true

unused:
local-variables-are-used: false

revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.55.2
hooks:
- id: golangci-lint
- id: golangci-lint-full
args: [--timeout=5m]
linters:
- repo: local
hooks:
- id: check-docs-and-schema
Expand Down
31 changes: 0 additions & 31 deletions revive.toml

This file was deleted.

3 changes: 1 addition & 2 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/config/lang"
"github.com/defenseunicorns/uds-cli/src/types"
"github.com/defenseunicorns/zarf/src/cmd/common"
zarfCommon "github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/spf13/cobra"
Expand All @@ -28,7 +27,7 @@ var rootCmd = &cobra.Command{
Use: "uds COMMAND",
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
// Skip for vendor-only commands
if common.CheckVendorOnlyFromPath(cmd) {
if zarfCommon.CheckVendorOnlyFromPath(cmd) {
return
}

Expand Down
3 changes: 0 additions & 3 deletions src/pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ func deployPackages(packages []types.Package, resume bool, b *Bundle) error {
}

pkgClient := packager.NewOrDie(&pkgCfg, packager.WithSource(source), packager.WithTemp(opts.PackageSource))
if err != nil {
return err
}

if err := pkgClient.Deploy(); err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions src/pkg/bundle/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ func (op *ociProvider) LoadBundle(opts types.BundlePullOptions, _ int) (*types.U
// grab sha of zarf image manifest and pull it down
sha := strings.Split(pkg.Ref, "@sha256:")[1] // this is where we use the SHA appended to the Zarf pkg inside the bundle
manifestDesc := rootManifest.Locate(sha)
if err != nil {
return nil, nil, err
}
manifestBytes, err := op.FetchLayer(ctx, manifestDesc)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -311,7 +308,7 @@ func ValidateArch(arch string) error {
}
if c != nil {
clusterArchs, err = c.GetArchitectures()
if err == nil {
if err != nil {
return err
}
// check if bundle arch is in clusterArchs
Expand Down
3 changes: 0 additions & 3 deletions src/pkg/bundle/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func removePackages(packagesToRemove []types.Package, b *Bundle) error {
}

pkgClient := packager.NewOrDie(&pkgCfg, packager.WithSource(source), packager.WithTemp(pkgTmp))
if err != nil {
return err
}
defer pkgClient.ClearTempPaths()

if err := pkgClient.Remove(); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions src/pkg/bundle/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ func (tp *tarballBundleProvider) PublishBundle(bundle types.UDSBundle, remote *o

// copy bundle
copyOpts := utils.CreateCopyOpts(layersToPush, config.CommonOptions.OCIConcurrency)
if err != nil {
return err
}
progressBar := message.NewProgressBar(estimatedBytes, fmt.Sprintf("Publishing %s:%s", remote.Repo().Reference.Repository, remote.Repo().Reference.Reference))
defer progressBar.Stop()
remote.SetProgressWriter(progressBar)
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/bundler/fetcher/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ func (f *localFetcher) toBundle(pkg zarfTypes.ZarfPackage, pkgTmp string) ([]oci
if exists, err := f.cfg.Store.Exists(ctx, desc); !exists && err == nil {
if err := f.cfg.Store.Push(ctx, desc, layer); err != nil {
return nil, err
} else if err != nil {
return nil, err
}
}
descs = append(descs, desc)
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/bundler/localbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ func writeTarball(bundle *types.UDSBundle, artifactPathMap types.PathMap, output
filename := fmt.Sprintf("%s%s-%s-%s.tar.zst", config.BundlePrefix, bundle.Metadata.Name, bundle.Metadata.Architecture, bundle.Metadata.Version)

if !helpers.IsDir(outputDir) {
os.MkdirAll(outputDir, 0755)
err := os.MkdirAll(outputDir, 0755)
if err != nil {
return err
}
}

dst := filepath.Join(outputDir, filename)
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/sources/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,13 @@ func (r *RemoteBundle) downloadPkgFromRemoteBundle() ([]ocispec.Descriptor, erro
estimatedBytes := int64(0)
layersToPull := []ocispec.Descriptor{pkgManifestDesc}
layersInBundle := []ocispec.Descriptor{pkgManifestDesc}
numLayersVerified := 0.0

for _, layer := range pkgManifest.Layers {
ok, err := r.Remote.Repo().Blobs().Exists(ctx, layer)
if err != nil {
return nil, err
}
progressBar.Add(1)
numLayersVerified++
if ok {
estimatedBytes += layer.Size
layersInBundle = append(layersInBundle, layer)
Expand Down
3 changes: 1 addition & 2 deletions src/pkg/sources/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/packager/filters"
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
zarfUtils "github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"
zarfTypes "github.com/defenseunicorns/zarf/src/types"
av4 "github.com/mholt/archiver/v4"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (t *TarballBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Com
}

// if in dev mode and package is a zarf init config, return an empty package
if config.Dev && pkg.Kind == types.ZarfInitConfig {
if config.Dev && pkg.Kind == zarfTypes.ZarfInitConfig {
return zarfTypes.ZarfPackage{}, nil, nil
}

Expand Down
2 changes: 0 additions & 2 deletions src/pkg/utils/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ func ToOCIRemote(t any, mediaType string, remote *oci.OrasRemote) (*ocispec.Desc
func CreateCopyOpts(layersToPull []ocispec.Descriptor, concurrency int) oras.CopyOptions {
var copyOpts oras.CopyOptions
copyOpts.Concurrency = concurrency
estimatedBytes := int64(0)
var shas []string
for _, layer := range layersToPull {
if len(layer.Digest.String()) > 0 {
estimatedBytes += layer.Size
shas = append(shas, layer.Digest.Encoded())
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ func ConfigureLogs(cmd *cobra.Command) error {
return err
}

logWriter := io.MultiWriter(logFile)

// use Zarf pterm output
message.Notef("Saving log file to %s", tmpLogLocation)
logWriter = io.MultiWriter(os.Stderr, logFile)
logWriter := io.MultiWriter(os.Stderr, logFile)
pterm.SetDefaultOutput(logWriter)
message.Debugf(fmt.Sprintf("Saving log file to %s", tmpLogLocation))
return nil
Expand Down
Loading