Skip to content

Commit

Permalink
Merge pull request #4 from ckaznocha/feature/Imports
Browse files Browse the repository at this point in the history
Handle imports better
  • Loading branch information
ckaznocha committed Apr 25, 2016
2 parents 024053c + 353f290 commit 39b86cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
27 changes: 9 additions & 18 deletions linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ var linterErrors = map[int]string{
// LintProtoFile takes a file name, proto file description, and a file.
// It checks the file for errors and writes them to the output file
func LintProtoFile(
fileName string,
protoFile *descriptor.FileDescriptorProto,
outFile io.WriteCloser,
) (int, error) {

defer outFile.Close()

var (
errors = protoBufErrors{}
protoSource = protoFile.GetSourceCodeInfo()
Expand All @@ -63,22 +59,17 @@ func LintProtoFile(
for i, v := range protoFile.GetService() {
errors.lintProtoService(int32(i), v)
}

for _, v := range errors {
line, col := v.getSourceLineNumber(protoSource)
_, err := outFile.Write([]byte(
fmt.Sprintf(
"%s:%d:%d: '%s' - %s\n",
fileName,
line,
col,
v.errorString,
linterErrors[v.errorCode],
),
))
if err != nil {
return len(errors), err
}
fmt.Fprintf(
outFile,
"%s:%d:%d: '%s' - %s\n",
*protoFile.Name,
line,
col,
v.errorString,
linterErrors[v.errorCode],
)
}

return len(errors), nil
Expand Down
11 changes: 2 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func main() {
err error
data []byte
protoFiles []*descriptor.FileDescriptorProto
protoFileNames []string
totalErrors int
generatorRequest = new(protoc.CodeGeneratorRequest)
)
Expand All @@ -34,14 +33,8 @@ func main() {
panicOnError(err)

protoFiles = generatorRequest.GetProtoFile()
protoFileNames = generatorRequest.GetFileToGenerate()

for i := 0; i < len(protoFileNames); i++ {
numErrors, err := linter.LintProtoFile(
protoFileNames[i],
protoFiles[i],
os.Stderr,
)
for _, file := range protoFiles {
numErrors, err := linter.LintProtoFile(file, os.Stderr)
panicOnError(err)
totalErrors += numErrors
}
Expand Down

0 comments on commit 39b86cb

Please sign in to comment.