Skip to content

Commit

Permalink
style: update and fix some code style error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 4, 2023
1 parent 5e9d147 commit fffbd5c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ readme:
readme-c: ## Generate or update README file and commit change to git
readme-c: readme
git add README.* internal
git commit -m "doc: update and re-generate README docs"
git commit -m ":memo: doc: update and re-generate README docs"

csfix: ## Fix code style for all files by go fmt
csfix:
Expand Down
4 changes: 2 additions & 2 deletions cflag/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RepeatableFlag interface {

// IntValue int, allow limit min and max value TODO
type IntValue struct {
val string
val string //lint:ignore U1000 is TODO
// validate
Min, Max int
}
Expand All @@ -36,7 +36,7 @@ type IntValue struct {
//
// Implemented the flag.Value interface
type IntsString struct {
val string // input
val string //nolint:unused
ints []int
// value and size validate
ValueFn func(val int) error
Expand Down
5 changes: 1 addition & 4 deletions fsutil/finder/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ func RegexMatch(pattern string) MatcherFunc {
reg := regexp.MustCompile(pattern)

return func(el Elem) bool {
if reg.MatchString(el.Name()) {
return true
}
return false
return reg.MatchString(el.Name())
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/gendoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type genOptsSt struct {
tplDir string
}

//lint:ignore U1000 for test
func (o genOptsSt) filePattern() string {
baseDir := genOpts.baseDir
if baseDir == "/" || baseDir == "./" {
Expand Down
8 changes: 6 additions & 2 deletions reflects/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestIsEmpty(t *testing.T) {
is.True(reflects.IsEmpty(reflect.ValueOf(uint(0))))
is.True(reflects.IsEmpty(reflect.ValueOf(float32(0))))

type T struct{ v any }
type T struct {
v any //lint:ignore U1000 for test
}
rv := reflect.ValueOf(T{}).Field(0)
is.True(reflects.IsEmpty(rv))
}
Expand All @@ -63,7 +65,9 @@ func TestIsEmptyValue(t *testing.T) {
is.True(reflects.IsEmptyValue(reflect.ValueOf(uint(0))))
is.True(reflects.IsEmptyValue(reflect.ValueOf(float32(0))))

type T struct{ v any }
type T struct {
v any //lint:ignore U1000 for test
}
rv := reflect.ValueOf(T{}).Field(0)
is.True(reflects.IsEmptyValue(rv))
}
Expand Down
6 changes: 3 additions & 3 deletions stdutil/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func TestIsNil(t *testing.T) {
is := assert.New(t)

is.True(stdutil.IsNil(nil))
}

Expand All @@ -23,7 +22,6 @@ func TestIsEmpty(t *testing.T) {

func TestIsFunc(t *testing.T) {
is := assert.New(t)

is.False(stdutil.IsFunc(nil))
}

Expand Down Expand Up @@ -57,7 +55,9 @@ func TestValueIsEmpty(t *testing.T) {
is.True(stdutil.ValueIsEmpty(reflect.ValueOf(nil)))
is.True(stdutil.ValueIsEmpty(reflect.ValueOf("")))

type T struct{ v any }
type T struct {
v any //lint:ignore U1000 for test
}
rv := reflect.ValueOf(T{}).Field(0)
is.True(stdutil.ValueIsEmpty(rv))
}
Expand Down
7 changes: 7 additions & 0 deletions structs/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestInitDefaults(t *testing.T) {
assert.NoErr(t, err)
assert.Eq(t, "inhere", u.Name)
assert.Eq(t, 0, u.Age)
assert.Eq(t, "", u.city)
// dump.P(u)

type User1 struct {
Expand Down Expand Up @@ -116,6 +117,12 @@ func TestInitDefaults_nestStruct(t *testing.T) {
assert.Eq(t, 30, u.Age)
assert.Eq(t, "chengdu", u.Extra.City)
assert.Eq(t, "https://github.com/inhere", u.Extra.Github)

u = &User{Extra: ExtraDefault{Github: "some url"}}
err = structs.InitDefaults(u)
dump.P(u)
assert.NoErr(t, err)
assert.Eq(t, "chengdu", u.Extra.City)
}

func TestInitDefaults_ptrStructField(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions structs/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ExampleTagParser_Parse() {
type User struct {
Age int `json:"age" yaml:"age" default:"23"`
Name string `json:"name,omitempty" yaml:"name" default:"inhere"`
inner string
inner string //lint:ignore U1000 for test
}

u := &User{}
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestParseTags(t *testing.T) {
type user struct {
Age int `json:"age" default:"23"`
Name string `json:"name" default:"inhere"`
inner string
inner string //lint:ignore U1000 unused
}

tags, err := structs.ParseTags(user{}, []string{"json", "default"})
Expand All @@ -123,7 +123,7 @@ func TestParseReflectTags(t *testing.T) {
type user struct {
Age int `json:"age" default:"23"`
Name string `json:"name" default:"inhere"`
inner string
inner string //lint:ignore U1000 unused
}

rt := reflect.TypeOf(user{})
Expand Down
12 changes: 3 additions & 9 deletions strutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,8 @@ func PathMatch(pattern, s string) bool {
// Difference with PathMatch() is: `*` can match any char, contain `/`.
func GlobMatch(pattern, s string) bool {
// replace `/` to `S` for path.Match
if strings.Contains(pattern, "/") {
pattern = strings.Replace(pattern, "/", "S", -1)
}
if strings.Contains(s, "/") {
s = strings.Replace(s, "/", "S", -1)
}
pattern = strings.Replace(pattern, "/", "S", -1)
s = strings.Replace(s, "/", "S", -1)

ok, err := path.Match(pattern, s)
if err != nil {
Expand Down Expand Up @@ -322,9 +318,7 @@ func MatchNodePath(pattern, s string, sep string) bool {
}

pattern = strings.Replace(pattern, sep, "/", -1)
if strings.Contains(s, sep) {
s = strings.Replace(s, sep, "/", -1)
}
s = strings.Replace(s, sep, "/", -1)

ok, err := path.Match(pattern, s)
if err != nil {
Expand Down

0 comments on commit fffbd5c

Please sign in to comment.