diff --git a/_example/proto/issue_111/multiple_fixers_applicable.proto b/_example/proto/issue_111/multiple_fixers_applicable.proto new file mode 100644 index 00000000..215c881c --- /dev/null +++ b/_example/proto/issue_111/multiple_fixers_applicable.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +enum enumAllowingAlias { + UNKNOWN = 0; + option allow_alias = true; + STARTED = 1; + RUNNING = 2 [(custom_option) = "hello world"]; +} + +enum enumAllowingAlias2 { + UNKNOWN = 0; + option allow_alias = true; + STARTED = 1; + RUNNING = 2 [(custom_option) = "hello world"]; +} diff --git a/internal/cmd/subcmds/lint/cmdLint.go b/internal/cmd/subcmds/lint/cmdLint.go index adedfd30..d3fc0107 100644 --- a/internal/cmd/subcmds/lint/cmdLint.go +++ b/internal/cmd/subcmds/lint/cmdLint.go @@ -6,6 +6,8 @@ import ( "log" "os" + "github.com/yoheimuta/go-protoparser/v4/parser" + "github.com/yoheimuta/protolint/internal/linter/config" "github.com/yoheimuta/protolint/internal/linter" @@ -128,13 +130,14 @@ func (c *CmdLint) runOneFile( return []report.Failure{}, nil } - proto, err := f.Parse(c.config.verbose) - if err != nil { - if c.config.verbose { - return nil, ParseError{Message: err.Error()} + return c.l.Run(func() (*parser.Proto, error) { + proto, err := f.Parse(c.config.verbose) + if err != nil { + if c.config.verbose { + return nil, ParseError{Message: err.Error()} + } + return nil, ParseError{Message: fmt.Sprintf("%s. Use -v for more details", err)} } - return nil, ParseError{Message: fmt.Sprintf("%s. Use -v for more details", err)} - } - - return c.l.Run(proto, rs) + return proto, nil + }, rs) } diff --git a/internal/linter/linter.go b/internal/linter/linter.go index c9efb7e5..42e7fd40 100644 --- a/internal/linter/linter.go +++ b/internal/linter/linter.go @@ -17,12 +17,17 @@ func NewLinter() *Linter { // Run lints the protocol buffer. func (l *Linter) Run( - proto *parser.Proto, + genProto func() (*parser.Proto, error), hasApplies []rule.HasApply, ) ([]report.Failure, error) { var fs []report.Failure for _, hasApply := range hasApplies { - f, err := hasApply.Apply(proto) + p, err := genProto() + if err != nil { + return nil, err + } + + f, err := hasApply.Apply(p) if err != nil { return nil, err }