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

enable gocognit linter #1037

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Conversation

grishagavrin
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #938

What is the new behavior?

Other information

First I load the files with the linter turned off to check the ci tests.
I have the linter enabled locally and with the last commit I enabled the linter in the remote repository.

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2024

Codecov Report

Attention: 230 lines in your changes are missing coverage. Please review.

Comparison is base (c6e45cd) 68.48% compared to head (57a84ee) 68.72%.

Files Patch % Lines
internal/table/scanner/scanner.go 41.56% 87 Missing and 10 partials ⚠️
internal/decimal/decimal.go 0.00% 35 Missing ⚠️
log/table.go 83.65% 29 Missing and 5 partials ⚠️
sugar/path.go 43.24% 17 Missing and 4 partials ⚠️
log/sql.go 76.47% 8 Missing and 4 partials ⚠️
internal/xsql/dsn.go 66.66% 6 Missing and 2 partials ⚠️
retry/retry.go 27.27% 7 Missing and 1 partial ⚠️
internal/bind/params.go 80.00% 4 Missing and 2 partials ⚠️
internal/table/client.go 78.57% 2 Missing and 1 partial ⚠️
log/topic.go 97.18% 0 Missing and 2 partials ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1037      +/-   ##
==========================================
+ Coverage   68.48%   68.72%   +0.24%     
==========================================
  Files         252      252              
  Lines       25155    25420     +265     
==========================================
+ Hits        17228    17471     +243     
- Misses       7069     7093      +24     
+ Partials      858      856       -2     
Flag Coverage Δ
55.48% <60.96%> (+0.29%) ⬆️
go-1.20.x 68.57% <70.84%> (+0.30%) ⬆️
go-1.21.x 68.67% <70.84%> (+0.21%) ⬆️
integration 55.48% <60.96%> (+0.29%) ⬆️
macOS 38.34% <15.71%> (-0.32%) ⬇️
ubuntu 38.38% <15.71%> (-0.30%) ⬇️
unit 38.44% <15.71%> (-0.30%) ⬇️
windows 38.38% <15.71%> (-0.34%) ⬇️
ydb-22.5 55.00% <60.96%> (+0.17%) ⬆️
ydb-23.1 54.98% <59.31%> (+0.04%) ⬆️
ydb-23.2 55.16% <60.96%> (+0.34%) ⬆️
ydb-23.3 55.22% <59.31%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grishagavrin
Copy link
Contributor Author

grishagavrin commented Feb 10, 2024

I noted one comment //nolint:gocognit, because if I rewrite a function internal/cmd/gtrace.findGtraceGen in
for _, c := range v.List { if strings.Contains(strings.TrimPrefix(c.Text, "//"), "gtrace:gen") { if item == nil { item = &GenItem{} } } } the autotest breaks either tests / unit (1.21.x, windows)

@asmyasnikov asmyasnikov self-assigned this Feb 19, 2024
CHANGELOG.md Outdated
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 refactorings not valuable for users. Thats why no need to add lines to CHANGELOG

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 no need to change test files for enabling gocongnit linter - this is no valuable for doing better source code
Can you add all test files to exclude-rules in .golangci.yaml config?

@@ -171,6 +166,18 @@ func (c call) Record(opts ...recordOption) string {
return buffer.String()
}

// findFileNameAndPkgPath finds the file, name and package path from the given file path, name and package path.
func findFileNameAndPkgPath(file, name, pkgPath string) (string, string, string) {
Copy link
Member

Choose a reason for hiding this comment

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

need to unit test for newest func

Copy link
Member

Choose a reason for hiding this comment

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

need to unit tests for newest func

@@ -96,3 +77,30 @@ func extractTablePathPrefixFromBinderName(binderName string) (string, error) {

return ss[0][1], nil
}

// bindTablePathPrefixInConnectorOptions binds table path prefix query transformers to a list of ConnectorOptions.
func bindTablePathPrefixInConnectorOptions(queryTransformers []string) ([]ConnectorOption, error) {
Copy link
Member

Choose a reason for hiding this comment

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

queryTransformersToConnectorOptions?

@@ -96,3 +77,30 @@ func extractTablePathPrefixFromBinderName(binderName string) (string, error) {

return ss[0][1], nil
}

// bindTablePathPrefixInConnectorOptions binds table path prefix query transformers to a list of ConnectorOptions.
func bindTablePathPrefixInConnectorOptions(queryTransformers []string) ([]ConnectorOption, error) {
Copy link
Member

Choose a reason for hiding this comment

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

need to unit test for newest func

log/driver.go Outdated
Copy link
Member

@asmyasnikov asmyasnikov Mar 7, 2024

Choose a reason for hiding this comment

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

I think this file need to stay as is with nolint comment because your simple functions can be clashed in log package.
For example onInit func may clashed between driver log and table log and other

log/sql.go Outdated
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 file need to stay as is with nolint comment because your simple functions can be clashed in log package.
For example onInit func may clashed between driver log and table log and other

log/table.go Outdated
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 file need to stay as is with nolint comment because your simple functions can be clashed in log package.
For example onInit func may clashed between driver log and table log and other

log/topic.go Outdated
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 file need to stay as is with nolint comment because your simple functions can be clashed in log package.
For example onInit func may clashed between driver log and table log and other

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 file need to stay as is with nolint comment because your simple functions can be clashed in log package.
For example onInit func may clashed between driver log and table log and other

// with a panic recovery mechanism. If the `options.panicCallback` is specified, it
// is invoked with the recovered value, and an error is returned with the recovered value wrapped
// as the cause. This function returns the result of the `op` retry operation.
func RecoveryCallbackWrapper(context context.Context, op retryOperation, options *retryOptions) (err error) {
Copy link
Member

Choose a reason for hiding this comment

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

public func not welcome

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 file need to stay as is with nolint comment because findGtraceGen also commented with nolint word

@@ -237,3 +216,40 @@ func Params(args ...interface{}) (params []table.ParameterOption, _ error) {

return params, nil
}

// checkDriverNamedValue checks the driver.NamedValue and adds it to the params slice.
func checkDriverNamedValue(
Copy link
Member

Choose a reason for hiding this comment

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

Need to test for newest func

@@ -237,3 +216,40 @@ func Params(args ...interface{}) (params []table.ParameterOption, _ error) {

return params, nil
}

// checkDriverNamedValue checks the driver.NamedValue and adds it to the params slice.
func checkDriverNamedValue(
Copy link
Member

Choose a reason for hiding this comment

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

appendParams or tryAppendParams?

@@ -266,6 +241,57 @@ func Format(x *big.Int, precision, scale uint32) string {
return xstring.FromBytes(bts[pos:])
}

// dotStringAnalysis performs analysis on a string representation of a decimal number.
func dotStringAnalysis(
Copy link
Member

Choose a reason for hiding this comment

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

toBigInt or stringToBigInt?

@@ -266,6 +241,57 @@ func Format(x *big.Int, precision, scale uint32) string {
return xstring.FromBytes(bts[pos:])
}

// dotStringAnalysis performs analysis on a string representation of a decimal number.
func dotStringAnalysis(
Copy link
Member

Choose a reason for hiding this comment

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

need to add unit test for newest func

}

// multipliedByTen multiplies the given big.Int value by 10 raised to the power of scale.
func multipliedByTen(v *big.Int, scale uint32, neg bool) {
Copy link
Member

Choose a reason for hiding this comment

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

need to add unit test for newest func


if timeout := c.config.DeleteTimeout(); timeout > 0 {
var cancel context.CancelFunc
createSessionCtx, cancel = xcontext.WithTimeout(closeSessionCtx, timeout)
Copy link
Member

Choose a reason for hiding this comment

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

createSessionCtx is not used

Copy link
Member

Choose a reason for hiding this comment

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

May be a bug in base version of code

@@ -223,6 +209,25 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
}
}

// onCloseSession is a closure function that takes a session and performs the actions to close it.
func onCloseSession(ctx, createSessionCtx context.Context, c *Client) func(s *session) {
Copy link
Member

Choose a reason for hiding this comment

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

createSessionCtx and c are not used

@@ -223,6 +209,25 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
}
}

// onCloseSession is a closure function that takes a session and performs the actions to close it.
func onCloseSession(ctx, createSessionCtx context.Context, c *Client) func(s *session) {
Copy link
Member

@asmyasnikov asmyasnikov Mar 7, 2024

Choose a reason for hiding this comment

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

I think ctx need to move from source args to result
And your high-ordered func may looks like:

func closerWithTimeout(timeout time.Duration) func(ctx context.Context, closer closer.Closer) {
	return func(ctx context.Context, s *session) {
        	if closer == nil {
			return
		}

		ctx = xcontext.WithoutDeadline(ctx)
		var cancel context.CancelFunc
		if timeout > 0 {
			ctx, cancel = xcontext.WithTimeout(ctx, timeout)
		} else {
			ctx, cancel = xcontext.WithCancel(ctx)
		}
		defer cancel()
		_ = closer.Close(ctx)
	}
}

And this func can be tested with unit test

@asmyasnikov
Copy link
Member

Summary of review:

  1. Need to rebase to master
  2. Need to add exclude-rules into .golangci.yaml config for:
    • all tests
    • packages log and metrics
  3. Need to add unit tests for newest funcs
  4. Minor issues see in full review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants