Skip to content

Commit

Permalink
refactor: ♻️ address several minor potential lint errors (#48)
Browse files Browse the repository at this point in the history
* refactor: ♻️ address several minor potential lit errors

* disable MD013 for code
  • Loading branch information
zoido authored Dec 10, 2023
1 parent a2ec721 commit 6f217e9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

## Example

<!-- markdownlint-disable MD010 -->
<!-- markdownlint-disable MD010 MD013 -->

```go
type config struct {
Expand Down Expand Up @@ -47,22 +47,20 @@ _ = os.Setenv("MY_DURATION_VALUE", "1h")

err := y.Parse(args)
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Printf("config.Str: %v\n", cfg.Str)
fmt.Printf("config.Int: %v\n", cfg.Int)
fmt.Printf("config.Bool %v\n", cfg.Bool)
fmt.Printf("config.Duration: %v\n", cfg.Duration)
fmt.Printf("config.Str: %v, ", cfg.Str)
fmt.Printf("config.Int: %v, ", cfg.Int)
fmt.Printf("config.Bool: %v, ", cfg.Bool)
fmt.Printf("config.Duration: %v", cfg.Duration)

// Output:
// config.Str: str flag value
// config.Int: 4
// config.Bool: false
// config.Duration: 1h0m0s
// config.Str: str flag value, config.Int: 4, config.Bool: false, config.Duration: 1h0m0s
```

<!-- markdownlint-enable MD010 -->
<!-- markdownlint-enable MD010 MD013 -->

## Supported types

Expand Down
18 changes: 7 additions & 11 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ func Example() {

err := y.Parse(args)
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Printf("config.Str: %v\n", cfg.Str)
fmt.Printf("config.Int: %v\n", cfg.Int)
fmt.Printf("config.Bool %v\n", cfg.Bool)
fmt.Printf("config.Duration: %v\n", cfg.Duration)
fmt.Printf("config.Str: %v, ", cfg.Str)
fmt.Printf("config.Int: %v, ", cfg.Int)
fmt.Printf("config.Bool: %v, ", cfg.Bool)
fmt.Printf("config.Duration: %v", cfg.Duration)

// Output:
// config.Str: str flag value
// config.Int: 4
// config.Bool: false
// config.Duration: 1h0m0s

//
// config.Str: str flag value, config.Int: 4, config.Bool: false, config.Duration: 1h0m0s
}
15 changes: 10 additions & 5 deletions options_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func ExampleWithEnvPrefix() {

err := y.Parse([]string{})
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Printf(cfg.Foo)
Expand All @@ -49,7 +50,8 @@ func ExampleFromEnv() {

err := y.Parse([]string{})
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Printf(cfg.Foo)
Expand Down Expand Up @@ -90,7 +92,8 @@ func ExampleRequired_flagOk() {

err := y.Parse([]string{"-foo=foo_value"})
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Print(cfg.Foo)
Expand All @@ -114,7 +117,8 @@ func ExampleRequired_envOnlyOk() {

err := y.Parse([]string{})
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Print(cfg.Foo)
Expand Down Expand Up @@ -158,7 +162,8 @@ func ExampleNoEnv() {
_ = os.Setenv("FOO", "Foo from the environment variable ")
err := y.Parse([]string{})
if err != nil {
os.Exit(2)
fmt.Printf("Error: %v\n", err)
return
}

fmt.Printf(cfg.Foo)
Expand Down
2 changes: 1 addition & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/zoido/yag-config"
)

func TestNew_Ok(t *testing.T) {
func TestNew_Ok(_ *testing.T) {
// When
yag.New()

Expand Down
4 changes: 2 additions & 2 deletions parser_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ type testFlagValue struct {
called bool
}

func (tfv *testFlagValue) Set(val string) error {
func (tfv *testFlagValue) Set(_ string) error {
tfv.called = true
return nil
}

func (tfv *testFlagValue) String() string {
func (*testFlagValue) String() string {
return "test_flag_value"
}

Expand Down
2 changes: 1 addition & 1 deletion value/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Bool(dest *bool) flag.Value {
// IsBoolFlag returns true if the flag.Value implementation has an IsBoolFlag() bool
// method returning true.
// This is used by the flag package commandline-parser for flags that can be supplied
// without "=value" text
// without "=value" text.
func IsBoolFlag(v flag.Value) bool {
type boolFlag interface {
flag.Value
Expand Down
2 changes: 1 addition & 1 deletion value/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestIsBooleanFlag_BoolFlagTrue(t *testing.T) {

type normalFlagValue struct{}

func (*normalFlagValue) Set(v string) error {
func (*normalFlagValue) Set(_ string) error {
return nil
}

Expand Down

0 comments on commit 6f217e9

Please sign in to comment.