diff --git a/backend/.golangci.yml b/backend/.golangci.yml index f8c0c7af..3a68037d 100644 --- a/backend/.golangci.yml +++ b/backend/.golangci.yml @@ -25,6 +25,11 @@ linters-settings: - experimental disabled-checks: - wrapperFunc +# TODO: feel free to remove these excludes and fix the code + - hugeParam + - rangeValCopy + - singleCaseSwitch + - ifElseChain linters: enable: @@ -47,6 +52,7 @@ linters: - stylecheck - gochecknoinits - scopelint + - gocritic - nakedret - gosimple - prealloc diff --git a/backend/_example/memory_store/accessor/data.go b/backend/_example/memory_store/accessor/data.go index 94705230..290e9bba 100644 --- a/backend/_example/memory_store/accessor/data.go +++ b/backend/_example/memory_store/accessor/data.go @@ -535,18 +535,19 @@ func (m *MemData) get(loc store.Locator, commentID string) (store.Comment, error func (m *MemData) updateComment(comment store.Comment) error { comments := m.posts[comment.Locator.SiteID] for i, c := range comments { - if c.ID == comment.ID && c.Locator == comment.Locator { - c.Text = comment.Text - c.Orig = comment.Orig - c.Score = comment.Score - c.Votes = comment.Votes - c.Pin = comment.Pin - c.Deleted = comment.Deleted - c.User = comment.User - comments[i] = c - m.posts[comment.Locator.SiteID] = comments - return nil + if c.ID != comment.ID || c.Locator != comment.Locator { + continue } + c.Text = comment.Text + c.Orig = comment.Orig + c.Score = comment.Score + c.Votes = comment.Votes + c.Pin = comment.Pin + c.Deleted = comment.Deleted + c.User = comment.User + comments[i] = c + m.posts[comment.Locator.SiteID] = comments + return nil } return errors.New("not found") } diff --git a/backend/app/cmd/cleanup.go b/backend/app/cmd/cleanup.go index 73a34fdf..c69897c1 100644 --- a/backend/app/cmd/cleanup.go +++ b/backend/app/cmd/cleanup.go @@ -234,7 +234,7 @@ func (cc *CleanupCommand) setTitle(c store.Comment) error { } // isSpam calculates spam's probability as a score -func (cc *CleanupCommand) isSpam(comment store.Comment) (bool, float64) { +func (cc *CleanupCommand) isSpam(comment store.Comment) (isSpam bool, spamScore float64) { badWord := func(txt string) float64 { res := 0.0 diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index 64e8a0cd..ac2b00ab 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -170,16 +170,16 @@ func TestServerApp_AnonMode(t *testing.T) { app.Wait() } -func getAuthFromCookie(t *testing.T, app *serverApp, resp *http.Response) (token string, claims token.Claims) { +func getAuthFromCookie(t *testing.T, app *serverApp, resp *http.Response) (tkn string, claims token.Claims) { var err error for _, c := range resp.Cookies() { if c.Name == "JWT" { - token = c.Value + tkn = c.Value claims, err = app.restSrv.Authenticator.TokenService().Parse(c.Value) require.NoError(t, err) } } - return token, claims + return tkn, claims } func TestServerApp_WithSSL(t *testing.T) { diff --git a/backend/app/main.go b/backend/app/main.go index 7141cc13..98445595 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -84,7 +84,7 @@ func getDump() string { return string(stacktrace[:length]) } -// nolint:gochecknoinits +// nolint:gochecknoinits // can't avoid it in this place func init() { // catch SIGQUIT and print stack traces sigChan := make(chan os.Signal) diff --git a/backend/app/migrator/disqus.go b/backend/app/migrator/disqus.go index 14a5dc89..dabefd54 100644 --- a/backend/app/migrator/disqus.go +++ b/backend/app/migrator/disqus.go @@ -52,9 +52,8 @@ type uid struct { // Import from disqus and save to store func (d *Disqus) Import(r io.Reader, siteID string) (size int, err error) { - - if err = d.DataStore.DeleteAll(siteID); err != nil { - return 0, err + if e := d.DataStore.DeleteAll(siteID); e != nil { + return 0, e } commentsCh := d.convert(r, siteID) diff --git a/backend/app/migrator/native.go b/backend/app/migrator/native.go index 9ab7d1e8..f0d329b3 100644 --- a/backend/app/migrator/native.go +++ b/backend/app/migrator/native.go @@ -140,8 +140,8 @@ func (n *Native) Import(reader io.Reader, siteID string) (size int, err error) { return 0, errors.Errorf("unexpected import file version %d", m.Version) } - if err = n.DataStore.DeleteAll(siteID); err != nil { - return 0, err + if e := n.DataStore.DeleteAll(siteID); e != nil { + return 0, e } var failed, total, comments int64 diff --git a/backend/app/migrator/native_test.go b/backend/app/migrator/native_test.go index 6468b8dd..0b41ef67 100644 --- a/backend/app/migrator/native_test.go +++ b/backend/app/migrator/native_test.go @@ -178,7 +178,7 @@ func TestNative_ImportManyWithError(t *testing.T) { } // makes new boltdb, put two records -func prep(t *testing.T) (*service.DataStore, func()) { +func prep(t *testing.T) (ds *service.DataStore, teardown func()) { testDb := fmt.Sprintf("/tmp/migrator-%d.db", rand.Intn(999999999)) diff --git a/backend/app/migrator/wordpress.go b/backend/app/migrator/wordpress.go index 114afaf1..689e633e 100644 --- a/backend/app/migrator/wordpress.go +++ b/backend/app/migrator/wordpress.go @@ -61,8 +61,8 @@ func (w *WordPress) Convert(text string) string { // Import comments from WP and save to store func (w *WordPress) Import(r io.Reader, siteID string) (size int, err error) { - if err = w.DataStore.DeleteAll(siteID); err != nil { - return 0, err + if e := w.DataStore.DeleteAll(siteID); e != nil { + return 0, e } commentsCh := w.convert(r, siteID) diff --git a/backend/app/notify/notify_test.go b/backend/app/notify/notify_test.go index 2797e48a..93a1d562 100644 --- a/backend/app/notify/notify_test.go +++ b/backend/app/notify/notify_test.go @@ -123,6 +123,6 @@ func (m mockStore) Get(_ store.Locator, id string, _ store.User) (store.Comment, return res, nil } -func (m mockStore) GetUserEmail(_ string, _ string) (string, error) { +func (m mockStore) GetUserEmail(_, _ string) (string, error) { return "", errors.New("no such user") } diff --git a/backend/app/notify/telegram.go b/backend/app/notify/telegram.go index 9c4a650e..092dc810 100644 --- a/backend/app/notify/telegram.go +++ b/backend/app/notify/telegram.go @@ -27,7 +27,7 @@ const telegramTimeOut = 5000 * time.Millisecond const telegramAPIPrefix = "https://api.telegram.org/bot" // NewTelegram makes telegram bot for notifications -func NewTelegram(token string, channelID string, timeout time.Duration, api string) (*Telegram, error) { +func NewTelegram(token, channelID string, timeout time.Duration, api string) (*Telegram, error) { if _, err := strconv.ParseInt(channelID, 10, 64); err != nil { channelID = "@" + channelID // if channelID not a number enforce @ prefix diff --git a/backend/app/rest/api/migrator.go b/backend/app/rest/api/migrator.go index 2e286728..c1334424 100644 --- a/backend/app/rest/api/migrator.go +++ b/backend/app/rest/api/migrator.go @@ -212,7 +212,7 @@ func (m *Migrator) remapCtrl(w http.ResponseWriter, r *http.Request) { } // runImport reads from tmpfile and import for given siteID and provider -func (m *Migrator) runImport(siteID string, provider string, tmpfile string) { +func (m *Migrator) runImport(siteID, provider, tmpfile string) { m.setBusy(siteID, true) defer func() { diff --git a/backend/app/rest/api/rest_private_test.go b/backend/app/rest/api/rest_private_test.go index 729c6d05..31e95cf6 100644 --- a/backend/app/rest/api/rest_private_test.go +++ b/backend/app/rest/api/rest_private_test.go @@ -717,11 +717,11 @@ func TestRest_UserAllData(t *testing.T) { // write 3 comments user := store.User{ID: "dev", Name: "user name 1"} c1 := store.Comment{User: user, Text: "test test #1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 10, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 10, 0, time.Local)} c2 := store.Comment{User: user, Text: "test test #2", ParentID: "p1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 20, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 20, 0, time.Local)} c3 := store.Comment{User: user, Text: "test test #3", ParentID: "p1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 25, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 25, 0, time.Local)} _, err := srv.DataService.Create(c1) require.NoError(t, err, "%+v", err) _, err = srv.DataService.Create(c2) @@ -771,7 +771,7 @@ func TestRest_UserAllDataManyComments(t *testing.T) { user := store.User{ID: "dev", Name: "user name 1"} c := store.Comment{User: user, Text: "test test #1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 10, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 10, 0, time.Local)} for i := 0; i < 51; i++ { c.ID = fmt.Sprintf("id-%03d", i) @@ -818,11 +818,11 @@ func TestRest_DeleteMe(t *testing.T) { assert.Equal(t, "remark42", m["site"]) assert.Equal(t, "dev", m["user_id"]) - token := m["token"] - claims, err := srv.Authenticator.TokenService().Parse(token) + tkn := m["token"] + claims, err := srv.Authenticator.TokenService().Parse(tkn) assert.NoError(t, err) assert.Equal(t, "dev", claims.User.ID) - assert.Equal(t, "https://demo.remark42.com/web/deleteme.html?token="+token, m["link"]) + assert.Equal(t, "https://demo.remark42.com/web/deleteme.html?token="+tkn, m["link"]) req, err = http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/v1/deleteme?site=remark42", ts.URL), nil) assert.NoError(t, err) diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 1e529ad3..48cebd76 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -546,11 +546,11 @@ func TestRest_Info(t *testing.T) { user := store.User{ID: "user1", Name: "user name 1"} c1 := store.Comment{User: user, Text: "test test #1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 10, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 10, 0, time.Local)} c2 := store.Comment{User: user, Text: "test test #2", ParentID: "p1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 20, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 20, 0, time.Local)} c3 := store.Comment{User: user, Text: "test test #3", ParentID: "p1", Locator: store.Locator{SiteID: "remark42", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 25, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 25, 0, time.Local)} _, err := srv.DataService.Create(c1) require.NoError(t, err, "%+v", err) @@ -566,7 +566,7 @@ func TestRest_Info(t *testing.T) { err = json.Unmarshal([]byte(body), &info) assert.NoError(t, err) exp := store.PostInfo{URL: "https://radio-t.com/blah1", Count: 3, - FirstTS: time.Date(2018, 05, 27, 1, 14, 10, 0, time.Local), LastTS: time.Date(2018, 05, 27, 1, 14, 25, 0, time.Local)} + FirstTS: time.Date(2018, 5, 27, 1, 14, 10, 0, time.Local), LastTS: time.Date(2018, 5, 27, 1, 14, 25, 0, time.Local)} assert.Equal(t, exp, info) _, code = get(t, ts.URL+"/api/v1/info?site=remark42&url=https://radio-t.com/blah-no") diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go index 2b4b5366..3193a761 100644 --- a/backend/app/rest/api/rest_test.go +++ b/backend/app/rest/api/rest_test.go @@ -99,11 +99,11 @@ func TestRest_Shutdown(t *testing.T) { func TestRest_filterComments(t *testing.T) { user := store.User{ID: "user1", Name: "user name 1"} c1 := store.Comment{User: user, Text: "test test #1", Locator: store.Locator{SiteID: "radio-t", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 10, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 10, 0, time.Local)} c2 := store.Comment{User: user, Text: "test test #2", ParentID: "p1", Locator: store.Locator{SiteID: "radio-t", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 20, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 20, 0, time.Local)} c3 := store.Comment{User: user, Text: "test test #3", ParentID: "p1", Locator: store.Locator{SiteID: "radio-t", - URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 05, 27, 1, 14, 25, 0, time.Local)} + URL: "https://radio-t.com/blah1"}, Timestamp: time.Date(2018, 5, 27, 1, 14, 25, 0, time.Local)} r := filterComments([]store.Comment{c1, c2, c3}, func(c store.Comment) bool { return c.Text == "test test #1" || c.Text == "test test #3" @@ -428,7 +428,7 @@ func fakeAuth(next http.Handler) http.Handler { return http.HandlerFunc(fn) } -func get(t *testing.T, url string) (string, int) { +func get(t *testing.T, url string) (response string, statusCode int) { r, err := http.Get(url) require.NoError(t, err) defer r.Body.Close() @@ -437,10 +437,10 @@ func get(t *testing.T, url string) (string, int) { return string(body), r.StatusCode } -func sendReq(_ *testing.T, r *http.Request, token string) (*http.Response, error) { +func sendReq(_ *testing.T, r *http.Request, tkn string) (*http.Response, error) { client := http.Client{Timeout: 5 * time.Second} - if token != "" { - r.Header.Set("X-JWT", token) + if tkn != "" { + r.Header.Set("X-JWT", tkn) } return client.Do(r) } @@ -458,7 +458,7 @@ func getWithDevAuth(t *testing.T, url string) (body string, code int) { return string(b), r.StatusCode } -func getWithAdminAuth(t *testing.T, url string) (string, int) { +func getWithAdminAuth(t *testing.T, url string) (response string, statusCode int) { client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("GET", url, nil) require.NoError(t, err) @@ -470,7 +470,7 @@ func getWithAdminAuth(t *testing.T, url string) (string, int) { assert.NoError(t, err) return string(body), r.StatusCode } -func post(t *testing.T, url string, body string) (*http.Response, error) { +func post(t *testing.T, url, body string) (*http.Response, error) { client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("POST", url, strings.NewReader(body)) assert.NoError(t, err) diff --git a/backend/app/rest/api/rss_test.go b/backend/app/rest/api/rss_test.go index d175f9bb..0dce54f8 100644 --- a/backend/app/rest/api/rss_test.go +++ b/backend/app/rest/api/rss_test.go @@ -279,7 +279,7 @@ func waitOnSecChange() { } // clean formatting, i.e. multiple spaces, \t, \n -func cleanRssFormatting(expected, actual string) (string, string) { +func cleanRssFormatting(expected, actual string) (cleanExp, cleanAct string) { reSpaces := regexp.MustCompile(`[\s\p{Zs}]{2,}`) expected = strings.Replace(expected, "\n", " ", -1) diff --git a/backend/app/store/admin/admin.go b/backend/app/store/admin/admin.go index 7651cc08..2a3d7aac 100644 --- a/backend/app/store/admin/admin.go +++ b/backend/app/store/admin/admin.go @@ -37,7 +37,7 @@ type StaticStore struct { } // NewStaticStore makes StaticStore instance with given key -func NewStaticStore(key string, sites []string, admins []string, email string) *StaticStore { +func NewStaticStore(key string, sites, admins []string, email string) *StaticStore { log.Printf("[DEBUG] admin users %+v, email %s", admins, email) return &StaticStore{key: key, sites: sites, admins: admins, email: email} } diff --git a/backend/app/store/admin/remote.go b/backend/app/store/admin/remote.go index 5797d18b..b0e7f19c 100644 --- a/backend/app/store/admin/remote.go +++ b/backend/app/store/admin/remote.go @@ -35,7 +35,7 @@ func (r *RPC) Admins(siteID string) (ids []string, err error) { return []string{}, err } - if err = json.Unmarshal(*resp.Result, &ids); err != nil { + if err := json.Unmarshal(*resp.Result, &ids); err != nil { return []string{}, err } return ids, nil @@ -48,7 +48,7 @@ func (r *RPC) Email(siteID string) (email string, err error) { return "", err } - if err = json.Unmarshal(*resp.Result, &email); err != nil { + if err := json.Unmarshal(*resp.Result, &email); err != nil { return "", err } return email, nil @@ -61,7 +61,7 @@ func (r *RPC) Enabled(siteID string) (ok bool, err error) { return false, err } - if err = json.Unmarshal(*resp.Result, &ok); err != nil { + if err := json.Unmarshal(*resp.Result, &ok); err != nil { return false, err } return ok, nil diff --git a/backend/app/store/engine/bolt.go b/backend/app/store/engine/bolt.go index 35992138..d2ee14e6 100644 --- a/backend/app/store/engine/bolt.go +++ b/backend/app/store/engine/bolt.go @@ -55,7 +55,7 @@ func NewBoltDB(options bolt.Options, sites ...BoltSite) (*BoltDB, error) { log.Printf("[INFO] bolt store for sites %+v, options %+v", sites, options) result := BoltDB{dbs: make(map[string]*bolt.DB)} for _, site := range sites { - db, err := bolt.Open(site.FileName, 0600, &options) + db, err := bolt.Open(site.FileName, 0600, &options) //nolint:gocritic //octalLiteral is OK as FileMode if err != nil { return nil, errors.Wrapf(err, "failed to make boltdb for %s", site.FileName) } @@ -844,7 +844,7 @@ func (b *BoltDB) deleteAll(bdb *bolt.DB, siteID string) error { // deleteUser removes all comments and details for given user. Everything will be market as deleted // and user name and userID will be changed to "deleted". Also removes from last and from user buckets. -func (b *BoltDB) deleteUser(bdb *bolt.DB, siteID string, userID string, mode store.DeleteMode) error { +func (b *BoltDB) deleteUser(bdb *bolt.DB, siteID, userID string, mode store.DeleteMode) error { // get list of all comments outside of transaction loop posts, err := b.Info(InfoRequest{Locator: store.Locator{SiteID: siteID}}) @@ -1008,7 +1008,8 @@ func (b *BoltDB) setInfo(tx *bolt.Tx, comment store.Comment) (store.PostInfo, er } info.Count++ info.LastTS = comment.Timestamp - return info, b.save(infoBkt, comment.Locator.URL, &info) + err := b.save(infoBkt, comment.Locator.URL, &info) + return info, err } func (b *BoltDB) db(siteID string) (*bolt.DB, error) { @@ -1024,7 +1025,7 @@ func (b *BoltDB) makeRef(comment store.Comment) []byte { } // parseRef gets parts of reference -func (b *BoltDB) parseRef(val []byte) (url string, id string, err error) { +func (b *BoltDB) parseRef(val []byte) (url, id string, err error) { elems := strings.Split(string(val), "!!") if len(elems) != 2 { return "", "", errors.Errorf("invalid reference value %s", string(val)) diff --git a/backend/app/store/image/bolt_store.go b/backend/app/store/image/bolt_store.go index ff1ac801..b13f7114 100644 --- a/backend/app/store/image/bolt_store.go +++ b/backend/app/store/image/bolt_store.go @@ -25,7 +25,7 @@ type Bolt struct { // NewBoltStorage create bolt image store func NewBoltStorage(fileName string, options bolt.Options) (*Bolt, error) { - db, err := bolt.Open(fileName, 0600, &options) + db, err := bolt.Open(fileName, 0600, &options) //nolint:gocritic //octalLiteral is OK as FileMode if err != nil { return nil, errors.Wrapf(err, "failed to make boltdb for %s", fileName) } diff --git a/backend/app/store/image/bolt_store_test.go b/backend/app/store/image/bolt_store_test.go index 14c7dc88..25d0038b 100644 --- a/backend/app/store/image/bolt_store_test.go +++ b/backend/app/store/image/bolt_store_test.go @@ -124,21 +124,21 @@ func TestBolt_Info(t *testing.T) { assert.False(t, info.FirstStagingImageTS.IsZero()) } -func assertBoltImgNil(t *testing.T, db *bolt.DB, bucket string, id string) { +func assertBoltImgNil(t *testing.T, db *bolt.DB, bucket, id string) { checkBoltImgData(t, db, bucket, id, func(data []byte) error { assert.Nil(t, data, id) return nil }) } -func assertBoltImgNotNil(t *testing.T, db *bolt.DB, bucket string, id string) { +func assertBoltImgNotNil(t *testing.T, db *bolt.DB, bucket, id string) { checkBoltImgData(t, db, bucket, id, func(data []byte) error { assert.NotNil(t, data, id) return nil }) } -func checkBoltImgData(t *testing.T, db *bolt.DB, bucket string, id string, callback func([]byte) error) { +func checkBoltImgData(t *testing.T, db *bolt.DB, bucket, id string, callback func([]byte) error) { err := db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket([]byte(bucket)) assert.NotNil(t, bkt, "bucket %s not found", bucket) diff --git a/backend/app/store/image/fs_store.go b/backend/app/store/image/fs_store.go index 5306dc35..919a8de0 100644 --- a/backend/app/store/image/fs_store.go +++ b/backend/app/store/image/fs_store.go @@ -81,7 +81,7 @@ func (f *FileSystem) Load(id string) ([]byte, error) { return nil, errors.Wrapf(err, "can't get image file for %s", id) } - fh, err := os.Open(imgFile) //nolint:gosec + fh, err := os.Open(imgFile) //nolint:gosec // we open file from known location if err != nil { return nil, errors.Wrapf(err, "can't load image %s", id) } @@ -146,7 +146,7 @@ func (f *FileSystem) Info() (StoreInfo, error) { // and avoid too many files in a single place. // the end result is a full path like this - /tmp/images/user1/92/xxx-yyy.png. // Number of partitions defined by FileSystem.Partitions -func (f *FileSystem) location(base string, id string) string { +func (f *FileSystem) location(base, id string) string { partition := func(id string) string { f.crc.Do(func() { diff --git a/backend/app/store/image/image.go b/backend/app/store/image/image.go index c94f9623..616e0458 100644 --- a/backend/app/store/image/image.go +++ b/backend/app/store/image/image.go @@ -294,7 +294,7 @@ func resize(data []byte, limitW, limitH int) []byte { } // getProportionalSizes returns width and height resized by both dimensions proportionally -func getProportionalSizes(srcW, srcH int, limitW, limitH int) (resW, resH int) { +func getProportionalSizes(srcW, srcH, limitW, limitH int) (resW, resH int) { if srcW <= limitW && srcH <= limitH { return srcW, srcH diff --git a/backend/app/store/image/remote_store.go b/backend/app/store/image/remote_store.go index b0048157..86a9a1bd 100644 --- a/backend/app/store/image/remote_store.go +++ b/backend/app/store/image/remote_store.go @@ -29,7 +29,7 @@ func (r *RPC) Load(id string) ([]byte, error) { return nil, err } var rawImg string - if err = json.Unmarshal(*resp.Result, &rawImg); err != nil { + if err := json.Unmarshal(*resp.Result, &rawImg); err != nil { return nil, err } return ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, strings.NewReader(rawImg))) @@ -54,8 +54,8 @@ func (r *RPC) Info() (StoreInfo, error) { return StoreInfo{}, err } info := StoreInfo{} - if err = json.Unmarshal(*resp.Result, &info); err != nil { - return StoreInfo{}, err + if e := json.Unmarshal(*resp.Result, &info); e != nil { + return StoreInfo{}, e } return info, err } diff --git a/backend/app/store/service/restricted_words.go b/backend/app/store/service/restricted_words.go index 7a4d0a54..c6400ebf 100644 --- a/backend/app/store/service/restricted_words.go +++ b/backend/app/store/service/restricted_words.go @@ -34,7 +34,7 @@ func NewRestrictedWordsMatcher(lister RestrictedWordsLister) *RestrictedWordsMat } // Match matches comment text against restricted words for specified site -func (m *RestrictedWordsMatcher) Match(siteID string, text string) bool { +func (m *RestrictedWordsMatcher) Match(siteID, text string) bool { restrictedWords, err := m.lister.List(siteID) if err != nil { log.Printf("[WARN] failed to get restricted patterns for site %s: %v", siteID, err) @@ -127,7 +127,7 @@ func (trie *wildcardTrie) addPattern(pattern string) { // check tests if any pattern stored in trie matches the token. Recursive. Max depth is longest pattern in trie. func (trie *wildcardTrie) check(token string) bool { - if len(token) == 0 { + if token == "" { if trie.terminal { return true } @@ -162,7 +162,7 @@ func (trie *wildcardTrie) check(token string) bool { func (trie *wildcardTrie) checkAllSuffixes(token string) bool { suffix := token for { - if len(suffix) == 0 { + if suffix == "" { return false } diff --git a/backend/app/store/service/service.go b/backend/app/store/service/service.go index a3d65fd9..2e59d62c 100644 --- a/backend/app/store/service/service.go +++ b/backend/app/store/service/service.go @@ -111,13 +111,13 @@ func (s *DataStore) Create(comment store.Comment) (commentID string, err error) // Find wraps engine's Find call and alter results if needed. User used to alter comments // in order to differentiate between user's comments vs others comments. -func (s *DataStore) Find(locator store.Locator, sort string, user store.User) ([]store.Comment, error) { - return s.FindSince(locator, sort, user, time.Time{}) +func (s *DataStore) Find(locator store.Locator, sortMethod string, user store.User) ([]store.Comment, error) { + return s.FindSince(locator, sortMethod, user, time.Time{}) } // FindSince wraps engine's Find call and alter results if needed. Returns comments after since tx -func (s *DataStore) FindSince(locator store.Locator, sort string, user store.User, since time.Time) ([]store.Comment, error) { - req := engine.FindRequest{Locator: locator, Sort: sort, Since: since} +func (s *DataStore) FindSince(locator store.Locator, sortMethod string, user store.User, since time.Time) ([]store.Comment, error) { + req := engine.FindRequest{Locator: locator, Sort: sortMethod, Since: since} comments, err := s.Engine.Find(req) if err != nil { return comments, err @@ -128,7 +128,7 @@ func (s *DataStore) FindSince(locator store.Locator, sort string, user store.Use for i, c := range comments { if c.Controversy == 0 && len(c.Votes) > 0 { c.Controversy = s.controversy(s.upsAndDowns(c)) - if !changedSort && strings.Contains(sort, "controversy") { // trigger sort change + if !changedSort && strings.Contains(sortMethod, "controversy") { // trigger sort change changedSort = true } } @@ -137,7 +137,7 @@ func (s *DataStore) FindSince(locator store.Locator, sort string, user store.Use // resort commits if altered if changedSort { - comments = engine.SortComments(comments, sort) + comments = engine.SortComments(comments, sortMethod) } return comments, nil @@ -159,7 +159,7 @@ func (s *DataStore) Put(locator store.Locator, comment store.Comment) error { } // GetUserEmail gets user email -func (s *DataStore) GetUserEmail(siteID string, userID string) (string, error) { +func (s *DataStore) GetUserEmail(siteID, userID string) (string, error) { res, err := s.Engine.UserDetail(engine.UserDetailRequest{ Detail: engine.UserEmail, Locator: store.Locator{SiteID: siteID}, @@ -175,7 +175,7 @@ func (s *DataStore) GetUserEmail(siteID string, userID string) (string, error) { } // SetUserEmail sets user email -func (s *DataStore) SetUserEmail(siteID string, userID string, value string) (string, error) { +func (s *DataStore) SetUserEmail(siteID, userID, value string) (string, error) { res, err := s.Engine.UserDetail(engine.UserDetailRequest{ Detail: engine.UserEmail, Locator: store.Locator{SiteID: siteID}, @@ -192,7 +192,7 @@ func (s *DataStore) SetUserEmail(siteID string, userID string, value string) (st } // DeleteUserDetail deletes user detail -func (s *DataStore) DeleteUserDetail(siteID string, userID string, detail engine.UserDetail) error { +func (s *DataStore) DeleteUserDetail(siteID, userID string, detail engine.UserDetail) error { return s.Engine.Delete(engine.DeleteRequest{ Locator: store.Locator{SiteID: siteID}, UserID: userID, @@ -590,7 +590,7 @@ func (s *DataStore) ValidateComment(c *store.Comment) error { } // IsAdmin checks if usesID in the list of admins -func (s *DataStore) IsAdmin(siteID string, userID string) bool { +func (s *DataStore) IsAdmin(siteID, userID string) bool { admins, err := s.AdminStore.Admins(siteID) if err != nil { log.Printf("[WARN] can't get admins for %s, %v", siteID, err) @@ -624,14 +624,14 @@ func (s *DataStore) SetReadOnly(locator store.Locator, status bool) error { } // IsVerified checks if user verified -func (s *DataStore) IsVerified(siteID string, userID string) bool { +func (s *DataStore) IsVerified(siteID, userID string) bool { req := engine.FlagRequest{Locator: store.Locator{SiteID: siteID}, UserID: userID, Flag: engine.Verified} ro, err := s.Engine.Flag(req) return err == nil && ro } // SetVerified set/reset verified status for user -func (s *DataStore) SetVerified(siteID string, userID string, status bool) error { +func (s *DataStore) SetVerified(siteID, userID string, status bool) error { roStatus := engine.FlagFalse if status { roStatus = engine.FlagTrue @@ -642,14 +642,14 @@ func (s *DataStore) SetVerified(siteID string, userID string, status bool) error } // IsBlocked checks if user blocked -func (s *DataStore) IsBlocked(siteID string, userID string) bool { +func (s *DataStore) IsBlocked(siteID, userID string) bool { req := engine.FlagRequest{Locator: store.Locator{SiteID: siteID}, UserID: userID, Flag: engine.Blocked} ro, err := s.Engine.Flag(req) return err == nil && ro } // SetBlock set/reset verified status for user -func (s *DataStore) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error { +func (s *DataStore) SetBlock(siteID, userID string, status bool, ttl time.Duration) error { roStatus := engine.FlagFalse if status { roStatus = engine.FlagTrue @@ -695,13 +695,13 @@ func (s *DataStore) Delete(locator store.Locator, commentID string, mode store.D } // DeleteUser removes all comments from user -func (s *DataStore) DeleteUser(siteID string, userID string, mode store.DeleteMode) error { +func (s *DataStore) DeleteUser(siteID, userID string, mode store.DeleteMode) error { req := engine.DeleteRequest{Locator: store.Locator{SiteID: siteID}, UserID: userID, DeleteMode: mode} return s.Engine.Delete(req) } // List of commented posts -func (s *DataStore) List(siteID string, limit int, skip int) ([]store.PostInfo, error) { +func (s *DataStore) List(siteID string, limit, skip int) ([]store.PostInfo, error) { req := engine.InfoRequest{Locator: store.Locator{SiteID: siteID}, Limit: limit, Skip: skip} return s.Engine.Info(req) } diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index a7748cd0..ec30136f 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -1465,7 +1465,7 @@ func Benchmark_ServiceCreate(b *testing.B) { } // makes new boltdb, put two records -func prepStoreEngine(t *testing.T) (engine.Interface, func()) { +func prepStoreEngine(t *testing.T) (e engine.Interface, teardown func()) { testDbLoc, err := ioutil.TempDir("", "test_image_r42") require.NoError(t, err) testDb := path.Join(testDbLoc, "test.db") diff --git a/backend/app/store/service/tree.go b/backend/app/store/service/tree.go index fead012e..7f915368 100644 --- a/backend/app/store/service/tree.go +++ b/backend/app/store/service/tree.go @@ -79,7 +79,7 @@ func MakeTree(comments []store.Comment, sortType string, readOnlyAge int) *Tree } // proc makes tree for one top-level comment recursively -func (t *Tree) proc(comments []store.Comment, node *Node, rd *recurData, parentID string) (*Node, time.Time, time.Time) { +func (t *Tree) proc(comments []store.Comment, node *Node, rd *recurData, parentID string) (result *Node, modified, created time.Time) { if rd.tsModified.IsZero() || rd.tsCreated.IsZero() { rd.tsModified, rd.tsCreated = node.Comment.Timestamp, node.Comment.Timestamp diff --git a/backend/app/store/user.go b/backend/app/store/user.go index b9bded97..9d8b28ad 100644 --- a/backend/app/store/user.go +++ b/backend/app/store/user.go @@ -35,7 +35,7 @@ func (u *User) HashIP(secret string) { } // HashValue makes hmac with secret -func HashValue(val string, secret string) string { +func HashValue(val, secret string) string { key := []byte(secret) return hashWithFallback(hmac.New(sha1.New, key), val) }