pingcap / tiup

A component manager for TiDB
https://tiup.io
Apache License 2.0
417 stars 310 forks source link

Change revive cognitive-complexity settings #2316

Closed dveeden closed 10 months ago

dveeden commented 10 months ago

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

Release notes:

NONE
codecov-commenter commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

:exclamation: 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 ```diff @@ 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](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | Coverage Δ | | |---|---|---| | [cluster](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `44.71% <ø> (+0.51%)` | :arrow_up: | | [dm](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `25.45% <ø> (ø)` | | | [playground](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `15.22% <ø> (-0.02%)` | :arrow_down: | | [tiup](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `33.48% <ø> (ø)` | | | [unittest](https://app.codecov.io/gh/pingcap/tiup/pull/2316/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `22.29% <ø> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dveeden commented 10 months ago

/cc @srstack

kaaaaaaang commented 10 months ago

/lgtm

ti-chi-bot[bot] commented 10 months ago

[LGTM Timeline notifier]

Timeline:

kaaaaaaang commented 10 months ago

/approve

ti-chi-bot[bot] commented 10 months ago

[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: - ~~[OWNERS](https://github.com/pingcap/tiup/blob/master/OWNERS)~~ [kaaaaaaang] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment