Skip to content

Commit

Permalink
use cwd when given path is empty on LintRepository and `GenerateDef…
Browse files Browse the repository at this point in the history
…aultConfig`
  • Loading branch information
rhysd committed Nov 1, 2024
1 parent 07cafa0 commit a93bb53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (cmd *Command) runLinter(args []string, opts *LinterOptions, initConfig boo
}

if initConfig {
return nil, l.GenerateDefaultConfig(".")
return nil, l.GenerateDefaultConfig("")
}

if len(args) == 0 {
return l.LintRepository(".")
return l.LintRepository("")
}

if len(args) == 1 && args[0] == "-" {
Expand Down
18 changes: 14 additions & 4 deletions linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ func (l *Linter) debugWriter() io.Writer {
}

// GenerateDefaultConfig generates default config file at ".github/actionlint.yaml" in the project
// which the given directory path belongs to.
// which the given directory path belongs to. When the directory path is empty, the current directory
// will be used instead.
func (l *Linter) GenerateDefaultConfig(dir string) error {
if dir == "" {
dir = l.cwd
}

l.log("Generating default actionlint.yaml in repository:", dir)

proj, err := l.projects.At(dir)
Expand Down Expand Up @@ -251,10 +256,15 @@ func (l *Linter) GenerateDefaultConfig(dir string) error {
return nil
}

// LintRepository lints YAML workflow files and outputs the errors to given writer. It finds the nearest
// `.github/workflows` directory based on `dir` and applies lint rules to all YAML workflow files
// under the directory.
// LintRepository lints YAML workflow files and outputs the errors to given writer. It finds the
// nearest `.github/workflows` directory based on `dir` and applies lint rules to all YAML workflow
// files under the directory. When the directory path is empty, the current working directory will
// be used instead.
func (l *Linter) LintRepository(dir string) ([]*Error, error) {
if dir == "" {
dir = l.cwd
}

l.log("Linting all workflow files in repository:", dir)

p, err := l.projects.At(dir)
Expand Down

0 comments on commit a93bb53

Please sign in to comment.