diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12e210868..18a019fa5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,10 +31,10 @@ jobs: - name: Test run: | - go install golang.org/x/lint/golint@latest + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 OUT="$(go get -a)"; test -z "$OUT" || (echo "$OUT" && return 1) OUT="$(gofmt -l -d ./)"; test -z "$OUT" || (echo "$OUT" && return 1) - golint -set_exit_status + golangci-lint run go vet -v ./... go test -race -v -coverprofile=coverage.txt -covermode=atomic ./... @@ -62,18 +62,18 @@ jobs: - name: Build run: | - go install golang.org/x/lint/golint@latest + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 OUT="$(go get -a)"; test -z "$OUT" || (echo "$OUT" && return 1) OUT="$(gofmt -l -d ./)"; test -z "$OUT" || (echo "$OUT" && return 1) - golint -set_exit_status + golangci-lint run go build codecov: - name: Codecov + name: Codecov runs-on: [ubuntu-latest] - needs: + needs: - test - build steps: - - name: Run Codecov + - name: Run Codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..c5671d98f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + skip-files: + - ".*\\_test\\.go$" diff --git a/cmd/colly/colly.go b/cmd/colly/colly.go index a8e626fd3..a460eaaa7 100644 --- a/cmd/colly/colly.go +++ b/cmd/colly/colly.go @@ -113,9 +113,9 @@ func main() { } } scraper.WriteString(scraperEndTemplate) - outfile.Write(scraper.Bytes()) + _, _ = outfile.Write(scraper.Bytes()) } }) - app.Run(os.Args) + _ = app.Run(os.Args) } diff --git a/colly.go b/colly.go index fdca94518..c5eacc6d0 100644 --- a/colly.go +++ b/colly.go @@ -450,7 +450,7 @@ func DetectCharset() CollectorOption { // Debugger sets the debugger used by the Collector. func Debugger(d debug.Debugger) CollectorOption { return func(c *Collector) { - d.Init() + _ = d.Init() c.debugger = d } } @@ -470,7 +470,7 @@ func (c *Collector) Init() { c.MaxDepth = 0 c.MaxRequests = 0 c.store = &storage.InMemoryStorage{} - c.store.Init() + _ = c.store.Init() c.MaxBodySize = 10 * 1024 * 1024 c.backend = &httpBackend{} jar, _ := cookiejar.New(nil) @@ -573,7 +573,7 @@ func (c *Collector) Request(method, URL string, requestData io.Reader, ctx *Cont // SetDebugger attaches a debugger to the collector func (c *Collector) SetDebugger(d debug.Debugger) { - d.Init() + _ = d.Init() c.debugger = d } @@ -648,6 +648,7 @@ func (c *Collector) scrape(u, method string, depth int, requestData io.Reader, c u = parsedURL.String() c.wg.Add(1) if c.Async { + // nolint:errcheck go c.fetch(u, method, depth, requestData, ctx, hdr, req) return nil } @@ -720,12 +721,12 @@ func (c *Collector) fetch(u, method string, depth int, requestData io.Reader, ct err = c.handleOnHTML(response) if err != nil { - c.handleOnError(response, err, request, ctx) + _ = c.handleOnError(response, err, request, ctx) } err = c.handleOnXML(response) if err != nil { - c.handleOnError(response, err, request, ctx) + _ = c.handleOnError(response, err, request, ctx) } c.handleOnScraped(response) @@ -1523,9 +1524,9 @@ func requestHash(url string, body io.Reader) uint64 { h := fnv.New64a() // reparse the url to fix ambiguities such as // "http://example.com" vs "http://example.com/" - io.WriteString(h, normalizeURL(url)) + _, _ = io.WriteString(h, normalizeURL(url)) if body != nil { - io.Copy(h, body) + _, _ = io.Copy(h, body) } return h.Sum64() } diff --git a/debug/webdebugger.go b/debug/webdebugger.go index 504a9eb04..bf7bdc783 100644 --- a/debug/webdebugger.go +++ b/debug/webdebugger.go @@ -57,6 +57,7 @@ func (w *WebDebugger) Init() error { http.HandleFunc("/", w.indexHandler) http.HandleFunc("/status", w.statusHandler) log.Println("Starting debug webserver on", w.Address) + // nolint:errcheck go http.ListenAndServe(w.Address, nil) return nil } @@ -84,7 +85,7 @@ func (w *WebDebugger) Event(e *Event) { } func (w *WebDebugger) indexHandler(wr http.ResponseWriter, r *http.Request) { - wr.Write([]byte(` + _, _ = wr.Write([]byte(` Colly Debugger WebUI @@ -149,5 +150,5 @@ func (w *WebDebugger) statusHandler(wr http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } - wr.Write(jsonData) + _, _ = wr.Write(jsonData) } diff --git a/queue/queue.go b/queue/queue.go index 0d0d78a66..6e980cf3b 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -9,8 +9,6 @@ import ( "github.com/gocolly/colly/v2" ) -const stop = true - var urlParser = whatwgUrl.NewParser(whatwgUrl.WithPercentEncodeSinglePercentSign()) // Storage is the interface of the queue's storage backend @@ -132,7 +130,7 @@ func (q *Queue) Size() (int, error) { // The given Storage must not be used directly while Run blocks. func (q *Queue) Run(c *colly.Collector) error { q.mut.Lock() - if q.wake != nil && q.running == true { + if q.wake != nil && q.running { q.mut.Unlock() panic("cannot call duplicate Queue.Run") } @@ -206,7 +204,7 @@ func (q *Queue) loop(c *colly.Collector, requestc chan<- *colly.Request, complet func independentRunner(requestc <-chan *colly.Request, complete chan<- struct{}) { for req := range requestc { - req.Do() + _ = req.Do() complete <- struct{}{} } } diff --git a/unmarshal.go b/unmarshal.go index 42ceb2a69..94a80480c 100644 --- a/unmarshal.go +++ b/unmarshal.go @@ -194,13 +194,13 @@ func unmarshalSlice(s *goquery.Selection, selector, htmlAttr string, attrV refle case reflect.Ptr: s.Find(selector).Each(func(_ int, innerSel *goquery.Selection) { someVal := reflect.New(attrV.Type().Elem().Elem()) - UnmarshalHTML(someVal.Interface(), innerSel, nil) + _ = UnmarshalHTML(someVal.Interface(), innerSel, nil) attrV.Set(reflect.Append(attrV, someVal)) }) case reflect.Struct: s.Find(selector).Each(func(_ int, innerSel *goquery.Selection) { someVal := reflect.New(attrV.Type().Elem()) - UnmarshalHTML(someVal.Interface(), innerSel, nil) + _ = UnmarshalHTML(someVal.Interface(), innerSel, nil) attrV.Set(reflect.Append(attrV, reflect.Indirect(someVal))) }) default: