From 1d307e28c084a7726ac31d684b4a6e943374d465 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 8 Aug 2024 15:32:53 +0000 Subject: [PATCH] move lint back Signed-off-by: Austin Abro --- main.go | 4 ++-- src/pkg/{rules => lint}/findings.go | 4 ++-- src/pkg/{rules => lint}/findings_test.go | 4 ++-- src/pkg/lint/lint.go | 27 ++++++++++++------------ src/pkg/lint/lint_test.go | 7 +++--- src/pkg/{rules => lint}/rules.go | 4 ++-- src/pkg/{rules => lint}/rules_test.go | 4 ++-- src/pkg/{rules => lint}/schema.go | 4 ++-- src/pkg/{rules => lint}/schema_test.go | 4 ++-- src/pkg/{rules => lint}/validate.go | 4 ++-- src/pkg/{rules => lint}/validate_test.go | 4 ++-- src/pkg/packager/composer/list.go | 5 ----- src/pkg/packager/creator/creator_test.go | 4 ++-- src/pkg/packager/creator/utils.go | 10 ++++----- src/pkg/packager/filters/os_test.go | 6 +++--- src/pkg/packager/generate.go | 4 ++-- src/pkg/packager/prepare_test.go | 4 ++-- src/pkg/packager/sources/cluster.go | 4 ++-- 18 files changed, 50 insertions(+), 57 deletions(-) rename src/pkg/{rules => lint}/findings.go (97%) rename src/pkg/{rules => lint}/findings_test.go (96%) rename src/pkg/{rules => lint}/rules.go (97%) rename src/pkg/{rules => lint}/rules_test.go (97%) rename src/pkg/{rules => lint}/schema.go (95%) rename src/pkg/{rules => lint}/schema_test.go (98%) rename src/pkg/{rules => lint}/validate.go (99%) rename src/pkg/{rules => lint}/validate_test.go (99%) diff --git a/main.go b/main.go index df0b3a78e7..f424789b54 100644 --- a/main.go +++ b/main.go @@ -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 @@ -41,6 +41,6 @@ func main() { }() config.CosignPublicKey = cosignPublicKey - rules.ZarfSchema = zarfSchema + lint.ZarfSchema = zarfSchema cmd.Execute(ctx) } diff --git a/src/pkg/rules/findings.go b/src/pkg/lint/findings.go similarity index 97% rename from src/pkg/rules/findings.go rename to src/pkg/lint/findings.go index c751a39069..a8ad9b5eac 100644 --- a/src/pkg/rules/findings.go +++ b/src/pkg/lint/findings.go @@ -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" diff --git a/src/pkg/rules/findings_test.go b/src/pkg/lint/findings_test.go similarity index 96% rename from src/pkg/rules/findings_test.go rename to src/pkg/lint/findings_test.go index b4cb527b4e..f3c09673c8 100644 --- a/src/pkg/rules/findings_test.go +++ b/src/pkg/lint/findings_test.go @@ -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" diff --git a/src/pkg/lint/lint.go b/src/pkg/lint/lint.go index 9b5f6667c9..9c0132f2e8 100644 --- a/src/pkg/lint/lint.go +++ b/src/pkg/lint/lint.go @@ -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) } @@ -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 } @@ -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) @@ -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() @@ -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 { @@ -101,9 +100,9 @@ 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 { @@ -111,9 +110,9 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat } } 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 { diff --git a/src/pkg/lint/lint_test.go b/src/pkg/lint/lint_test.go index 3176ab2da6..d6ad24ad82 100644 --- a/src/pkg/lint/lint_test.go +++ b/src/pkg/lint/lint_test.go @@ -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" ) @@ -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"), }, } diff --git a/src/pkg/rules/rules.go b/src/pkg/lint/rules.go similarity index 97% rename from src/pkg/rules/rules.go rename to src/pkg/lint/rules.go index 5926e00b9d..0be01cf687 100644 --- a/src/pkg/rules/rules.go +++ b/src/pkg/lint/rules.go @@ -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" diff --git a/src/pkg/rules/rules_test.go b/src/pkg/lint/rules_test.go similarity index 97% rename from src/pkg/rules/rules_test.go rename to src/pkg/lint/rules_test.go index 928469be38..803dae9096 100644 --- a/src/pkg/rules/rules_test.go +++ b/src/pkg/lint/rules_test.go @@ -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" diff --git a/src/pkg/rules/schema.go b/src/pkg/lint/schema.go similarity index 95% rename from src/pkg/rules/schema.go rename to src/pkg/lint/schema.go index 9ab1d2e0b1..ae3e991863 100644 --- a/src/pkg/rules/schema.go +++ b/src/pkg/lint/schema.go @@ -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" diff --git a/src/pkg/rules/schema_test.go b/src/pkg/lint/schema_test.go similarity index 98% rename from src/pkg/rules/schema_test.go rename to src/pkg/lint/schema_test.go index 0a3a58100f..9e59dddcd4 100644 --- a/src/pkg/rules/schema_test.go +++ b/src/pkg/lint/schema_test.go @@ -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" diff --git a/src/pkg/rules/validate.go b/src/pkg/lint/validate.go similarity index 99% rename from src/pkg/rules/validate.go rename to src/pkg/lint/validate.go index 8c4864f00f..c37658139e 100644 --- a/src/pkg/rules/validate.go +++ b/src/pkg/lint/validate.go @@ -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" diff --git a/src/pkg/rules/validate_test.go b/src/pkg/lint/validate_test.go similarity index 99% rename from src/pkg/rules/validate_test.go rename to src/pkg/lint/validate_test.go index e50bfca9b5..c3b4f8b519 100644 --- a/src/pkg/rules/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -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" diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 45a4cdd94c..6f33003097 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -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" @@ -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") diff --git a/src/pkg/packager/creator/creator_test.go b/src/pkg/packager/creator/creator_test.go index 67a92ae005..95803cc0f4 100644 --- a/src/pkg/packager/creator/creator_test.go +++ b/src/pkg/packager/creator/creator_test.go @@ -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" ) @@ -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 diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index e43a1ca973..b138ce7af2 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -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") } diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index c546fca2b2..c2e022a752 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -9,12 +9,12 @@ 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, @@ -22,7 +22,7 @@ func TestLocalOSFilter(t *testing.T) { }) } - for _, os := range rules.SupportedOS() { + for _, os := range lint.SupportedOS() { filter := ByLocalOS(os) result, err := filter.Apply(pkg) if os == "" { diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index 3df9ea1933..068808b171 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -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. @@ -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 } diff --git a/src/pkg/packager/prepare_test.go b/src/pkg/packager/prepare_test.go index 3d4bb85092..8c43e194ac 100644 --- a/src/pkg/packager/prepare_test.go +++ b/src/pkg/packager/prepare_test.go @@ -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" ) @@ -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{ diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index 169f8a28f9..5c4da94271 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -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" ) @@ -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) }