Skip to content

Commit 799bea3

Browse files
committed
fall back to . when os.Getwd returns an error
1 parent 0c0a521 commit 799bea3

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"gopkg.in/yaml.v3"
1313
)
1414

15-
// IgnorePatterns is a list of regular expressions. They are used for ignoring errors by matching
16-
// to the error messages.
15+
// IgnorePatterns is a list of regular expressions. These patterns are used for filtering errors by
16+
// matching the error messages.
1717
type IgnorePatterns []*regexp.Regexp
1818

1919
// Match returns whether the given error should be ignored due to the "ignore" configuration.
@@ -69,9 +69,9 @@ type Config struct {
6969
Paths map[string]PathConfig `yaml:"paths"`
7070
}
7171

72-
// PathConfigsFor returns a list of all PathConfig values matching to the given file path. The path must
72+
// PathConfigs returns a list of all PathConfig values matching to the given file path. The path must
7373
// be relative to the root of the project.
74-
func (cfg *Config) PathConfigsFor(path string) []PathConfig {
74+
func (cfg *Config) PathConfigs(path string) []PathConfig {
7575
path = filepath.ToSlash(path)
7676

7777
var ret []PathConfig

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ paths:
201201

202202
for _, tc := range tests {
203203
var ignored bool
204-
for _, c := range cfg.PathConfigsFor(tc.path) {
204+
for _, c := range cfg.PathConfigs(tc.path) {
205205
if c.Ignore.Match(&Error{Message: tc.msg}) {
206206
ignored = true
207207
break

linter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ func NewLinter(out io.Writer, opts *LinterOptions) (*Linter, error) {
166166
formatter = f
167167
}
168168

169-
cwd := opts.WorkingDir
170-
if cwd == "" {
171-
if d, err := os.Getwd(); err == nil {
172-
cwd = d
173-
}
169+
cwd := "."
170+
if opts.WorkingDir != "" {
171+
cwd = opts.WorkingDir
172+
} else if d, err := os.Getwd(); err == nil {
173+
cwd = d
174174
}
175175

176176
stdin := "<stdin>"
@@ -628,7 +628,7 @@ func (l *Linter) check(
628628
}
629629
}
630630

631-
all = l.filterErrors(all, cfg.PathConfigsFor(path))
631+
all = l.filterErrors(all, cfg.PathConfigs(path))
632632

633633
for _, err := range all {
634634
err.Filepath = path // Populate filename in the error

0 commit comments

Comments
 (0)