From 353f2900cbe47451838ed13ed298d27b61365010 Mon Sep 17 00:00:00 2001 From: Clifton Kaznocha Date: Sun, 24 Apr 2016 23:57:58 -0400 Subject: [PATCH] Handle imports better --- linter/linter.go | 27 +++++++++------------------ main.go | 11 ++--------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/linter/linter.go b/linter/linter.go index 80961d9..a7adc0c 100644 --- a/linter/linter.go +++ b/linter/linter.go @@ -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() @@ -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 diff --git a/main.go b/main.go index 7f020b1..74123c1 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ func main() { err error data []byte protoFiles []*descriptor.FileDescriptorProto - protoFileNames []string totalErrors int generatorRequest = new(protoc.CodeGeneratorRequest) ) @@ -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 }