fix: implement various deepsource suggestions

This commit is contained in:
Vikram Rangnekar
2020-06-15 10:16:47 -04:00
parent 06214a3850
commit dd4accfdd2
26 changed files with 76 additions and 86 deletions

View File

@ -155,7 +155,7 @@ func cmdVersion(cmd *cobra.Command, args []string) {
}
func BuildDetails() string {
if len(version) == 0 {
if version == "" {
return `
Super Graph (unknown version)
For documentation, visit https://supergraph.dev

View File

@ -80,7 +80,7 @@ func cmdDBSeed(cmd *cobra.Command, args []string) {
func graphQLFunc(sg *core.SuperGraph, query string, data interface{}, opt map[string]string) map[string]interface{} {
ct := context.Background()
if v, ok := opt["user_id"]; ok && len(v) != 0 {
if v, ok := opt["user_id"]; ok && v != "" {
ct = context.WithValue(ct, core.UserIDKey, v)
}
@ -144,7 +144,7 @@ func (c *csvSource) Values() ([]interface{}, error) {
for _, v := range c.rows[c.i] {
switch {
case len(v) == 0:
case v == "":
vals = append(vals, "")
case isDigit(v):
var n int
@ -243,7 +243,7 @@ func avatarURL(size int) string {
return fmt.Sprintf("https://i.pravatar.cc/%d?%d", size, rand.Intn(5000))
}
func imageURL(width int, height int) string {
func imageURL(width, height int) string {
return fmt.Sprintf("https://picsum.photos/%d/%d?%d", width, height, rand.Intn(5000))
}

View File

@ -90,7 +90,7 @@ func newViper(configPath, configFile string) *viper.Viper {
}
func GetConfigName() string {
if len(os.Getenv("GO_ENV")) == 0 {
if os.Getenv("GO_ENV") == "" {
return "dev"
}

View File

@ -105,7 +105,7 @@ func apiV1(w http.ResponseWriter, r *http.Request) {
}
if err == nil {
if len(conf.CacheControl) != 0 && res.Operation() == core.OpQuery {
if conf.CacheControl != "" && res.Operation() == core.OpQuery {
w.Header().Set("Cache-Control", conf.CacheControl)
}
//nolint: errcheck

View File

@ -47,17 +47,17 @@ func SimpleHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
ctx := r.Context()
userIDProvider := r.Header.Get("X-User-ID-Provider")
if len(userIDProvider) != 0 {
if userIDProvider != "" {
ctx = context.WithValue(ctx, core.UserIDProviderKey, userIDProvider)
}
userID := r.Header.Get("X-User-ID")
if len(userID) != 0 {
if userID != "" {
ctx = context.WithValue(ctx, core.UserIDKey, userID)
}
userRole := r.Header.Get("X-User-Role")
if len(userRole) != 0 {
if userRole != "" {
ctx = context.WithValue(ctx, core.UserRoleKey, userRole)
}
@ -68,11 +68,11 @@ func SimpleHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
func HeaderHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
hdr := ac.Header
if len(hdr.Name) == 0 {
if hdr.Name == "" {
return nil, fmt.Errorf("auth '%s': no header.name defined", ac.Name)
}
if !hdr.Exists && len(hdr.Value) == 0 {
if !hdr.Exists && hdr.Value == "" {
return nil, fmt.Errorf("auth '%s': no header.value defined", ac.Name)
}
@ -82,7 +82,7 @@ func HeaderHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
switch {
case hdr.Exists:
fo1 = (len(value) == 0)
fo1 = (value == "")
default:
fo1 = (value != hdr.Value)

View File

@ -44,10 +44,10 @@ func JwtHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
publicKeyFile := ac.JWT.PubKeyFile
switch {
case len(secret) != 0:
case secret != "":
key = []byte(secret)
case len(publicKeyFile) != 0:
case publicKeyFile != "":
kd, err := ioutil.ReadFile(publicKeyFile)
if err != nil {
return nil, err
@ -74,7 +74,7 @@ func JwtHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
var tok string
if len(cookie) != 0 {
if cookie != "" {
ck, err := r.Cookie(cookie)
if err != nil {
next.ServeHTTP(w, r)

View File

@ -165,7 +165,7 @@ func railsAuth(ac *Auth) (*rails.Auth, error) {
}
version := ac.Rails.Version
if len(version) == 0 {
if version == "" {
return nil, errors.New("no auth.rails.version defined")
}

View File

@ -199,7 +199,7 @@ func (m *Migrator) LoadMigrations(path string) error {
for _, v := range strings.Split(upSQL, "\n") {
// Only account for regular single line comment, empty line and space/comment combination
cleanString := strings.TrimSpace(v)
if len(cleanString) != 0 &&
if cleanString != "" &&
!strings.HasPrefix(cleanString, "--") {
containsSQL = true
break

View File

@ -27,7 +27,7 @@ func initWatcher() {
}
var d dir
if len(cpath) == 0 || cpath == "./" {
if cpath == "" || cpath == "./" {
d = Dir("./config", ReExec)
} else {
d = Dir(cpath, ReExec)
@ -52,11 +52,11 @@ func startHTTP() {
hp := strings.SplitN(conf.HostPort, ":", 2)
if len(hp) == 2 {
if len(conf.Host) != 0 {
if conf.Host != "" {
hp[0] = conf.Host
}
if len(conf.Port) != 0 {
if conf.Port != "" {
hp[1] = conf.Port
}
@ -64,7 +64,7 @@ func startHTTP() {
}
}
if len(conf.hostPort) == 0 {
if conf.hostPort == "" {
conf.hostPort = defaultHP
}
@ -123,7 +123,7 @@ func routeHandler() (http.Handler, error) {
return mux, nil
}
if len(conf.APIPath) != 0 {
if conf.APIPath != "" {
apiRoute = path.Join("/", conf.APIPath, "/v1/graphql")
}