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

enabled nonamedreturns linter #1033

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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 .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ linters:
- interfacebloat
- ireturn
- maintidx
- nonamedreturns
- paralleltest
- scopelint
- structcheck
Expand Down
5 changes: 3 additions & 2 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var (
}
)

func defaultGrpcOptions(t *trace.Driver, secure bool, tlsConfig *tls.Config) (opts []grpc.DialOption) {
func defaultGrpcOptions(t *trace.Driver, secure bool, tlsConfig *tls.Config) []grpc.DialOption {
opts := make([]grpc.DialOption, 0, 5) // capacity is 5 because later will be append 5 objects
opts = append(opts,
// keep-aliving all connections
grpc.WithKeepaliveParams(
Expand Down Expand Up @@ -84,7 +85,7 @@ func defaultTLSConfig() *tls.Config {
}
}

func defaultConfig() (c *Config) {
func defaultConfig() *Config {
return &Config{
credentials: credentials.NewAnonymousCredentials(
credentials.WithSourceInfo(stack.Record(0)),
Expand Down
4 changes: 2 additions & 2 deletions driver_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestDriver_String(t *testing.T) {
config.WithDatabase("local"),
config.WithSecure(false),
)},
s: `Driver{Endpoint:"localhost",Database:"local",Secure:false,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:90)"}}`, //nolint:lll
s: `Driver{Endpoint:"localhost",Database:"local",Secure:false,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:91)"}}`, //nolint:lll
},
{
name: xtest.CurrentFileLine(),
Expand All @@ -32,7 +32,7 @@ func TestDriver_String(t *testing.T) {
config.WithDatabase("local"),
config.WithSecure(true),
)},
s: `Driver{Endpoint:"localhost",Database:"local",Secure:true,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:90)"}}`, //nolint:lll
s: `Driver{Endpoint:"localhost",Database:"local",Secure:true,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:91)"}}`, //nolint:lll
},
{
name: xtest.CurrentFileLine(),
Expand Down
5 changes: 4 additions & 1 deletion examples/basic/database_sql/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func episodeData(seriesID, seasonID, episodeID, title string, date time.Time) ty
)
}

//nolint:nonamedreturns
func getData() (series, seasons, episodes []types.Value) {
for seriesID, fill := range map[string]func(seriesID string) (
seriesData types.Value, seasons []types.Value, episodes []types.Value,
Expand All @@ -61,9 +62,10 @@ func getData() (series, seasons, episodes []types.Value) {
episodes = append(episodes, episodesData...)
}

return
return series, seasons, episodes
}

//nolint:nonamedreturns
func getDataForITCrowd(seriesID string) (series types.Value, seasons, episodes []types.Value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this changes not required and harmful
Because if I call getDataForITCrowd - I want to know about each of three results.
Old variant helps to understand. New variant cannot helps

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I returned previous declaration.
I simple followed by linter's comment.

series = seriesData(
seriesID, date("2006-02-03"), "IT Crowd", ""+
Expand Down Expand Up @@ -120,6 +122,7 @@ func getDataForITCrowd(seriesID string) (series types.Value, seasons, episodes [
return series, seasons, episodes
}

//nolint:nonamedreturns
func getDataForSiliconValley(seriesID string) (series types.Value, seasons, episodes []types.Value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read previous comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I returned previous declaration.
I simple followed by linter's comment.

series = seriesData(
seriesID, date("2014-04-06"), "Silicon Valley", ""+
Expand Down
36 changes: 18 additions & 18 deletions examples/basic/database_sql/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

func selectDefault(ctx context.Context, db *sql.DB) (err error) {
func selectDefault(ctx context.Context, db *sql.DB) error {
// explain of query
err = retry.Do(ctx, db, func(ctx context.Context, cc *sql.Conn) (err error) {
err := retry.Do(ctx, db, func(ctx context.Context, cc *sql.Conn) error {
row := cc.QueryRowContext(ydb.WithQueryMode(ctx, ydb.ExplainQueryMode),
`SELECT series_id, title, release_date FROM series;`,
)
var (
ast string
plan string
)
if err = row.Scan(&ast, &plan); err != nil {
if err := row.Scan(&ast, &plan); err != nil {
return err
}
log.Printf("AST = %s\n\nPlan = %s", ast, plan)
Expand All @@ -39,10 +39,10 @@ func selectDefault(ctx context.Context, db *sql.DB) (err error) {
err = retry.Do(
ydb.WithTxControl(ctx, table.OnlineReadOnlyTxControl()),
db,
func(ctx context.Context, cc *sql.Conn) (err error) {
rows, err := cc.QueryContext(ctx, `SELECT series_id, title, release_date FROM series;`)
if err != nil {
return err
func(ctx context.Context, cc *sql.Conn) error {
rows, errIn := cc.QueryContext(ctx, `SELECT series_id, title, release_date FROM series;`)
if errIn != nil {
return errIn
}
defer func() {
_ = rows.Close()
Expand Down Expand Up @@ -72,12 +72,12 @@ func selectDefault(ctx context.Context, db *sql.DB) (err error) {
return nil
}

func selectScan(ctx context.Context, db *sql.DB) (err error) {
func selectScan(ctx context.Context, db *sql.DB) error {
// scan query
err = retry.Do(
err := retry.Do(
ydb.WithTxControl(ctx, table.StaleReadOnlyTxControl()),
db,
func(ctx context.Context, cc *sql.Conn) (err error) {
func(ctx context.Context, cc *sql.Conn) error {
var (
id string
seriesIDs []types.Value
Expand All @@ -92,11 +92,11 @@ func selectScan(ctx context.Context, db *sql.DB) (err error) {
table.ValueParam("$seriesTitle", types.TextValue("%IT Crowd%")),
),
)
if err = row.Scan(&id); err != nil {
if err := row.Scan(&id); err != nil {
return err
}
seriesIDs = append(seriesIDs, types.BytesValueFromString(id))
if err = row.Err(); err != nil {
if err := row.Err(); err != nil {
return err
}

Expand Down Expand Up @@ -167,15 +167,15 @@ func selectScan(ctx context.Context, db *sql.DB) (err error) {
return nil
}

func fillTablesWithData(ctx context.Context, db *sql.DB) (err error) {
func fillTablesWithData(ctx context.Context, db *sql.DB) error {
series, seasonsData, episodesData := getData()
args := []interface{}{
sql.Named("seriesData", types.ListValue(series...)),
sql.Named("seasonsData", types.ListValue(seasonsData...)),
sql.Named("episodesData", types.ListValue(episodesData...)),
}
err = retry.DoTx(ctx, db, func(ctx context.Context, tx *sql.Tx) error {
if _, err = tx.ExecContext(ctx, `
err := retry.DoTx(ctx, db, func(ctx context.Context, tx *sql.Tx) error {
if _, err := tx.ExecContext(ctx, `
REPLACE INTO series
SELECT
series_id,
Expand Down Expand Up @@ -216,9 +216,9 @@ func fillTablesWithData(ctx context.Context, db *sql.DB) (err error) {
return nil
}

func prepareSchema(ctx context.Context, db *sql.DB) (err error) {
err = retry.Do(ctx, db, func(ctx context.Context, cc *sql.Conn) error {
err = dropTableIfExists(ctx, cc, "series")
func prepareSchema(ctx context.Context, db *sql.DB) error {
err := retry.Do(ctx, db, func(ctx context.Context, cc *sql.Conn) error {
err := dropTableIfExists(ctx, cc, "series")
if err != nil {
_, _ = fmt.Fprintf(os.Stdout, "warn: drop series table failed: %v\n", err)
}
Expand Down
12 changes: 6 additions & 6 deletions examples/basic/gorm/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Series struct {
Seasons []Season
}

func (s *Series) BeforeCreate(_ *gorm.DB) (err error) {
func (s *Series) BeforeCreate(_ *gorm.DB) error {
id, err := uuid.NewUUID()
if err != nil {
return err
Expand All @@ -27,7 +27,7 @@ func (s *Series) BeforeCreate(_ *gorm.DB) (err error) {
s.Seasons[i].SeriesID = s.ID
}

return
return err
}

type Season struct {
Expand All @@ -40,7 +40,7 @@ type Season struct {
Episodes []Episode
}

func (s *Season) BeforeCreate(_ *gorm.DB) (err error) {
func (s *Season) BeforeCreate(_ *gorm.DB) error {
id, err := uuid.NewUUID()
if err != nil {
return err
Expand All @@ -50,7 +50,7 @@ func (s *Season) BeforeCreate(_ *gorm.DB) (err error) {
s.Episodes[i].SeasonID = s.ID
}

return
return err
}

type Episode struct {
Expand All @@ -60,12 +60,12 @@ type Episode struct {
AirDate time.Time `gorm:"column:air_date"`
}

func (e *Episode) BeforeCreate(_ *gorm.DB) (err error) {
func (e *Episode) BeforeCreate(_ *gorm.DB) error {
id, err := uuid.NewUUID()
if err != nil {
return err
}
e.ID = id.String()

return
return err
}
56 changes: 30 additions & 26 deletions examples/basic/native/query/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,19 @@ SELECT
FROM AS_TABLE($episodesData);
`))

func readTable(ctx context.Context, c table.Client, path string) (err error) {
func readTable(ctx context.Context, c table.Client, path string) error {
var res result.StreamResult
err = c.Do(ctx,
func(ctx context.Context, s table.Session) (err error) {
res, err = s.StreamReadTable(ctx, path,
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
var errIn error
res, errIn = s.StreamReadTable(ctx, path,
options.ReadOrdered(),
options.ReadColumn("series_id"),
options.ReadColumn("title"),
options.ReadColumn("release_date"),
)

return
return errIn
},
)
if err != nil {
Expand Down Expand Up @@ -138,13 +139,14 @@ func readTable(ctx context.Context, c table.Client, path string) (err error) {
return res.Err()
}

func describeTableOptions(ctx context.Context, c table.Client) (err error) {
func describeTableOptions(ctx context.Context, c table.Client) error {
var desc options.TableOptionsDescription
err = c.Do(ctx,
func(ctx context.Context, s table.Session) (err error) {
desc, err = s.DescribeTableOptions(ctx)
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
var errIn error
desc, errIn = s.DescribeTableOptions(ctx)

return
return errIn
},
)
if err != nil {
Expand Down Expand Up @@ -191,7 +193,7 @@ func describeTableOptions(ctx context.Context, c table.Client) (err error) {
return nil
}

func selectSimple(ctx context.Context, c table.Client, prefix string) (err error) {
func selectSimple(ctx context.Context, c table.Client, prefix string) error {
query := render(
template.Must(template.New("").Parse(`
PRAGMA TablePathPrefix("{{ .TablePathPrefix }}");
Expand Down Expand Up @@ -221,16 +223,17 @@ func selectSimple(ctx context.Context, c table.Client, prefix string) (err error
table.CommitTx(),
)
var res result.Result
err = c.Do(ctx,
func(ctx context.Context, s table.Session) (err error) {
_, res, err = s.Execute(ctx, readTx, query,
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
var errIn error
_, res, errIn = s.Execute(ctx, readTx, query,
table.NewQueryParameters(
table.ValueParam("$seriesID", types.Uint64Value(1)),
),
options.WithCollectStatsModeBasic(),
)

return
return errIn
},
)
if err != nil {
Expand Down Expand Up @@ -266,7 +269,7 @@ func selectSimple(ctx context.Context, c table.Client, prefix string) (err error
return res.Err()
}

func scanQuerySelect(ctx context.Context, c table.Client, prefix string) (err error) {
func scanQuerySelect(ctx context.Context, c table.Client, prefix string) error {
query := render(
template.Must(template.New("").Parse(`
PRAGMA TablePathPrefix("{{ .TablePathPrefix }}");
Expand Down Expand Up @@ -327,32 +330,33 @@ func scanQuerySelect(ctx context.Context, c table.Client, prefix string) (err er
)
}

func fillTablesWithData(ctx context.Context, c table.Client, prefix string) (err error) {
func fillTablesWithData(ctx context.Context, c table.Client, prefix string) error {
writeTx := table.TxControl(
table.BeginTx(
table.WithSerializableReadWrite(),
),
table.CommitTx(),
)
err = c.Do(ctx,
func(ctx context.Context, s table.Session) (err error) {
_, _, err = s.Execute(ctx, writeTx, render(fill, templateConfig{
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
var errIn error
_, _, errIn = s.Execute(ctx, writeTx, render(fill, templateConfig{
TablePathPrefix: prefix,
}), table.NewQueryParameters(
table.ValueParam("$seriesData", getSeriesData()),
table.ValueParam("$seasonsData", getSeasonsData()),
table.ValueParam("$episodesData", getEpisodesData()),
))

return err
return errIn
},
)

return err
}

func createTables(ctx context.Context, c table.Client, prefix string) (err error) {
err = c.Do(ctx,
func createTables(ctx context.Context, c table.Client, prefix string) error {
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
return s.CreateTable(ctx, path.Join(prefix, "series"),
options.WithColumn("series_id", types.Optional(types.TypeUint64)),
Expand Down Expand Up @@ -403,8 +407,8 @@ func createTables(ctx context.Context, c table.Client, prefix string) (err error
return nil
}

func describeTable(ctx context.Context, c table.Client, path string) (err error) {
err = c.Do(ctx,
func describeTable(ctx context.Context, c table.Client, path string) error {
err := c.Do(ctx,
func(ctx context.Context, s table.Session) error {
desc, err := s.DescribeTable(ctx, path)
if err != nil {
Expand All @@ -419,7 +423,7 @@ func describeTable(ctx context.Context, c table.Client, path string) (err error)
},
)

return
return err
}

func render(t *template.Template, data interface{}) string {
Expand Down
Loading
Loading