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

PMM-7 enable gocritic linter rule #2281

Merged
merged 4 commits into from
Jun 21, 2023
Merged

Conversation

ademidoff
Copy link
Member

PMM-7

Ref: #1541

This PR:

  • enables the rule
  • fixes some warnings
  • disables some others

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #2281 (e1bd3ae) into main (53b4aaa) will increase coverage by 0.00%.
The diff coverage is 75.00%.

@@           Coverage Diff           @@
##             main    #2281   +/-   ##
=======================================
  Coverage   42.94%   42.95%           
=======================================
  Files         386      386           
  Lines       47994    47976   -18     
=======================================
- Hits        20611    20607    -4     
+ Misses      25455    25447    -8     
+ Partials     1928     1922    -6     
Flag Coverage Δ
admin 10.39% <ø> (ø)
agent 52.68% <75.00%> (+0.01%) ⬆️
vmproxy 69.69% <ø> (ø)

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

Impacted Files Coverage Δ
agent/client/client.go 42.67% <0.00%> (ø)
managed/services/dbaas/kubernetes/client/client.go 3.62% <ø> (+0.01%) ⬆️
managed/services/dbaas/kubernetes/kubernetes.go 10.37% <ø> (-0.15%) ⬇️
managed/services/management/alerting/service.go 29.22% <ø> (-0.22%) ⬇️
...aged/services/management/backup/backups_service.go 54.09% <ø> (-0.07%) ⬇️
...ged/services/management/dbaas/dbaas_initializer.go 0.00% <ø> (ø)
...ged/services/management/dbaas/kubernetes_server.go 64.40% <ø> (ø)
managed/services/management/ia/common.go 27.92% <ø> (+0.49%) ⬆️
managed/services/telemetry/uievents/uievents.go 0.00% <ø> (ø)
agent/agents/process/process_logger.go 80.48% <50.00%> (+0.96%) ⬆️
... and 3 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -201,7 +201,7 @@ func parseKeyValueFromComment(s string) (map[string]bool, error) {
func prepareMultilineRegexp() error {
// to compile regexp only once
multilineOnce.Do(func() {
multilineRegexp, errMultiline = regexp.Compile(`(?s)\/\*(.*?)\*\/`)
multilineRegexp, errMultiline = regexp.Compile(`(?s)\/\*(.*?)\*\/`) //nolint:gocritic
Copy link
Member Author

Choose a reason for hiding this comment

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

@JiriCtvrtka I believe we can use regexp.MustCompile everywhere in this file and simplify the code.

Copy link
Member

Choose a reason for hiding this comment

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

and by using MustCompile we can migrate the initialization of regexps to the top of the file

@ademidoff ademidoff changed the title PMM-7 enable the rule PMM-7 enable gocritic linter rule Jun 16, 2023
@ademidoff ademidoff marked this pull request as ready for review June 19, 2023 11:16
@ademidoff ademidoff requested review from idoqo and artemgavrilov and removed request for a team June 19, 2023 11:16
Copy link
Member

@BupycHuk BupycHuk left a comment

Choose a reason for hiding this comment

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

Great job!

@@ -201,7 +201,7 @@ func parseKeyValueFromComment(s string) (map[string]bool, error) {
func prepareMultilineRegexp() error {
// to compile regexp only once
multilineOnce.Do(func() {
multilineRegexp, errMultiline = regexp.Compile(`(?s)\/\*(.*?)\*\/`)
multilineRegexp, errMultiline = regexp.Compile(`(?s)\/\*(.*?)\*\/`) //nolint:gocritic
Copy link
Member

Choose a reason for hiding this comment

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

and by using MustCompile we can migrate the initialization of regexps to the top of the file

agent/client/client.go Show resolved Hide resolved
managed/services/checks/checks_test.go Show resolved Hide resolved
Comment on lines -104 to +105
//nolint:nestif
if err == nil {
switch {
case err == nil:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can be just

if err != nil {
   if errors.Is(err, rest.ErrNotInCluster) {
		in.l.Info("PMM is running outside a kubernetes cluster")
                return nil
    }
    in.l.Errorf("failed getting kubeconfig inside cluster: %v", err)
    return nil
}

// Code for case when we don't have error at all

@ademidoff
Copy link
Member Author

I'll merge this PR to enable the rule and create another issue to address just the regexp.MustCompile part.

@ademidoff ademidoff enabled auto-merge (squash) June 21, 2023 21:12
@ademidoff ademidoff merged commit e136f49 into main Jun 21, 2023
@ademidoff ademidoff deleted the PMM-7-enable-gocritic-linter-rule branch June 21, 2023 21:28
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