Skip to content

Commit

Permalink
feat: skip "examples" directory check for output extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Nov 14, 2024
1 parent 06c6678 commit cf26d64
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
50 changes: 0 additions & 50 deletions checker_examples.go

This file was deleted.

51 changes: 51 additions & 0 deletions checker_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package k6lint

import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -149,3 +151,52 @@ func (mc *moduleChecker) types(_ context.Context, dir string) *checkResult {

return checkFailed("no `index.d.ts` file found")
}

//nolint:forbidigo
func (mc *moduleChecker) examples(_ context.Context, dir string) *checkResult {
if mc.exe == "" {
return checkFailed("can't build")
}

if !mc.js {
return checkPassed("skipped due to output extension")
}

dir = filepath.Join(dir, "examples")

info, err := os.Stat(dir)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return checkFailed("missing `examples` directory")
}

return checkError(err)
}

if !info.IsDir() {
return checkFailed("`examples` is not a directory")
}

hasRegular := false

err = filepath.WalkDir(dir, func(_ string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}

if entry.Type().IsRegular() {
hasRegular = true
}

return nil
})
if err != nil {
return checkError(err)
}

if hasRegular {
return checkPassed("found `examples` as examples directory")
}

return checkFailed("no examples found in the `examples` directory")
}
2 changes: 1 addition & 1 deletion checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func checkDefinitions(official bool) []checkDefinition {
{id: CheckerModule, score: 2, fn: modCheck.hasGoModule},
{id: CheckerReplace, score: 2, fn: modCheck.hasNoReplace},
{id: CheckerReadme, score: 5, fn: checkerReadme},
{id: CheckerExamples, score: 2, fn: checkerExamples},
{id: CheckerLicense, score: 5, fn: checkerLicense},
{id: CheckerGit, score: 1, fn: gitCheck.isWorkDir},
{id: CheckerVersions, score: 5, fn: gitCheck.hasVersions},
{id: CheckerBuild, score: 5, fn: modCheck.canBuild},
{id: CheckerSmoke, score: 2, fn: modCheck.smoke},
{id: CheckerExamples, score: 2, fn: modCheck.examples},
{id: CheckerTypes, score: 2, fn: modCheck.types},
}

Expand Down

0 comments on commit cf26d64

Please sign in to comment.