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

Change revive cognitive-complexity settings #2316

Merged
merged 4 commits into from
Nov 17, 2023

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Nov 14, 2023

What problem does this PR solve?

The revive check for cognitive complexity was emitting warnings:

$ make lint 
linting
  ⚠  https://revive.run/r#cognitive-complexity  function (*Manager).Deploy has cognitive complexity 66 (> max enabled 48)  
  ./pkg/cluster/manager/deploy.go:57:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Specification).CountDir has cognitive complexity 51 (> max enabled 48)  
  ./pkg/cluster/spec/validate.go:812:1

  ⚠  https://revive.run/r#cognitive-complexity  function newImportCmd has cognitive complexity 51 (> max enabled 48)  
  ./components/cluster/command/import.go:31:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*cleanupFiles).instanceCleanupFiles has cognitive complexity 54 (> max enabled 48)  
  ./pkg/cluster/manager/cleanup.go:186:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Manager).ScaleOut has cognitive complexity 64 (> max enabled 48)  
  ./pkg/cluster/manager/scale_out.go:40:1

  ⚠  https://revive.run/r#cognitive-complexity  function init has cognitive complexity 56 (> max enabled 48)  
  ./cmd/root.go:56:1

  ⚠  https://revive.run/r#cognitive-complexity  function parseGroupVars has cognitive complexity 245 (> max enabled 48)  
  ./pkg/cluster/ansible/inventory.go:136:1

  ⚠  https://revive.run/r#cognitive-complexity  function parseDirs has cognitive complexity 105 (> max enabled 48)  
  ./pkg/cluster/ansible/service.go:37:1

  ⚠  https://revive.run/r#cognitive-complexity  function cloneComponents has cognitive complexity 71 (> max enabled 48)  
  ./pkg/repository/clone_mirror.go:246:1

  ⚠  https://revive.run/r#cognitive-complexity  function combineVersions has cognitive complexity 79 (> max enabled 48)  
  ./pkg/repository/clone_mirror.go:423:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Importer).ImportFromAnsibleDir has cognitive complexity 156 (> max enabled 48)  
  ./components/dm/ansible/import.go:276:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Playground).handleScaleIn has cognitive complexity 74 (> max enabled 48)  
  ./components/playground/playground.go:261:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Playground).bootCluster has cognitive complexity 99 (> max enabled 48)  
  ./components/playground/playground.go:894:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Playground).terminate has cognitive complexity 56 (> max enabled 48)  
  ./components/playground/playground.go:1204:1

  ⚠  https://revive.run/r#cognitive-complexity  function Execute has cognitive complexity 57 (> max enabled 48)  
  ./components/cluster/command/root.go:276:1

  ⚠  https://revive.run/r#cognitive-complexity  function ScpDownload has cognitive complexity 65 (> max enabled 48)  
  ./pkg/cluster/executor/scp.go:33:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Manager).Upgrade has cognitive complexity 90 (> max enabled 48)  
  ./pkg/cluster/manager/upgrade.go:41:1

  ⚠  https://revive.run/r#cognitive-complexity  function Upgrade has cognitive complexity 91 (> max enabled 48)  
  ./pkg/cluster/operation/upgrade.go:43:1

  ⚠  https://revive.run/r#cognitive-complexity  function setCustomDefaults has cognitive complexity 57 (> max enabled 48)  
  ./pkg/cluster/spec/spec.go:608:1

  ⚠  https://revive.run/r#cognitive-complexity  function DestroyComponent has cognitive complexity 59 (> max enabled 48)  
  ./pkg/cluster/operation/destroy.go:339:1

  ⚠  https://revive.run/r#cognitive-complexity  function DestroyClusterTombstone has cognitive complexity 65 (> max enabled 48)  
  ./pkg/cluster/operation/destroy.go:475:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*MonitorInstance).InitConfig has cognitive complexity 80 (> max enabled 48)  
  ./pkg/cluster/spec/monitoring.go:190:1

  ⚠  https://revive.run/r#cognitive-complexity  function ScaleInCluster has cognitive complexity 167 (> max enabled 48)  
  ./pkg/cluster/operation/scale_in.go:86:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Manager).Display has cognitive complexity 65 (> max enabled 48)  
  ./pkg/cluster/manager/display.go:117:1

  ⚠  https://revive.run/r#cognitive-complexity  function (*Manager).GetClusterTopology has cognitive complexity 56 (> max enabled 48)  
  ./pkg/cluster/manager/display.go:528:1

  ⚠  https://revive.run/r#cognitive-complexity  function ScaleInDMCluster has cognitive complexity 57 (> max enabled 48)  
  ./components/dm/command/scale_in.go:76:1

⚠ 26 problems (0 errors, 26 warnings)

Warnings:
  26  cognitive-complexity  

It looks like these warnings were not getting noticed or fixed.

What is changed and how it works?

This PR:

  1. Changes the complexity limit to 100 and marks existing cases that go over 100 with //revive:disable.
  2. Changes the check to error when the limit is exceeded (previously it would just warn)

This makes accidentally exceeding this with new code harder.

Check List

Tests

  • No code

Release notes:

NONE

@ti-chi-bot ti-chi-bot bot requested a review from nexustar November 14, 2023 09:49
@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 14, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c0abd84) 55.03% compared to head (b70f3a6) 55.36%.

❗ Current head b70f3a6 differs from pull request most recent head c720f41. Consider uploading reports for the commit c720f41 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2316      +/-   ##
==========================================
+ Coverage   55.03%   55.36%   +0.33%     
==========================================
  Files         325      325              
  Lines       34753    34753              
==========================================
+ Hits        19124    19239     +115     
+ Misses      13318    13202     -116     
- Partials     2311     2312       +1     
Flag Coverage Δ
cluster 44.71% <ø> (+0.51%) ⬆️
dm 25.45% <ø> (ø)
playground 15.22% <ø> (-0.02%) ⬇️
tiup 33.48% <ø> (ø)
unittest 22.29% <ø> (-0.01%) ⬇️

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.

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 14, 2023
@dveeden
Copy link
Contributor Author

dveeden commented Nov 14, 2023

/cc @srstack

@ti-chi-bot ti-chi-bot bot requested a review from srstack November 14, 2023 13:17
@kaaaaaaang
Copy link
Collaborator

/lgtm

@ti-chi-bot ti-chi-bot bot added the lgtm label Nov 16, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 16, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-16 07:53:32.575713537 +0000 UTC m=+4322010.162823682: ☑️ agreed by kaaaaaaang.

@kaaaaaaang
Copy link
Collaborator

/approve

Copy link
Contributor

ti-chi-bot bot commented Nov 17, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kaaaaaaang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Nov 17, 2023
@ti-chi-bot ti-chi-bot bot merged commit 137f80d into pingcap:master Nov 17, 2023
17 checks passed
@kaaaaaaang kaaaaaaang added this to the v1.14.0 milestone Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants