Skip to content

Commit

Permalink
feat: Parse a file every time a single linter rule runs
Browse files Browse the repository at this point in the history
  • Loading branch information
yoheimuta committed Jan 16, 2022
1 parent 1656b45 commit 375f265
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
14 changes: 14 additions & 0 deletions _example/proto/issue_111/multiple_fixers_applicable.proto
Original file line number Diff line number Diff line change
@@ -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"];
}
19 changes: 11 additions & 8 deletions internal/cmd/subcmds/lint/cmdLint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
9 changes: 7 additions & 2 deletions internal/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 375f265

Please sign in to comment.