github.com/jdhenke/godel@v0.0.0-20161213181855-abeb3861bf0d/apps/okgo/checks/definitions.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package checks 16 17 import ( 18 "sort" 19 "strings" 20 21 "github.com/palantir/amalgomate/amalgomated" 22 "github.com/palantir/pkg/pkgpath" 23 "github.com/pkg/errors" 24 25 "github.com/palantir/godel/apps/okgo/checkoutput" 26 "github.com/palantir/godel/apps/okgo/cmd/cmdlib" 27 ) 28 29 type byName []Checker 30 31 func (a byName) Len() int { return len(a) } 32 func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 33 func (a byName) Less(i, j int) bool { return a[i].Cmd().Name() < a[j].Cmd().Name() } 34 35 type allArgType string 36 37 func GetChecker(cmd amalgomated.Cmd) (Checker, error) { 38 for _, checker := range checkers() { 39 if cmd == checker.Cmd() { 40 return checker, nil 41 } 42 } 43 return nil, errors.Errorf("no checker exists for %s", cmd.Name()) 44 } 45 46 func checkers() []Checker { 47 checkers := []Checker{ 48 &checkerDefinition{ 49 cmd: cmdlib.Instance().MustNewCmd("compiles"), 50 lineParser: checkoutput.MultiLineParser(pkgpath.Absolute), 51 rawLineFilter: func(line string) bool { 52 return strings.HasPrefix(line, "err: couldn't load packages due to errors:") || strings.HasPrefix(line, "-: ") 53 }, 54 }, 55 &checkerDefinition{ 56 cmd: cmdlib.Instance().MustNewCmd("deadcode"), 57 lineParser: checkoutput.StartAfterFirstWhitespaceParser(pkgpath.Relative), 58 }, 59 &checkerDefinition{ 60 cmd: cmdlib.Instance().MustNewCmd("errcheck"), 61 lineParser: checkoutput.DefaultParser(pkgpath.Relative), 62 }, 63 &checkerDefinition{ 64 cmd: cmdlib.Instance().MustNewCmd("extimport"), 65 lineParser: checkoutput.DefaultParser(pkgpath.Absolute), 66 }, 67 &checkerDefinition{ 68 cmd: cmdlib.Instance().MustNewCmd("golint"), 69 lineParser: checkoutput.DefaultParser(pkgpath.Relative), 70 allArg: splat, 71 }, 72 &checkerDefinition{ 73 cmd: cmdlib.Instance().MustNewCmd("govet"), 74 lineParser: checkoutput.DefaultParser(pkgpath.Relative), 75 rawLineFilter: func(line string) bool { 76 return line == "exit status 1" 77 }, 78 }, 79 &checkerDefinition{ 80 cmd: cmdlib.Instance().MustNewCmd("ineffassign"), 81 lineParser: checkoutput.DefaultParser(pkgpath.Absolute), 82 allArg: rootDir, 83 globalCheck: true, 84 }, 85 &checkerDefinition{ 86 cmd: cmdlib.Instance().MustNewCmd("novendor"), 87 lineParser: checkoutput.RawParser(), 88 }, 89 &checkerDefinition{ 90 cmd: cmdlib.Instance().MustNewCmd("outparamcheck"), 91 lineParser: checkoutput.DefaultParser(pkgpath.Relative), 92 rawLineFilter: func(line string) bool { 93 return strings.HasSuffix(line, `the parameters listed above require the use of '&', for example f(&x) instead of f(x)`) 94 }, 95 }, 96 &checkerDefinition{ 97 cmd: cmdlib.Instance().MustNewCmd("unconvert"), 98 lineParser: checkoutput.DefaultParser(pkgpath.Absolute), 99 }, 100 &checkerDefinition{ 101 cmd: cmdlib.Instance().MustNewCmd("varcheck"), 102 lineParser: checkoutput.StartAfterFirstWhitespaceParser(pkgpath.Absolute), 103 }, 104 } 105 sort.Sort(byName(checkers)) 106 return checkers 107 }