Skip to content

Commit

Permalink
Update sort_imports (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaznocha authored Feb 7, 2018
1 parent 3f5880c commit 68a0585
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ the executable is available in your PATH.
```
protoc --lint_out=. *.proto
```
### Optional Checks
Optional checks are enabled but passing a comma separated list to the protoc
"parameter". Example:
```
protoc --lint_out=sort_imports:. *.proto
```

Available optional checks:
* `sort_imports` - checks that imports are sorted in descending alphabetical
order.

## TODO
* Write more tests
Expand Down
18 changes: 8 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ func main() {
}
)

data, err := ioutil.ReadAll(os.Stdin)
panicOnError(err)
panicOnError(proto.Unmarshal(data, &generatorRequest))

for _, p := range strings.Split(generatorRequest.GetParameter(), ",") {
switch p {
switch strings.TrimSpace(p) {
case "":
continue
case SortImports:
parameters.SortImports = true
default:
fmt.Fprintf(os.Stderr, "Unmatched parameter: %s", p)
totalErrors++
os.Exit(1)
}
}
if totalErrors != 0 {
os.Exit(1)
}

data, err := ioutil.ReadAll(os.Stdin)
panicOnError(err)

panicOnError(proto.Unmarshal(data, &generatorRequest))

for _, file := range generatorRequest.GetProtoFile() {
numErrors, err := linter.LintProtoFile(linter.Config{
Expand Down

0 comments on commit 68a0585

Please sign in to comment.