Fix some lint problems

This commit is contained in:
Alessio 2022-03-06 15:36:07 -08:00
parent 06167eef18
commit 1582dfe44e
5 changed files with 58 additions and 42 deletions

View File

@ -26,7 +26,7 @@ linters:
# - wsl
# - wrapcheck
- lll
# - godox
- godox
# - errorlint
@ -97,10 +97,6 @@ linters-settings:
# # Exclude godoc examples from forbidigo checks. Default is true.
# exclude_godoc_examples: false
# funlen:
# lines: 60
# statements: 40
# gci:
# # put imports beginning with prefix after 3rd-party packages;
# # only support one prefix
@ -111,10 +107,6 @@ linters-settings:
# # minimal code complexity to report, 30 by default (but we recommend 10-20)
# min-complexity: 10
# nestif:
# # minimal complexity of if statements to report, 5 by default
# min-complexity: 4
# goconst:
# # minimal length of string constant, 3 by default
# min-len: 3
@ -205,11 +197,11 @@ linters-settings:
# # check that each sentence starts with a capital letter
# capital: false
# godox:
# # report any comments starting with keywords, this is useful for TODO or FIXME comments that
# # might be left in the code accidentally and should be resolved before merging
# keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
# - XXX
godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
- XXX
# gofmt:
# # simplify code: gofmt with `-s` option, true by default
@ -329,27 +321,27 @@ linters-settings:
# # https://staticcheck.io/docs/options#checks
# checks: [ "all" ]
# govet:
# # report about shadowed variables
# check-shadowing: true
govet:
# report about shadowed variables
check-shadowing: true
# # settings per analyzer
# settings per analyzer
# settings:
# printf: # analyzer name, run `go tool vet help` to see all analyzers
# funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# # enable or disable analyzers by name
# # run `go tool vet help` to see all analyzers
# enable or disable analyzers by name
# run `go tool vet help` to see all analyzers
# enable:
# - atomicalign
# enable-all: false
# disable:
# - shadow
enable-all: true
# disable-all: false
disable:
# - shadow
- fieldalignment
- composites
- shadow
# depguard:
# list-type: blacklist

View File

@ -97,7 +97,9 @@ func parse_user_from_row(row *sql.Row) (scraper.User, error) {
var u scraper.User
var joinDate int64
err := row.Scan(&u.ID, &u.DisplayName, &u.Handle, &u.Bio, &u.FollowingCount, &u.FollowersCount, &u.Location, &u.Website, &joinDate, &u.IsPrivate, &u.IsVerified, &u.IsBanned, &u.ProfileImageUrl, &u.ProfileImageLocalPath, &u.BannerImageUrl, &u.BannerImageLocalPath, &u.PinnedTweetID, &u.IsContentDownloaded, &u.IsFollowed)
err := row.Scan(&u.ID, &u.DisplayName, &u.Handle, &u.Bio, &u.FollowingCount, &u.FollowersCount, &u.Location, &u.Website, &joinDate,
&u.IsPrivate, &u.IsVerified, &u.IsBanned, &u.ProfileImageUrl, &u.ProfileImageLocalPath, &u.BannerImageUrl,
&u.BannerImageLocalPath, &u.PinnedTweetID, &u.IsContentDownloaded, &u.IsFollowed)
if err != nil {
return u, err
}
@ -120,7 +122,9 @@ func (p Profile) GetUserByHandle(handle scraper.UserHandle) (scraper.User, error
db := p.DB
stmt, err := db.Prepare(`
select id, display_name, handle, bio, following_count, followers_count, location, website, join_date, is_private, is_verified, is_banned, profile_image_url, profile_image_local_path, banner_image_url, banner_image_local_path, pinned_tweet_id, is_content_downloaded, is_followed
select id, display_name, handle, bio, following_count, followers_count, location, website, join_date, is_private, is_verified,
is_banned, profile_image_url, profile_image_local_path, banner_image_url, banner_image_local_path, pinned_tweet_id,
is_content_downloaded, is_followed
from users
where lower(handle) = lower(?)
`)
@ -151,7 +155,9 @@ func (p Profile) GetUserByID(id scraper.UserID) (scraper.User, error) {
db := p.DB
stmt, err := db.Prepare(`
select id, display_name, handle, bio, following_count, followers_count, location, website, join_date, is_private, is_verified, is_banned, profile_image_url, profile_image_local_path, banner_image_url, banner_image_local_path, pinned_tweet_id, is_content_downloaded, is_followed
select id, display_name, handle, bio, following_count, followers_count, location, website, join_date, is_private, is_verified,
is_banned, profile_image_url, profile_image_local_path, banner_image_url, banner_image_local_path, pinned_tweet_id,
is_content_downloaded, is_followed
from users
where id = ?
`)

View File

@ -48,7 +48,10 @@ func (api API) GetFeedFor(user_id UserID, cursor string) (TweetResponse, error)
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
s := ""
for header := range resp.Header {
s += fmt.Sprintf(" %s: %s\n", header, resp.Header.Get(header))
@ -133,7 +136,10 @@ func (api API) GetTweet(id TweetID, cursor string) (TweetResponse, error) {
defer resp.Body.Close()
if !(resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden) {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return TweetResponse{}, fmt.Errorf("Error getting %q. HTTP %s: %s", req.URL, resp.Status, content)
}
@ -206,7 +212,10 @@ func (api API) GetUser(handle UserHandle) (APIUser, error) {
// Sometimes it randomly gives 403 Forbidden. API's fault, not ours
// We check for this below
if !(resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden) {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return APIUser{}, fmt.Errorf("response status %s: %s", resp.Status, content)
}
@ -264,7 +273,10 @@ func (api API) Search(query string, cursor string) (TweetResponse, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return TweetResponse{}, fmt.Errorf("Error while searching for %q. HTTP %s: %s", req.URL, resp.Status, content)
}

View File

@ -400,7 +400,10 @@ func (api API) GetGraphqlFeedFor(user_id UserID, cursor string) (APIV2Response,
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
s := ""
for header := range resp.Header {
s += fmt.Sprintf(" %s: %s\n", header, resp.Header.Get(header))

View File

@ -34,7 +34,10 @@ func GetGuestToken() (string, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
content, _ := ioutil.ReadAll(resp.Body)
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return "", fmt.Errorf("HTTP %s: %s", resp.Status, content)
}