Skip to content

Commit

Permalink
Add cli lint option to treat warnings as errors (#4373)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Kaussow <[email protected]>
  • Loading branch information
6543 and xoxys authored Nov 13, 2024
1 parent e6eb581 commit f4d7e9f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .woodpecker/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ steps:
- go run go.woodpecker-ci.org/woodpecker/v2/cmd/cli lint
environment:
WOODPECKER_DISABLE_UPDATE_CHECK: true
WOODPECKER_LINT_STRICT: true
WOODPECKER_PLUGINS_PRIVILEGED: 'docker.io/woodpeckerci/plugin-docker-buildx:5.0.0'
when:
- event: pull_request
Expand Down
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax
Workflow: conf,
}})
if err != nil {
str, err := lint.FormatLintError(file, err)
str, err := lint.FormatLintError(file, err, false)
fmt.Print(str)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ var Command = &cli.Command{
Usage: "Plugins which are trusted to handle the netrc info in clone steps",
Value: constant.TrustedClonePlugins,
},
&cli.BoolFlag{
Sources: cli.EnvVars("WOODPECKER_LINT_STRICT"),
Name: "strict",
Usage: "treat warnings as errors",
},
},
}

Expand Down Expand Up @@ -119,7 +124,7 @@ func lintFile(_ context.Context, c *cli.Command, file string) error {
linter.WithTrustedClonePlugins(c.StringSlice("plugins-trusted-clone")),
).Lint([]*linter.WorkflowConfig{config})
if err != nil {
str, err := FormatLintError(config.File, err)
str, err := FormatLintError(config.File, err, c.Bool("strict"))

if str != "" {
fmt.Print(str)
Expand Down
4 changes: 2 additions & 2 deletions cli/lint/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors"
)

func FormatLintError(file string, err error) (string, error) {
func FormatLintError(file string, err error, strict bool) (string, error) {
if err == nil {
return "", nil
}
Expand All @@ -24,7 +24,7 @@ func FormatLintError(file string, err error) (string, error) {
for _, err := range linterErrors {
line := " "

if err.IsWarning {
if !strict && err.IsWarning {
line = fmt.Sprintf("%s ⚠️ ", line)
amountWarnings++
} else {
Expand Down

0 comments on commit f4d7e9f

Please sign in to comment.