Skip to content

Commit

Permalink
do not use shellcheck and pyflakes executables at current directory
Browse files Browse the repository at this point in the history
by using execabs.LookPath instead of exec.LookPath

context: sharkdp/bat#1724
  • Loading branch information
rhysd committed Jul 14, 2021
1 parent bc8d625 commit 1c1b003
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions example_test.go
Expand Up @@ -4,12 +4,13 @@ import (
"bufio"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
"strings"
"testing"

"golang.org/x/sys/execabs"
)

func TestExamples(t *testing.T) {
Expand Down Expand Up @@ -51,15 +52,15 @@ func TestExamples(t *testing.T) {
opts := LinterOptions{}

if strings.Contains(testName, "shellcheck") {
p, err := exec.LookPath("shellcheck")
p, err := execabs.LookPath("shellcheck")
if err != nil {
t.Skip("skipped because \"shellcheck\" command does not exist in system")
}
opts.Shellcheck = p
}

if strings.Contains(testName, "pyflakes") {
p, err := exec.LookPath("pyflakes")
p, err := execabs.LookPath("pyflakes")
if err != nil {
t.Skip("skipped because \"pyflakes\" command does not exist in system")
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -11,5 +11,6 @@ require (
github.com/mattn/go-runewidth v0.0.13
github.com/robfig/cron v1.2.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
3 changes: 2 additions & 1 deletion go.sum
Expand Up @@ -22,8 +22,9 @@ github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfm
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
3 changes: 2 additions & 1 deletion rule_pyflakes.go
Expand Up @@ -8,6 +8,7 @@ import (
"sync"

"golang.org/x/sync/errgroup"
"golang.org/x/sys/execabs"
)

type shellIsPythonKind int
Expand Down Expand Up @@ -43,7 +44,7 @@ type RulePyflakes struct {
// or relative/absolute file path. When the given executable is not found in system, it returns
// an error.
func NewRulePyflakes(executable string) (*RulePyflakes, error) {
p, err := exec.LookPath(executable)
p, err := execabs.LookPath(executable)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion rule_shellcheck.go
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"golang.org/x/sync/errgroup"
"golang.org/x/sys/execabs"
)

type shellcheckError struct {
Expand All @@ -34,7 +35,7 @@ type RuleShellcheck struct {
// or relative/absolute file path. When the given executable is not found in system, it returns an
// error as 2nd return value.
func NewRuleShellcheck(executable string) (*RuleShellcheck, error) {
p, err := exec.LookPath(executable)
p, err := execabs.LookPath(executable)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1c1b003

Please sign in to comment.