Skip to content

Commit

Permalink
avoid redundant name
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Jul 25, 2020
1 parent 347d793 commit 997e2e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/reviewdog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func readConf(conf string) ([]byte, error) {
}

func newParserFromOpt(opt *option) (parser.Parser, error) {
p, err := parser.NewParser(&parser.ParserOpt{FormatName: opt.f, Errorformat: opt.efms})
p, err := parser.New(&parser.Option{FormatName: opt.f, Errorformat: opt.efms})
if err != nil {
return nil, fmt.Errorf("fail to create parser. use either -f or -efm: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type Parser interface {
Parse(r io.Reader) ([]*rdf.Diagnostic, error)
}

// ParserOpt represents option to create Parser. Either FormatName or
// Option represents option to create Parser. Either FormatName or
// Errorformat should be specified.
type ParserOpt struct {
type Option struct {
FormatName string
Errorformat []string
}

// NewParser returns Parser based on ParserOpt.
func NewParser(opt *ParserOpt) (Parser, error) {
// New returns Parser based on Option.
func New(opt *Option) (Parser, error) {
name := opt.FormatName

if name != "" && len(opt.Errorformat) > 0 {
Expand Down
18 changes: 9 additions & 9 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@ import (

func TestNewParser(t *testing.T) {
tests := []struct {
in *ParserOpt
in *Option
typ Parser
wantErr bool
}{
{
in: &ParserOpt{
in: &Option{
FormatName: "checkstyle",
},
typ: &CheckStyleParser{},
},
{
in: &ParserOpt{
in: &Option{
FormatName: "rdjsonl",
},
typ: &RDJSONLParser{},
},
{
in: &ParserOpt{
in: &Option{
FormatName: "golint",
},
typ: &ErrorformatParser{},
},
{
in: &ParserOpt{
in: &Option{
Errorformat: []string{`%f:%l:%c:%m`},
},
typ: &ErrorformatParser{},
},
{ // empty
in: &ParserOpt{},
in: &Option{},
wantErr: true,
},
{ // both
in: &ParserOpt{
in: &Option{
FormatName: "checkstyle",
Errorformat: []string{`%f:%l:%c:%m`},
},
wantErr: true,
},
{ // unsupported
in: &ParserOpt{
in: &Option{
FormatName: "unsupported format",
},
wantErr: true,
},
}
for _, tt := range tests {
p, err := NewParser(tt.in)
p, err := New(tt.in)
if tt.wantErr && err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions project/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func RunAndParse(ctx context.Context, conf *Config, runners map[string]bool, def
if fname == "" && len(runner.Errorformat) == 0 {
fname = runnerName
}
opt := &parser.ParserOpt{FormatName: fname, Errorformat: runner.Errorformat}
p, err := parser.NewParser(opt)
opt := &parser.Option{FormatName: fname, Errorformat: runner.Errorformat}
p, err := parser.New(opt)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 997e2e1

Please sign in to comment.