Skip to content

Commit

Permalink
fix: drop golint and change to golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pashifika committed Aug 22, 2023
1 parent c925eca commit be6b9bf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run:
skip-files:
- ".*\\_test\\.go$"
4 changes: 2 additions & 2 deletions cmd/colly/colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 8 additions & 7 deletions colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
5 changes: 3 additions & 2 deletions debug/webdebugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func (w *WebDebugger) Event(e *Event) {
}

func (w *WebDebugger) indexHandler(wr http.ResponseWriter, r *http.Request) {
wr.Write([]byte(`<!DOCTYPE html>
_, _ = wr.Write([]byte(`<!DOCTYPE html>
<html>
<head>
<title>Colly Debugger WebUI</title>
Expand Down Expand Up @@ -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)
}
6 changes: 2 additions & 4 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{}{}
}
}
Expand Down
4 changes: 2 additions & 2 deletions unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit be6b9bf

Please sign in to comment.