diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index c49d2824..d4da547f 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -7,7 +7,7 @@ jobs: go: ["1.14", "1.13", "1.12"] steps: - uses: actions/checkout@v2.3.4 - - uses: actions/setup-go@v2-beta + - uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} - run: go build -x -work ./cmds/... @@ -19,14 +19,29 @@ jobs: with: node-version: "10.x" - run: npm install + golangci: + name: lint + strategy: + matrix: + go: ["1.14"] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2.3.4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2.3.0 + with: + # the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.35.2 go-test: - runs-on: ubuntu-latest strategy: matrix: go: ["1.14", "1.13", "1.12"] + os: [windows-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2.3.4 - - uses: actions/setup-go@v2-beta + - uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} - run: go test -race ./... diff --git a/Makefile b/Makefile index fa3725a7..535ec866 100644 --- a/Makefile +++ b/Makefile @@ -35,5 +35,12 @@ test: go test github.com/hound-search/hound/... npm test +lint: + export GO111MODULE=on + go get github.com/golangci/golangci-lint/cmd/golangci-lint + export GOPATH=/tmp/gopath + export PATH=$GOPATH/bin:$PATH + golangci-lint run ./... + clean: rm -rf .build node_modules diff --git a/ansi/ansi_test.go b/ansi/ansi_test.go index efe6ae7a..10456c13 100644 --- a/ansi/ansi_test.go +++ b/ansi/ansi_test.go @@ -11,7 +11,7 @@ var ( printTests = false ) -func makeReal(s string) string { +func makeReal(s string) string { //nolint return strings.Replace(s, "~", "\x1b", -1) } diff --git a/ansi/tty_linux.go b/ansi/tty_linux.go index d6fad23e..321978bf 100644 --- a/ansi/tty_linux.go +++ b/ansi/tty_linux.go @@ -1,4 +1,4 @@ package ansi const ioctlReadTermios = 0x5401 // syscall.TCGETS -const ioctlWriteTermios = 0x5402 // syscall.TCSETS +const ioctlWriteTermios = 0x5402 //nolint syscall.TCSETS diff --git a/api/api.go b/api/api.go index b6340487..4f686beb 100644 --- a/api/api.go +++ b/api/api.go @@ -89,7 +89,7 @@ func searchAll( *filesOpened += r.res.FilesOpened } - *duration = int(time.Now().Sub(startedAt).Seconds() * 1000) + *duration = int(time.Now().Sub(startedAt).Seconds() * 1000) //nolint return res, nil } diff --git a/client/coalesce.go b/client/coalesce.go index 69d085ac..0c55794c 100644 --- a/client/coalesce.go +++ b/client/coalesce.go @@ -30,13 +30,13 @@ func matchToBlock(m *index.Match) *Block { v[b] = true - for _, line := range m.Before { + for _, line := range m.Before { //nolint l = append(l, line) } l = append(l, m.Line) - for _, line := range m.After { + for _, line := range m.After { //nolint l = append(l, line) } diff --git a/cmds/houndd/main.go b/cmds/houndd/main.go index 43d4a304..9d2d79e5 100644 --- a/cmds/houndd/main.go +++ b/cmds/houndd/main.go @@ -47,7 +47,7 @@ func makeSearchers(cfg *config.Config) (map[string]*searcher.Searcher, bool, err if len(errs) > 0 { // NOTE: This mutates the original config so the repos // are not even seen by other code paths. - for name, _ := range errs { + for name, _ := range errs { //nolint delete(cfg.Repos, name) } @@ -79,7 +79,7 @@ func registerShutdownSignal() <-chan os.Signal { return shutdownCh } -func makeTemplateData(cfg *config.Config) (interface{}, error) { +func makeTemplateData(cfg *config.Config) (interface{}, error) { //nolint var data struct { ReposAsJson string } @@ -98,7 +98,7 @@ func makeTemplateData(cfg *config.Config) (interface{}, error) { return &data, nil } -func runHttp( +func runHttp( //nolint addr string, dev bool, cfg *config.Config, diff --git a/codesearch/index/merge.go b/codesearch/index/merge.go index 708a531b..01a0c47a 100644 --- a/codesearch/index/merge.go +++ b/codesearch/index/merge.go @@ -41,10 +41,10 @@ type idrange struct { lo, hi, new uint32 } -type postIndex struct { - tri uint32 - count uint32 - offset uint32 +type postIndex struct { //nolint + tri uint32 //nolint + count uint32 //nolint + offset uint32 //nolint } // Merge creates a new index in the file dst that corresponds to merging @@ -70,7 +70,7 @@ func Merge(dst, src1, src2 string) { for i1 < uint32(ix1.numName) && ix1.Name(i1) < limit { i1++ } - hi := i1 + hi := i1 //nolint // Record range before the shadow. if old < lo { @@ -304,7 +304,7 @@ func (r *postMapReader) nextId() bool { type postDataWriter struct { out *bufWriter postIndexFile *bufWriter - buf [10]byte + buf [10]byte //nolint base uint32 count, offset uint32 last uint32 diff --git a/codesearch/index/read.go b/codesearch/index/read.go index 3ee05194..5234266e 100644 --- a/codesearch/index/read.go +++ b/codesearch/index/read.go @@ -133,7 +133,7 @@ func (ix *Index) Close() error { } // uvarint returns the varint value at the given offset in the index data. -func (ix *Index) uvarint(off uint32) uint32 { +func (ix *Index) uvarint(off uint32) uint32 { //nolint v, n := binary.Uvarint(ix.slice(off, -1)) if n <= 0 { corrupt(ix.data.f) @@ -185,7 +185,7 @@ func (ix *Index) listAt(off uint32) (trigram, count, offset uint32) { return } -func (ix *Index) dumpPosting() { +func (ix *Index) dumpPosting() { //nolint d := ix.slice(ix.postIndex, postEntrySize*ix.numPost) for i := 0; i < ix.numPost; i++ { j := i * postEntrySize diff --git a/codesearch/index/regexp.go b/codesearch/index/regexp.go index 4f336fea..82cf1989 100644 --- a/codesearch/index/regexp.go +++ b/codesearch/index/regexp.go @@ -226,7 +226,7 @@ func trigramsImply(t []string, q *Query) bool { // maybeRewrite rewrites q to use op if it is possible to do so // without changing the meaning. It also simplifies if the node // is an empty OR or AND. -func (q *Query) maybeRewrite(op QueryOp) { +func (q *Query) maybeRewrite(op QueryOp) { //nolint if q.Op != QAnd && q.Op != QOr { return } @@ -736,7 +736,7 @@ func (s stringSet) have() bool { } // contains reports whether s contains str. -func (s stringSet) contains(str string) bool { +func (s stringSet) contains(str string) bool { //nolint for _, ss := range s { if ss == str { return true @@ -814,7 +814,7 @@ func (s stringSet) minLen() int { } // maxLen returns the length of the longest string in s. -func (s stringSet) maxLen() int { +func (s stringSet) maxLen() int { //nolint if len(s) == 0 { return 0 } @@ -847,7 +847,7 @@ func (s stringSet) cross(t stringSet, isSuffix bool) stringSet { } // clear empties the set but preserves the storage. -func (s *stringSet) clear() { +func (s *stringSet) clear() { //nolint *s = (*s)[:0] } diff --git a/codesearch/index/write.go b/codesearch/index/write.go index c8eddb32..f056e35e 100644 --- a/codesearch/index/write.go +++ b/codesearch/index/write.go @@ -43,7 +43,7 @@ type IndexWriter struct { paths []string nameData *bufWriter // temp file holding list of names - nameLen uint32 // number of bytes written to nameData + nameLen uint32 //nolint number of bytes written to nameData nameIndex *bufWriter // temp file holding name index numName int // number of names written totalBytes int64 @@ -123,7 +123,7 @@ func (ix *IndexWriter) AddFile(name string) { func (ix *IndexWriter) Add(name string, f io.Reader) string { ix.trigram.Reset() var ( - c = byte(0) + c = byte(0) //nolint i = 0 buf = ix.inbuf[:0] tv = uint32(0) @@ -131,7 +131,7 @@ func (ix *IndexWriter) Add(name string, f io.Reader) string { linelen = 0 numLines = 0 longLines = 0 - skipReason = "" + skipReason = "" //nolint ) for { @@ -246,7 +246,7 @@ func (ix *IndexWriter) Flush() { os.Remove(ix.nameData.name) for _, d := range ix.postData { - unmmap(d) + unmmap(d) //nolint } for _, f := range ix.postFile { f.Close() @@ -310,7 +310,7 @@ func (ix *IndexWriter) flushPost() { } ix.post = ix.post[:0] - w.Seek(0, 0) + w.Seek(0, 0) //nolint ix.postFile = append(ix.postFile, w) } @@ -368,7 +368,7 @@ type postChunk struct { m []postEntry // remaining entries after e } -const postBuf = 4096 +const postBuf = 4096 //nolint // A postHeap is a heap (priority queue) of postChunks. type postHeap struct { @@ -388,7 +388,7 @@ func (h *postHeap) addMem(x []postEntry) { // step reads the next entry from ch and saves it in ch.e. // It returns false if ch is over. -func (h *postHeap) step(ch *postChunk) bool { +func (h *postHeap) step(ch *postChunk) bool { //nolint old := ch.e m := ch.m if len(m) == 0 { @@ -414,7 +414,7 @@ func (h *postHeap) add(ch *postChunk) { } // empty reports whether the postHeap is empty. -func (h *postHeap) empty() bool { +func (h *postHeap) empty() bool { //nolint return len(h.ch) == 0 } @@ -492,7 +492,7 @@ type bufWriter struct { name string file *os.File buf []byte - tmp [8]byte + tmp [8]byte //nolint } // bufCreate creates a new file with the given name and returns a @@ -578,7 +578,7 @@ func (b *bufWriter) flush() { func (b *bufWriter) finish() *os.File { b.flush() f := b.file - f.Seek(0, 0) + f.Seek(0, 0) //nolint return f } diff --git a/codesearch/regexp/copy.go b/codesearch/regexp/copy.go index 9be19874..c46e87a4 100644 --- a/codesearch/regexp/copy.go +++ b/codesearch/regexp/copy.go @@ -18,7 +18,7 @@ import ( // cleanClass sorts the ranges (pairs of elements of r), // merges them, and eliminates duplicates. -func cleanClass(rp *[]rune) []rune { +func cleanClass(rp *[]rune) []rune { //nolint // Sort by lo increasing, hi decreasing to break ties. sort.Sort(ranges{rp}) @@ -119,7 +119,7 @@ func appendFoldedRange(r []rune, lo, hi rune) []rune { // The choice of receiver type definition is strange // but avoids an allocation since we already have // a *[]rune. -type ranges struct { +type ranges struct { //nolint p *[]rune } @@ -141,25 +141,25 @@ func (ra ranges) Swap(i, j int) { p[i], p[i+1], p[j], p[j+1] = p[j], p[j+1], p[i], p[i+1] } -func progString(p *syntax.Prog) string { +func progString(p *syntax.Prog) string { //nolint var b bytes.Buffer dumpProg(&b, p) return b.String() } -func instString(i *syntax.Inst) string { +func instString(i *syntax.Inst) string { //nolint var b bytes.Buffer dumpInst(&b, i) return b.String() } -func bw(b *bytes.Buffer, args ...string) { +func bw(b *bytes.Buffer, args ...string) { //nolint for _, s := range args { b.WriteString(s) } } -func dumpProg(b *bytes.Buffer, p *syntax.Prog) { +func dumpProg(b *bytes.Buffer, p *syntax.Prog) { //nolint for j := range p.Inst { i := &p.Inst[j] pc := strconv.Itoa(j) @@ -175,11 +175,11 @@ func dumpProg(b *bytes.Buffer, p *syntax.Prog) { } } -func u32(i uint32) string { +func u32(i uint32) string { //nolint return strconv.FormatUint(uint64(i), 10) } -func dumpInst(b *bytes.Buffer, i *syntax.Inst) { +func dumpInst(b *bytes.Buffer, i *syntax.Inst) { //nolint switch i.Op { case syntax.InstAlt: bw(b, "alt -> ", u32(i.Out), ", ", u32(i.Arg)) diff --git a/codesearch/regexp/match.go b/codesearch/regexp/match.go index f1ff2361..480f9109 100644 --- a/codesearch/regexp/match.go +++ b/codesearch/regexp/match.go @@ -38,9 +38,9 @@ type flags uint32 const ( flagBOL flags = 1 << iota // beginning of line - flagEOL // end of line + flagEOL //nolint end of line flagBOT // beginning of text - flagEOT // end of text + flagEOT //nolint end of text flagWord // last byte was word byte ) diff --git a/codesearch/regexp/utf.go b/codesearch/regexp/utf.go index d587eaaf..858c83c1 100644 --- a/codesearch/regexp/utf.go +++ b/codesearch/regexp/utf.go @@ -216,7 +216,7 @@ func (b *runeBuilder) addRange(lo, hi rune, fold bool) { } // TODO: Pick off 80-10FFFF for special handling? - if lo == 0x80 && hi == 0x10FFFF { + if lo == 0x80 && hi == 0x10FFFF { //nolint } // Split range into same-length sized ranges. diff --git a/config/config_test.go b/config/config_test.go index 2f867abb..fd680d6f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -40,14 +40,14 @@ func TestExampleConfigsAreValid(t *testing.T) { repo := cfg.Repos["SomeGitRepo"] vcsConfigBytes := repo.VcsConfig() var vcsConfigVals map[string]interface{} - json.Unmarshal(vcsConfigBytes, &vcsConfigVals) + json.Unmarshal(vcsConfigBytes, &vcsConfigVals) //nolint if detectRef, ok := vcsConfigVals["detect-ref"]; !ok || !detectRef.(bool) { t.Error("global detectRef vcs config setting not set for repo") } repo = cfg.Repos["GitRepoWithDetectRefDisabled"] vcsConfigBytes = repo.VcsConfig() - json.Unmarshal(vcsConfigBytes, &vcsConfigVals) + json.Unmarshal(vcsConfigBytes, &vcsConfigVals) //nolint if detectRef, ok := vcsConfigVals["detect-ref"]; !ok || detectRef.(bool) { t.Error("global detectRef vcs config setting not overriden by repo-level setting") } diff --git a/index/grep.go b/index/grep.go index dcdf2e76..d8af1640 100644 --- a/index/grep.go +++ b/index/grep.go @@ -28,7 +28,7 @@ func countLines(b []byte) int { return n } -func (g *grepper) grepFile(filename string, re *regexp.Regexp, +func (g *grepper) grepFile(filename string, re *regexp.Regexp, //nolint fn func(line []byte, lineno int) (bool, error)) error { r, err := os.Open(filename) if err != nil { @@ -189,7 +189,7 @@ func (g *grepper) grep2( // This nonsense is adapted from https://code.google.com/p/codesearch/source/browse/regexp/match.go#399 // and I assume it is a mess to make it faster, but I would like to try a much simpler cleaner version. -func (g *grepper) grep(r io.Reader, re *regexp.Regexp, fn func(line []byte, lineno int) (bool, error)) error { +func (g *grepper) grep(r io.Reader, re *regexp.Regexp, fn func(line []byte, lineno int) (bool, error)) error { //nolint if g.buf == nil { g.buf = make([]byte, 1<<20) } @@ -248,5 +248,5 @@ func (g *grepper) grep(r io.Reader, re *regexp.Regexp, fn func(line []byte, line } } - return nil + return nil //nolint } diff --git a/index/index.go b/index/index.go index 626ec481..d956f3eb 100644 --- a/index/index.go +++ b/index/index.go @@ -236,7 +236,7 @@ func (n *Index) Search(pat string, opt *SearchOptions) (*SearchResponse, error) Matches: results, FilesWithMatch: filesFound, FilesOpened: filesOpened, - Duration: time.Now().Sub(startedAt), + Duration: time.Now().Sub(startedAt), //nolint Revision: n.Ref.Rev, }, nil } @@ -364,7 +364,7 @@ func indexAllFiles(opt *IndexOptions, dst, src string) error { } defer fileHandle.Close() - if err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { //nolint name := info.Name() rel, err := filepath.Rel(src, path) if err != nil { diff --git a/index/index_test.go b/index/index_test.go index 716e77da..e2920ee2 100644 --- a/index/index_test.go +++ b/index/index_test.go @@ -35,7 +35,7 @@ func TestSearch(t *testing.T) { if err != nil { t.Fatal(err) } - defer ref.Remove() + defer ref.Remove() //nolint // Make sure the metadata in the ref is good. if ref.Rev != rev { @@ -79,7 +79,7 @@ func TestRead(t *testing.T) { if err != nil { t.Fatal(err) } - defer ref.Remove() + defer ref.Remove() //nolint r, err := Read(ref.Dir()) if err != nil { diff --git a/searcher/searcher.go b/searcher/searcher.go index 67727b9d..e2f9b350 100644 --- a/searcher/searcher.go +++ b/searcher/searcher.go @@ -264,7 +264,7 @@ func reportOnMemory() { // Utility function for producing a hex encoded sha1 hash for a string. func hashFor(name string) string { h := sha1.New() - h.Write([]byte(name)) + h.Write([]byte(name)) //nolint return hex.EncodeToString(h.Sum(nil)) } diff --git a/ui/content.go b/ui/content.go index c4f34900..67105215 100644 --- a/ui/content.go +++ b/ui/content.go @@ -22,7 +22,7 @@ type renderer interface { type content struct { // The uri for accessing this asset - uri string + uri string //nolint // The filename of the template relative to the asset directory template string diff --git a/vcs/vcs_test.go b/vcs/vcs_test.go index f965f250..5ef41e6b 100644 --- a/vcs/vcs_test.go +++ b/vcs/vcs_test.go @@ -8,7 +8,7 @@ import ( // Just make sure all drivers are tolerant of nil func TestNilConfigs(t *testing.T) { - for name, _ := range drivers { + for name, _ := range drivers { //nolint d, err := New(name, nil) if err != nil { t.Fatal(err)