Skip to content

Commit

Permalink
Merge pull request #746 from Elizafox/pkglint
Browse files Browse the repository at this point in the history
Extricate config stuff from linter.
  • Loading branch information
Elizafox authored Oct 10, 2023
2 parents 2c1195f + 4156090 commit 3342136
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 1 addition & 3 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,6 @@ func (b *Build) BuildPackage(ctx context.Context) error {
// add the main package to the linter queue
lintTarget := linterTarget{
pkgName: b.Configuration.Package.Name,
checks: b.Configuration.Package.Checks,
}
linterQueue = append(linterQueue, lintTarget)
}
Expand Down Expand Up @@ -1121,7 +1120,6 @@ func (b *Build) BuildPackage(ctx context.Context) error {
// add the main package to the linter queue
lintTarget := linterTarget{
pkgName: sp.Name,
checks: sp.Checks,
}
linterQueue = append(linterQueue, lintTarget)
}
Expand All @@ -1139,7 +1137,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {

path := filepath.Join(b.WorkspaceDir, "melange-out", lt.pkgName)
fsys := os.DirFS(path)
lctx := linter.NewLinterContext(lt.pkgName, fsys, &b.Configuration, &lt.checks)
lctx := linter.NewLinterContext(lt.pkgName, fsys)
linters := lt.checks.GetLinters()

var innerErr error
Expand Down
8 changes: 2 additions & 6 deletions pkg/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ import (
"os"
"path/filepath"
"regexp"

"chainguard.dev/melange/pkg/config"
)

type LinterContext struct {
pkgname string
fsys fs.FS
cfg *config.Configuration
chk *config.Checks
}

func NewLinterContext(name string, fsys fs.FS, cfg *config.Configuration, chk *config.Checks) LinterContext {
return LinterContext{name, fsys, cfg, chk}
func NewLinterContext(name string, fsys fs.FS) LinterContext {
return LinterContext{name, fsys}
}

type linterFunc func(lctx LinterContext, path string, d fs.DirEntry) error
Expand Down
20 changes: 10 additions & 10 deletions pkg/linter/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_emptyLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"empty"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -78,7 +78,7 @@ func Test_usrLocalLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"usrlocal"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -112,7 +112,7 @@ func Test_varEmptyLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"varempty"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -146,7 +146,7 @@ func Test_devLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"dev"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -180,7 +180,7 @@ func Test_optLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"opt"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -214,7 +214,7 @@ func Test_srvLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"srv"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -260,7 +260,7 @@ func Test_tempDirLinter(t *testing.T) {
assert.NoError(t, err)
_, err = os.Create(filename)
assert.NoError(t, err)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -319,7 +319,7 @@ func Test_setUidGidLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"setuidgid"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -352,7 +352,7 @@ func Test_worldWriteLinter(t *testing.T) {
linters := cfg.Package.Checks.GetLinters()
assert.Equal(t, linters, []string{"worldwrite"})
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down Expand Up @@ -425,7 +425,7 @@ func Test_disableDefaultLinter(t *testing.T) {

linters := cfg.Package.Checks.GetLinters()
fsys := os.DirFS(dir)
lctx := NewLinterContext(cfg.Package.Name, fsys, &cfg, &cfg.Package.Checks)
lctx := NewLinterContext(cfg.Package.Name, fsys)
called := false
assert.NoError(t, lctx.LintPackageFs(fsys, func(err error) {
called = true
Expand Down

0 comments on commit 3342136

Please sign in to comment.