8000 deepsource: fix some simple by molon · Pull Request #555 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

deepsource: fix some simple #555

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

Merged
merged 2 commits into from
Sep 4, 2024
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
1 change: 0 additions & 1 deletion autocomplete/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,4 @@ func (b *ModelBuilder) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(jsonResponse)
return
}
6 changes: 3 additions & 3 deletions media/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (b *Base) Scan(data interface{}) (err error) {
}
}
case []byte:
if string(values) != "" {
if len(values) != 0 {
if err = json.Unmarshal(values, b); err == nil {
var options struct {
Crop bool
Expand Down Expand Up @@ -175,10 +175,10 @@ func (b Base) GetURLTemplate(option *Option) (path string) {
return
}

var urlReplacer = regexp.MustCompile("(\\s|\\+)+")
var urlReplacer = regexp.MustCompile(`(\s|\+)+`)

func getFuncMap(db *gorm.DB, field *schema.Field, filename string) template.FuncMap {
hash := func() string { return strings.Replace(time.Now().Format("20060102150405.000000"), ".", "", -1) }
hash := func() string { return strings.ReplaceAll(time.Now().Format("20060102150405.000000"), ".", "") }
shortHash := func() string { return time.Now().Format("20060102150405") }

return template.FuncMap{
Expand Down
3 changes: 1 addition & 2 deletions media/filechooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ func mediaLibraryContent(mb *Builder, field string, ctx *web.EventContext,
clickTabEvent += ";" + web.Plaid().PushState(true).MergeQuery(true).ClearMergeQuery([]string{ParamParentID}).Query(paramTab, web.Var("$event")).RunPushState()
}
for _, f := range files {
var fileComp h.HTMLComponent
fileComp = fileOrFolderComponent(mb, field, tab, ctx, f, msgr, cfg, initCroppingVars, inMediaLibrary)
fileComp := fileOrFolderComponent(mb, field, tab, ctx, f, msgr, cfg, initCroppingVars, inMediaLibrary)
col := VCol(fileComp).Attr("style", "flex: 0 0 calc(100% / 5); max-width: calc(100% / 5);")
if !f.Folder {
hasFiles = true
Expand Down
10 changes: 6 additions & 4 deletions media/media_library/media_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
Description string
}

func (mediaLibraryStorage MediaLibraryStorage) GetSizes() map[string]*base.Size {
func (mediaLibraryStorage *MediaLibraryStorage) GetSizes() map[string]*base.Size {
if len(mediaLibraryStorage.Sizes) == 0 && !(mediaLibraryStorage.GetFileHeader() != nil || mediaLibraryStorage.Crop) {
return map[string]*base.Size{}
}
Expand Down Expand Up @@ -112,7 +112,7 @@
// cropOptions := mediaLibraryStorage.CropOptions
sizeOptions := mediaLibraryStorage.Sizes

if string(values) != "" {
if len(values) != 0 {
mediaLibraryStorage.Base.Scan(values)
if err = json.Unmarshal(values, mediaLibraryStorage); err == nil {
if mediaLibraryStorage.CropOptions == nil {
Expand Down Expand Up @@ -147,7 +147,9 @@
}
}
case string:
err = mediaLibraryStorage.Scan([]byte(values))
if err = mediaLibraryStorage.Scan([]byte(values)); err != nil {
return err

Check warning on line 151 in media/media_library/media_library.go

View check run for this annotation

Codecov / codecov/patch

media/media_library/media_library.go#L151

Added line #L151 was not covered by tests
}
case []string:
for _, str := range values {
if err = mediaLibraryStorage.Scan(str); err != nil {
Expand All @@ -165,7 +167,7 @@
return string(results), err
}

func (mediaLibraryStorage MediaLibraryStorage) URL(styles ...string) string {
func (mediaLibraryStorage *MediaLibraryStorage) URL(styles ...string) string {
if mediaLibraryStorage.Url != "" && len(styles) > 0 {
ext := path.Ext(mediaLibraryStorage.Url)
return fmt.Sprintf("%v.%v%v", strings.TrimSuffix(mediaLibraryStorage.Url, ext), styles[0], ext)
Expand Down
6 changes: 3 additions & 3 deletions presets/integration/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestExample(t *testing.T) {
},
EventResponseMatch: func(t *testing.T, er *TestEventResponse) {
partial := er.UpdatePortals[0].Body
if strings.Index(partial, `v-model='form["Number"]' v-assign='[form, {"Number":""}]'`) < 0 {
if !strings.Contains(partial, `v-model='form["Number"]' v-assign='[form, {"Number":""}]'`) {
t.Error(`v-model='form["Number"]' v-assign='[form, {"Number":""}]'`, partial)
}
return
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestExample(t *testing.T) {
},
EventResponseMatch: func(t *testing.T, er *TestEventResponse) {
partial := er.UpdatePortals[0].Body
if strings.Index(partial, `v-model='form["OwnerName"]' v-assign='[form, {"OwnerName":""}]'`) < 0 {
if !strings.Contains(partial, `v-model='form["OwnerName"]' v-assign='[form, {"OwnerName":""}]'`) {
t.Error(`can't find v-model='form["OwnerName"]' v-assign='[form, {"OwnerName":""}]'`, partial)
}
return
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestExample(t *testing.T) {
},
EventResponseMatch: func(t *testing.T, er *TestEventResponse) {
partial := er.UpdatePortals[0].Body
if strings.Index(partial, `v-model='form["Agree"]' v-assign='[form, {"Agree":""}]'`) < 0 {
if !strings.Contains(partial, `v-model='form["Agree"]' v-assign='[form, {"Agree":""}]'`) {
t.Error(`can't find v-model='form["Agree"]' v-assign='[form, {"Agree":""}]'`, partial)
}
return
Expand Down
2 changes: 1 addition & 1 deletion utils/testflow/gentool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gobuffalo/flect v1.0.2
github.com/pkg/errors v0.9.1
github.com/qor5/admin/v3 v3.0.1-0.20240424102851-d75759576158
github.com/qor5/web/v3 v3.0.7-0.20240823021609-53fc3c71f073
github.com/qor5/web/v3 v3.0.7
github.com/sergi/go-diff v1.3.1
mvdan.cc/gofumpt v0.6.0
)
Expand Down
7 changes: 2 additions & 5 deletions utils/testflow/gentool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qor5/web/v3 v3.0.6 h1:9OjFl/5czP2adC5b6YR/ybLJjHBJjaC1k0zJs0l31gc=
github.com/qor5/web/v3 v3.0.6/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/web/v3 v3.0.7-0.20240820073152-c8eaf32af2a1/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/web/v3 v3.0.7-0.20240821051857-359165e78fdf/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/web/v3 v3.0.7-0.20240823021609-53fc3c71f073/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/web/v3 v3.0.7 h1:1+Ezbl+1m9oZ4S1kcFKybyi6at6qxoY7eJqjb3JETQQ=
github.com/qor5/web/v3 v3.0.7/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
Expand Down
4 changes: 2 additions & 2 deletions utils/testflow/gentool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func run(sampleFile, patchFile, backupDir, outputFile string) (xerr error) {
flowName = flect.Pascalize(flowName)

// Generate steps for each request-response pair
steps := []*Step{}
var steps []*Step
for i, rr := range rrs {
v, err := generateStep(rr)
if err != nil {
Expand Down Expand Up @@ -116,7 +116,7 @@ func run(sampleFile, patchFile, backupDir, outputFile string) (xerr error) {
diffs := dmp.DiffMain(string(original), string(edited), false)
patches := dmp.PatchMake(string(original), diffs)
pacthed, bs := dmp.PatchApply(patches, output)
patcherrs := []string{}
var patcherrs []string
for idx, b := range bs {
if !b {
patcherrs = append(patcherrs, fmt.Sprintf("patch failed: %s", patches[idx].String()))
Expand Down
12 changes: 7 additions & 5 deletions utils/testflow/gentool/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func generateLines(body string) ([]string, error) {
return nil, errors.Wrapf(err, "UnmarshalResponseBody: %s", body)
}

lines := []string{}
var lines []string

assertions := generateAssertions("resp", resp, func(prefix string) bool {
return assertIgnoreRegexp.MatchString(prefix)
Expand All @@ -162,7 +162,7 @@ func generateLines(body string) ([]string, error) {
}

b := []byte(body)
vlines := []string{}
var vlines []string
for _, validator := range validators {
params, err := validator.ParseParams(b)
if err != nil {
Expand All @@ -188,9 +188,11 @@ func generateLines(body string) ([]string, error) {
vlines = append(vlines, fmt.Sprintf("%s(%s)", validator.Name, strings.Join(callParams, ",")))
}
if len(vlines) > 0 {
lines = append(lines, `testflow.Validate(t, w, r,`)
lines = append(lines, strings.Join(vlines, ",\n")+",")
lines = append(lines, ")")
lines = append(lines,
`testflow.Validate(t, w, r,`,
strings.Join(vlines, ",\n")+",",
")",
)
}

return lines, nil
Expand Down
Loading
0