-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
392 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package golangcilint | ||
|
||
import ( | ||
"github.com/golangci/golangci-lint/pkg/result" | ||
) | ||
|
||
// Issue is a wrapper of the issue model represented golangci-lint internally. | ||
type Issue struct { | ||
issue *result.Issue | ||
} | ||
|
||
func NewIssues(issues []result.Issue) []Issue { | ||
res := make([]Issue, 0, len(issues)) | ||
for _, i := range issues { | ||
res = append(res, Issue{issue: &i}) | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package golangcilint | ||
|
||
type Linter struct { | ||
Name string | ||
Enabled bool | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,68 @@ | ||
package golangcilint | ||
|
||
import "github.com/nakabonne/golintui/pkg/config" | ||
import ( | ||
"encoding/json" | ||
"os/exec" | ||
|
||
"github.com/golangci/golangci-lint/pkg/printers" | ||
|
||
"github.com/nakabonne/golintui/pkg/config" | ||
) | ||
|
||
const globOperator = "/..." | ||
|
||
type Runner struct { | ||
// Path to a golangci-lint executable. | ||
Executable string | ||
// Args given to `golangci-lint run`. | ||
// An arg can be a file name, a dir, and in addition, | ||
// `...` to analyze them recursively. | ||
Args []string | ||
Config *config.Config | ||
|
||
// dir specifies the working directory. | ||
dir string | ||
} | ||
|
||
func NewRunner(args []string) *Runner { | ||
func NewRunner(executable string, args []string) *Runner { | ||
// TODO: Automatically read config from golangci settings file. | ||
return &Runner{Args: args, Config: &config.Config{}} | ||
return &Runner{ | ||
Executable: executable, | ||
Args: args, | ||
Config: &config.Config{}, | ||
dir: ".", | ||
} | ||
} | ||
|
||
func (r *Runner) AddArgs(arg string) { | ||
r.Args = append(r.Args, arg+globOperator) | ||
} | ||
|
||
// Run executes `golangci-lint run` with its own args and configuration. | ||
func (r *Runner) Run(arg string) ([]Issue, error) { | ||
outJSON, err := r.execute("run", true, r.Args...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res printers.JSONResult | ||
if err := json.Unmarshal(outJSON, &res); err != nil { | ||
return nil, err | ||
} | ||
return NewIssues(res.Issues), nil | ||
} | ||
|
||
func (r *Runner) ListLinters() []Linter { | ||
// TODO: First up, run `golangci-lint run --out-format=json` against safety dir. | ||
// And then fetch linters from Report.Linters. | ||
return []Linter{} | ||
} | ||
|
||
func (r *Runner) execute(subCommand string, outJSON bool, args ...string) ([]byte, error) { | ||
if outJSON { | ||
args = append(args, "--out-format=json") | ||
} | ||
cmd := exec.Command(r.Executable, args...) | ||
cmd.Dir = r.dir | ||
return cmd.CombinedOutput() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters