Skip to content

Commit

Permalink
refactor lint
Browse files Browse the repository at this point in the history
fix e2e tests

check for var in component import

improve tests
  • Loading branch information
AustinAbro321 committed Jun 24, 2024
1 parent b72d4c8 commit d9f1f31
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 348 deletions.
16 changes: 6 additions & 10 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager"
"github.com/defenseunicorns/zarf/src/pkg/packager/lint"
"github.com/defenseunicorns/zarf/src/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"
Expand Down Expand Up @@ -249,19 +248,16 @@ var devLintCmd = &cobra.Command{
Aliases: []string{"l"},
Short: lang.CmdDevLintShort,
Long: lang.CmdDevLintLong,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {

Check warning on line 251 in src/cmd/dev.go

View check run for this annotation

Codecov / codecov/patch

src/cmd/dev.go#L251

Added line #L251 was not covered by tests
pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args)
v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper)
validator, err := lint.Validate(cmd.Context(), pkgConfig.CreateOpts)
if err != nil {
message.Fatal(err, err.Error())
}
validator.DisplayFormattedMessage()
if !validator.IsSuccess() {
os.Exit(1)
}

pkgClient := packager.NewOrDie(&pkgConfig)
defer pkgClient.ClearTempPaths()

Check warning on line 258 in src/cmd/dev.go

View check run for this annotation

Codecov / codecov/patch

src/cmd/dev.go#L257-L258

Added lines #L257 - L258 were not covered by tests

return pkgClient.Lint(cmd.Context())

Check warning on line 260 in src/cmd/dev.go

View check run for this annotation

Codecov / codecov/patch

src/cmd/dev.go#L260

Added line #L260 was not covered by tests
},
}

Expand Down
29 changes: 29 additions & 0 deletions src/pkg/packager/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package packager

import (
"context"
"errors"
"fmt"
"os"
"runtime"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager/creator"
"github.com/defenseunicorns/zarf/src/pkg/packager/filters"
"github.com/defenseunicorns/zarf/src/pkg/packager/lint"
"github.com/defenseunicorns/zarf/src/types"
)

Expand Down Expand Up @@ -105,3 +107,30 @@ func (p *Packager) DevDeploy(ctx context.Context) error {
// cd back
return os.Chdir(cwd)
}

// Lint ensures a package is valid & follows suggested conventions
func (p *Packager) Lint(ctx context.Context) (err error) {
config.CommonOptions.Confirm = true

Check warning on line 113 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L112-L113

Added lines #L112 - L113 were not covered by tests

if err := os.Chdir(p.cfg.CreateOpts.BaseDir); err != nil {
return fmt.Errorf("unable to access directory %q: %w", p.cfg.CreateOpts.BaseDir, err)

Check warning on line 116 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}

lintFindings, err := lint.Validate(ctx, p.cfg.CreateOpts)
if err != nil {
return fmt.Errorf("linting failed: %w", err)

Check warning on line 121 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L119-L121

Added lines #L119 - L121 were not covered by tests
}

if len(lintFindings) == 0 {
message.Successf("0 findings for %q", p.cfg.Pkg.Metadata.Name)
return nil

Check warning on line 126 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L124-L126

Added lines #L124 - L126 were not covered by tests
}

lint.PrintFindings(lintFindings, types.SevWarn, p.cfg.CreateOpts.BaseDir, p.cfg.Pkg.Metadata.Name)

Check warning on line 129 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L129

Added line #L129 was not covered by tests

if lint.HasErrors(lintFindings) {
return errors.New("errors during lint")

Check warning on line 132 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L131-L132

Added lines #L131 - L132 were not covered by tests
}

return nil

Check warning on line 135 in src/pkg/packager/dev.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/dev.go#L135

Added line #L135 was not covered by tests
}
Loading

0 comments on commit d9f1f31

Please sign in to comment.