Skip to content

Commit

Permalink
move lint back
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 8, 2024
1 parent 7d017ab commit 1d307e2
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 57 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/zarf-dev/zarf/src/cmd"
"github.com/zarf-dev/zarf/src/config"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/lint"
)

//go:embed cosign.pub
Expand Down Expand Up @@ -41,6 +41,6 @@ func main() {
}()

config.CosignPublicKey = cosignPublicKey
rules.ZarfSchema = zarfSchema
lint.ZarfSchema = zarfSchema
cmd.Execute(ctx)
}
4 changes: 2 additions & 2 deletions src/pkg/rules/findings.go → src/pkg/lint/findings.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"testing"
Expand Down
27 changes: 13 additions & 14 deletions src/pkg/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import (
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/packager/composer"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/types"
)

// Validate lints the given Zarf package
func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error {
var findings []rules.PackageFinding
var findings []PackageFinding
if err := os.Chdir(createOpts.BaseDir); err != nil {
return fmt.Errorf("unable to access directory %q: %w", createOpts.BaseDir, err)
}
Expand All @@ -37,7 +36,7 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error {
return err
}
findings = append(findings, compFindings...)
schemaFindings, err := rules.ValidatePackageSchema()
schemaFindings, err := ValidatePackageSchema()
if err != nil {
return err
}
Expand All @@ -47,15 +46,15 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error {
message.Successf("0 findings for %q", pkg.Metadata.Name)
return nil
}
rules.PrintFindings(findings, rules.SevWarn, createOpts.BaseDir, pkg.Metadata.Name)
if rules.HasSevOrHigher(findings, rules.SevErr) {
PrintFindings(findings, SevWarn, createOpts.BaseDir, pkg.Metadata.Name)
if HasSevOrHigher(findings, SevErr) {
return errors.New("errors during lint")
}
return nil
}

func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) {
var findings []rules.PackageFinding
func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) {
var findings []PackageFinding

for i, component := range pkg.Components {
arch := config.GetArch(pkg.Metadata.Architecture)
Expand All @@ -76,7 +75,7 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty
if err != nil {
return nil, err
}
compFindings = append(compFindings, rules.CheckComponentValues(component, node.Index())...)
compFindings = append(compFindings, CheckComponentValues(component, node.Index())...)
for i := range compFindings {
compFindings[i].PackagePathOverride = node.ImportLocation()
compFindings[i].PackageNameOverride = node.OriginalPackageName()
Expand All @@ -88,8 +87,8 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty
return findings, nil
}

func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) {
var findings []rules.PackageFinding
func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) {
var findings []PackageFinding
templateMap := map[string]string{}

setVarsAndWarn := func(templatePrefix string, deprecated bool) error {
Expand All @@ -101,19 +100,19 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat
var unSetTemplates bool
for key := range yamlTemplates {
if deprecated {
findings = append(findings, rules.PackageFinding{
findings = append(findings, PackageFinding{
Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key),
Severity: rules.SevWarn,
Severity: SevWarn,
})
}
if _, present := createOpts.SetVariables[key]; !present {
unSetTemplates = true
}
}
if unSetTemplates {
findings = append(findings, rules.PackageFinding{
findings = append(findings, PackageFinding{
Description: lang.UnsetVarLintWarning,
Severity: rules.SevWarn,
Severity: SevWarn,
})
}
for key, value := range createOpts.SetVariables {
Expand Down
7 changes: 3 additions & 4 deletions src/pkg/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/config/lang"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/types"
)

Expand Down Expand Up @@ -51,13 +50,13 @@ func TestFillComponentTemplate(t *testing.T) {

findings, err := fillComponentTemplate(&component, createOpts)
require.NoError(t, err)
expectedFindings := []rules.PackageFinding{
expectedFindings := []PackageFinding{
{
Severity: rules.SevWarn,
Severity: SevWarn,
Description: "There are templates that are not set and won't be evaluated during lint",
},
{
Severity: rules.SevWarn,
Severity: SevWarn,
Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, "KEY2", "KEY2", "KEY2"),
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/rules/rules.go → src/pkg/lint/rules.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/rules/rules_test.go → src/pkg/lint/rules_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/rules/schema.go → src/pkg/lint/schema.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/rules/schema_test.go → src/pkg/lint/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/rules/validate.go → src/pkg/lint/validate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package rules checks Zarf packages and reports any findings or errors
package rules
// Package lint contains functions for verifying zarf yaml files are valid
package lint

import (
"fmt"
Expand Down
5 changes: 0 additions & 5 deletions src/pkg/packager/composer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/zarf-dev/zarf/src/extensions/bigbang"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/packager/deprecated"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/pkg/variables"
"github.com/zarf-dev/zarf/src/pkg/zoci"
Expand Down Expand Up @@ -142,10 +141,6 @@ func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int,
return ic, nil
}

if err := rules.ValidateComponent(node.ZarfComponent); err != nil {
return ic, err
}

// ensure that remote components are not importing other remote components
if node.prev != nil && node.prev.Import.URL != "" && isRemote {
return ic, fmt.Errorf("detected malformed import chain, cannot import remote components from remote components")
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/creator/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/test/testutil"
"github.com/zarf-dev/zarf/src/types"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestLoadPackageDefinition(t *testing.T) {
creator: NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}),
},
}
rules.ZarfSchema = testutil.LoadSchema(t, "../../../../zarf.schema.json")
lint.ZarfSchema = testutil.LoadSchema(t, "../../../../zarf.schema.json")

for _, tt := range tests {
tt := tt
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/packager/creator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import (

"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/config"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/pkg/packager/deprecated"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/types"
)

// Validate errors if a package violates the schema or any runtime validations
// This must be run while in the parent directory of the zarf.yaml being validated
func Validate(pkg v1alpha1.ZarfPackage, baseDir string) error {
if err := rules.ValidatePackage(pkg); err != nil {
if err := lint.ValidatePackage(pkg); err != nil {
return fmt.Errorf("package validation failed: %w", err)
}

findings, err := rules.ValidatePackageSchema()
findings, err := lint.ValidatePackageSchema()
if err != nil {
return fmt.Errorf("unable to check schema: %w", err)
}

if rules.HasSevOrHigher(findings, rules.SevErr) {
rules.PrintFindings(findings, rules.SevErr, baseDir, pkg.Metadata.Name)
if lint.HasSevOrHigher(findings, lint.SevErr) {
lint.PrintFindings(findings, lint.SevErr, baseDir, pkg.Metadata.Name)
return fmt.Errorf("found errors in schema")
}

Expand Down
6 changes: 3 additions & 3 deletions src/pkg/packager/filters/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (

"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/lint"
)

func TestLocalOSFilter(t *testing.T) {
pkg := v1alpha1.ZarfPackage{}
for _, os := range rules.SupportedOS() {
for _, os := range lint.SupportedOS() {
pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{
Only: v1alpha1.ZarfComponentOnlyTarget{
LocalOS: os,
},
})
}

for _, os := range rules.SupportedOS() {
for _, os := range lint.SupportedOS() {
filter := ByLocalOS(os)
result, err := filter.Apply(pkg)
if os == "" {
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/config"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/rules"
)

// Generate generates a Zarf package definition.
Expand Down Expand Up @@ -74,7 +74,7 @@ func (p *Packager) Generate(ctx context.Context) (err error) {
p.cfg.Pkg.Components[i].Images = images[name]
}

if err := rules.ValidatePackage(p.cfg.Pkg); err != nil {
if err := lint.ValidatePackage(p.cfg.Pkg); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/test/testutil"
"github.com/zarf-dev/zarf/src/types"
)
Expand All @@ -18,7 +18,7 @@ func TestFindImages(t *testing.T) {

ctx := testutil.TestContext(t)

rules.ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json")
lint.ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json")

cfg := &types.PackagerConfig{
CreateOpts: types.ZarfCreateOptions{
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/sources/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/pkg/cluster"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/pkg/packager/filters"
"github.com/zarf-dev/zarf/src/pkg/rules"
"github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/types"
)
Expand All @@ -25,7 +25,7 @@ var (

// NewClusterSource creates a new cluster source.
func NewClusterSource(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) {
if !rules.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) {
if !lint.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) {
return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource)
}

Expand Down

0 comments on commit 1d307e2

Please sign in to comment.