Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix linter warnings and add GH lint workflow #1074

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: golangci-lint
on:
workflow_dispatch:
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "stable"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
only-new-issues: true
args: --timeout=10m
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
run:
# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-dirs:
- internal/gopher-lua
- internal/cronexpr

linters:
enable:
- gofmt

linters-settings:
gofmt:
simplify: false

errcheck:
ignore: cleanup
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]
### Fixed
- Fixed multiple issues found by linter.

### [3.17.1] - 2023-08-23
### Added
Expand Down
204 changes: 102 additions & 102 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
// application we load from the yaml file to get the necessary parameters to
// create the connection. Our base.yaml looks like this
//
// base.yaml
// ---
// mysql:
// user: 'foo'
// password: 'xxxxxx'
// mysql_defaults_file: ./mysql_defaults.ini
// mysql_socket_path: /var/run/mysqld/mysqld.sock
// ... more config options ...
// base.yaml
// ---
// mysql:
// user: 'foo'
// password: 'xxxxxx'
// mysql_defaults_file: ./mysql_defaults.ini
// mysql_socket_path: /var/run/mysqld/mysqld.sock
// ... more config options ...
//
// we want to load all the configs from it but we want to provide some
// flexibility for the program to connect via a different db user. We could
Expand All @@ -56,125 +56,125 @@
//
// Let's say we have our configration object as the following.
//
// type logging struct {
// Interval int
// Path string
// }
// type logging struct {
// Interval int
// Path string
// }
//
// type socket struct {
// ReadTimeout time.Duration
// WriteTimeout time.Duration
// }
// type socket struct {
// ReadTimeout time.Duration
// WriteTimeout time.Duration
// }
//
// type tcp struct {
// ReadTimeout time.Duration
// socket
// }
// type tcp struct {
// ReadTimeout time.Duration
// socket
// }
//
// type network struct {
// ReadTimeout time.Duration
// WriteTimeout time.Duration
// tcp
// }
// type network struct {
// ReadTimeout time.Duration
// WriteTimeout time.Duration
// tcp
// }
//
// type Cfg struct {
// logging
// network
// }
// type Cfg struct {
// logging
// network
// }
//
// The following code
//
// func main() {
// c := &Cfg{}
// flags.ParseArgs(c, os.Args[1:])
// }
// func main() {
// c := &Cfg{}
// flags.ParseArgs(c, os.Args[1:])
// }
//
// will create the following flags
//
// -logging.interval int
// logging.interval
// -logging.path string
// logging.path
// -network.readtimeout duration
// network.readtimeout
// -network.tcp.readtimeout duration
// network.tcp.readtimeout
// -network.tcp.socket.readtimeout duration
// network.tcp.socket.readtimeout
// -network.tcp.socket.writetimeout duration
// network.tcp.socket.writetimeout
// -network.writetimeout duration
// network.writetimeout
// -logging.interval int
// logging.interval
// -logging.path string
// logging.path
// -network.readtimeout duration
// network.readtimeout
// -network.tcp.readtimeout duration
// network.tcp.readtimeout
// -network.tcp.socket.readtimeout duration
// network.tcp.socket.readtimeout
// -network.tcp.socket.writetimeout duration
// network.tcp.socket.writetimeout
// -network.writetimeout duration
// network.writetimeout
//
// flags to subcommands are naturally suported.
//
// func main() {
// cmd := os.Args[1]
// switch cmd {
// case "new"
// c1 := &Cfg1{}
// ParseArgs(c1, os.Args[2:])
// case "update":
// c2 := &Cfg2{}
// ParseArgs(c2, os.Args[2:])
// func main() {
// cmd := os.Args[1]
// switch cmd {
// case "new"
// c1 := &Cfg1{}
// ParseArgs(c1, os.Args[2:])
// case "update":
// c2 := &Cfg2{}
// ParseArgs(c2, os.Args[2:])
//
// ... more sub commands ...
// }
// }
// ... more sub commands ...
// }
// }
//
// One can set Flatten to true when calling NewFlagMakerAdv, in which case,
// flags are created without namespacing. For example,
//
// type auth struct {
// Token string
// Tag float64
// }
//
// type credentials struct {
// User string
// Password string
// auth
// }
//
// type database struct {
// DBName string
// TableName string
// credentials
// }
//
// type Cfg struct {
// logging
// database
// }
//
// func main() {
// c := &Cfg{}
// flags.ParseArgs(c, os.Args[1:])
// }
// type auth struct {
// Token string
// Tag float64
// }
//
// type credentials struct {
// User string
// Password string
// auth
// }
//
// type database struct {
// DBName string
// TableName string
// credentials
// }
//
// type Cfg struct {
// logging
// database
// }
//
// func main() {
// c := &Cfg{}
// flags.ParseArgs(c, os.Args[1:])
// }
//
// will create the following flags
// -dbname string
// dbname
// -interval int
// interval
// -password string
// password
// -path string
// path
// -tablename string
// tablename
// -tag float
// tag
// -token string
// token
// -user string
// user
//
// -dbname string
// dbname
// -interval int
// interval
// -password string
// password
// -path string
// path
// -tablename string
// tablename
// -tag float
// tag
// -token string
// token
// -user string
// user
//
// Please be aware that usual GoLang flag creation rules apply, i.e., if there are
// duplication in flag names (in the flattened case it's more likely to happen
// unless the caller make due dilligence to create the struct properly), it panics.
//
//
// Note that not all types can have command line flags created for. map, channel
// and function type will not defien a flag corresponding to the field. Pointer
// types are properly handled and slice type will create multi-value command
Expand Down
3 changes: 1 addition & 2 deletions internal/skiplist/skiplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func TestInt(t *testing.T) {
sl.Delete(Int(888))
sl.Delete(Int(1000))

expect = []Int{Int(-999), Int(-888), Int(1), Int(3), Int(999)}

if sl.Front().Value.(Int) != -999 {
t.Fatal()
}
Expand Down Expand Up @@ -283,6 +281,7 @@ func BenchmarkIntRankRandom(b *testing.B) {
}
}

// nolint:unused
func output(sl *SkipList) {
var x *Element
for i := 0; i < SKIPLIST_MAXLEVEL; i++ {
Expand Down
2 changes: 1 addition & 1 deletion server/api_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var (
invalidUsernameRegex = regexp.MustCompilePOSIX("([[:cntrl:]]|[[\t\n\r\f\v]])+")
invalidCharsRegex = regexp.MustCompilePOSIX("([[:cntrl:]]|[[:space:]])+")
emailRegex = regexp.MustCompile("^.+@.+\\..+$")
emailRegex = regexp.MustCompile(`^.+@.+\..+$`)
)

type SessionTokenClaims struct {
Expand Down
4 changes: 1 addition & 3 deletions server/api_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
continue
}
headers[k] = make([]string, 0, len(v))
for _, h := range v {
headers[k] = append(headers[k], h)
}
headers[k] = append(headers[k], v...)
}

// Execute the function.
Expand Down
4 changes: 2 additions & 2 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func CheckConfig(logger *zap.Logger, config Config) map[string]string {
logger.Warn("WARNING: deprecated configuration parameter", zap.String("deprecated", "runtime.registry_size"), zap.String("param", "runtime.lua_registry_size"))
configWarnings["runtime.registry_size"] = "Deprecated configuration parameter"
}
if config.GetRuntime().ReadOnlyGlobals != true {
if !config.GetRuntime().ReadOnlyGlobals {
logger.Warn("WARNING: deprecated configuration parameter", zap.String("deprecated", "runtime.read_only_globals"), zap.String("param", "runtime.lua_read_only_globals"))
configWarnings["runtime.read_only_globals"] = "Deprecated configuration parameter"
}
Expand Down Expand Up @@ -862,7 +862,7 @@ func (r *RuntimeConfig) GetLuaRegistrySize() int {

// Function to allow backwards compatibility for LuaReadOnlyGlobals config
func (r *RuntimeConfig) GetLuaReadOnlyGlobals() bool {
if r.ReadOnlyGlobals != true {
if !r.ReadOnlyGlobals {
return r.ReadOnlyGlobals
}
return r.LuaReadOnlyGlobals
Expand Down
5 changes: 2 additions & 3 deletions server/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ SELECT collection FROM t WHERE collection IS NOT NULL`
sort.Strings(collections)
collectionSetCache.Store(collections)

elapsed := time.Now().Sub(startAt)
elapsed := time.Since(startAt)
elapsed *= 20
if elapsed < time.Minute {
elapsed = time.Minute
Expand Down Expand Up @@ -410,8 +410,7 @@ func registerDashboardHandlers(logger *zap.Logger, router *mux.Router) {

w.Header().Add("Cache-Control", "no-cache")
w.Header().Set("X-Frame-Options", "deny")
w.Write(indexBytes)
return
_, _ = w.Write(indexBytes)
}

router.Path("/").HandlerFunc(indexFn)
Expand Down
2 changes: 1 addition & 1 deletion server/console_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *ConsoleServer) Authenticate(ctx context.Context, in *console.Authentica
return nil, status.Error(codes.ResourceExhausted, "Try again later.")
}

role := console.UserRole_USER_ROLE_UNKNOWN
var role console.UserRole
var uname string
var email string
var id uuid.UUID
Expand Down
2 changes: 1 addition & 1 deletion server/core_leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func LeaderboardRecordsList(ctx context.Context, logger *zap.Logger, db *sql.DB,
}
}

if ownerIds != nil && len(ownerIds) != 0 {
if len(ownerIds) != 0 {
params := make([]interface{}, 0, len(ownerIds)+2)
params = append(params, leaderboardId, time.Unix(expiryTime, 0).UTC())
statements := make([]string, len(ownerIds))
Expand Down
Loading
Loading