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

golangci-lint run --fix #15840

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

golangci-lint run --fix #15840

wants to merge 1 commit into from

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Jan 3, 2025

No description provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I manually tweaked this one since the autofix exposed a lot of appending.

Copy link
Contributor

github-actions bot commented Jan 3, 2025

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

🎖️ No JIRA issue number found in: PR title, commit message, or branch name. Please include the issue ID in one of these.

Copy link
Contributor

github-actions bot commented Jan 3, 2025

AER Report: CI Core

aer_workflow , commit , Detect Changes , Clean Go Tidy & Generate , Scheduled Run Frequency , Core Tests (go_core_tests) , Core Tests (go_core_tests_integration) , Core Tests (go_core_ccip_deployment_tests) , GolangCI Lint (.) , Core Tests (go_core_fuzz) , Core Tests (go_core_race_tests) , test-scripts , lint , SonarQube Scan

1. Unused field tokenRatioCalldata and constant getL1FeeMethod:

[A 1 <= 10 words sentence that describes the error]:[job id where the error happened]

  • Field tokenRatioCalldata is unused: Golang Lint (.)
  • Const getL1FeeMethod is unused: Golang Lint (.)
Source of Error:
<file name="core/chains/evm/gas/rollups/op_l1_oracle.go">
<error column="2" line="52" message="field `tokenRatioCalldata` is unused" severity="error" source="unused"></error>
<error column="2" line="69" message="const `getL1FeeMethod` is unused" severity="error" source="unused"></error>
</file>

Why: The field tokenRatioCalldata and the constant getL1FeeMethod are declared but not used anywhere in the code.

Suggested fix: Remove the unused field and constant to clean up the code.

2. Capitalization issues in variable names:

  • GasLimit should not be capitalized: Golang Lint (.)
  • GasPrice should not be capitalized: Golang Lint (.)
Source of Error:
<file name="core/chains/evm/gas/suggested_price_estimator.go">
<error column="79" line="175" message="captLocal: `GasLimit&#39; should not be capitalized" severity="error" source="gocritic"></error>
<error column="50" line="241" message="captLocal: `GasPrice&#39; should not be capitalized" severity="error" source="gocritic"></error>
</file>

Why: Local variable names should follow camelCase convention.

Suggested fix: Rename GasLimit to gasLimit and GasPrice to gasPrice.

3. Pre-allocating slices:

  • Consider pre-allocating topicsInHex: Golang Lint (.)
  • Consider pre-allocating addresses: Golang Lint (.)
Source of Error:
<file name="core/chains/evm/log/broadcaster.go">
<error column="2" line="735" message="Consider pre-allocating `topicsInHex`" severity="error" source="prealloc"></error>
</file>
<file name="core/chains/evm/log/registrations.go">
<error column="2" line="369" message="Consider pre-allocating `addresses`" severity="error" source="prealloc"></error>
</file>

Why: Pre-allocating slices can improve performance by reducing the number of allocations.

Suggested fix: Pre-allocate the slices with an appropriate capacity.

4. Integer overflow conversions:

  • Integer overflow conversion uint -> int64: Golang Lint (.)
  • Integer overflow conversion int64 -> uint: Golang Lint (.)
Source of Error:
<file name="core/chains/evm/logpoller/log_poller.go">
<error column="21" line="829" message="G115: integer overflow conversion uint -&gt; int64" severity="high" source="gosec"></error>
</file>
<file name="core/chains/evm/logpoller/models.go">
<error column="20" line="56" message="G115: integer overflow conversion int64 -&gt; uint" severity="high" source="gosec"></error>
</file>

Why: Converting between integer types can lead to overflow if the value exceeds the range of the target type.

Suggested fix: Ensure that the values being converted are within the range of the target type or use a type that can handle the value range.

5. Float comparison in tests:

  • Use assert.InEpsilon (or InDelta): Golang Lint (.)
Source of Error:
<file name="core/chains/evm/logpoller/observability_test.go">
<error column="2" line="110" message="float-compare: use assert.InEpsilon (or InDelta)" severity="error" source="testifylint"></error>
<error column="2" line="119" message="float-compare: use assert.InEpsilon (or InDelta)" severity="error" source="testifylint"></error>
</file>

Why: Direct float comparisons can be unreliable due to precision issues.

Suggested fix: Use assert.InEpsilon or assert.InDelta for float comparisons in tests.

6. Copying lock values:

  • Assignment copies lock value to ethTx: Golang Lint (.)
  • Assignment copies lock value to *signedLegacyTx: Golang Lint (.)
Source of Error:
<file name="core/chains/evm/txmgr/confirmer_test.go">
<error column="13" line="855" message="copylocks: assignment copies lock value to ethTx: github.com/ethereum/go-ethereum/core/types.Transaction contains sync/atomic.Pointer[github.com/ethereum/go-ethereum/common.Hash] contains sync/atomic.noCopy" severity="error" source="govet"></error>
<error column="22" line="1370" message="copylocks: assignment copies lock value to *signedLegacyTx: github.com/ethereum/go-ethereum/core/types.Transaction contains sync/atomic.Pointer[github.com/ethereum/go-ethereum/common.Hash] contains sync/atomic.noCopy" severity="error" source="govet"></error>
</file>

Why: Copying lock values can lead to race conditions and undefined behavior.

Suggested fix: Avoid copying lock values by passing pointers or using other synchronization mechanisms.

7. Error type naming conventions:

  • Error type name errChainDisabled should conform to the xxxError format: Golang Lint (.)
  • Sentinel error name ErrorNoAPICredentialsAvailable should conform to the ErrXxx format: Golang Lint (.)
Source of Error:
<file name="core/chains/legacyevm/chain.go">
<error column="6" line="122" message="the error type name `errChainDisabled` should conform to the `xxxError` format" severity="error" source="errname"></error>
</file>
<file name="core/cmd/shell.go">
<error column="2" line="141" message="the sentinel error name `ErrorNoAPICredentialsAvailable` should conform to the `ErrXxx` format" severity="error" source="errname"></error>
</file>

Why: Consistent naming conventions improve code readability and maintainability.

Suggested fix: Rename errChainDisabled to chainDisabledError and ErrorNoAPICredentialsAvailable to ErrNoAPICredentialsAvailable.

8. Deprecated function usage:

  • commonservices.NewChecker is deprecated: Golang Lint (.)
Source of Error:
<file name="core/services/chainlink/application.go">
<error column="19" line="637" message="SA1019: commonservices.NewChecker is deprecated: Use NewHealthChecker " severity="error" source="staticcheck"></error>
</file>

Why: Using deprecated functions can lead to issues when the function is removed in future versions.

Suggested fix: Replace commonservices.NewChecker with NewHealthChecker.

9. Shadowed variable declarations:

  • Declaration of err shadows declaration at line 131: Golang Lint (.)
  • Declaration of ctx shadows declaration at line 80: Golang Lint (.)
Source of Error:
<file name="core/services/gateway/handlers/functions/allowlist/allowlist.go">
<error column="7" line="137" message="shadow: declaration of &#34;err&#34; shadows declaration at line 131" severity="error" source="govet"></error>
</file>
<file name="core/services/job/spawner_test.go">
<error column="3" line="151" message="shadow: declaration of &#34;ctx&#34; shadows declaration at line 80" severity="error" source="govet"></error>
<error column="3" line="202" message="shadow: declaration of &#34;ctx&#34; shadows declaration at line 80" severity="error" source="govet"></error>
<error column="3" line="237" message="shadow: declaration of &#34;ctx&#34; shadows declaration at line 80" severity="error" source="govet"></error>
</file>

Why: Shadowing variables can lead to bugs and confusion in the code.

Suggested fix: Rename the shadowed variables to avoid conflicts.

10. Slice bounds out of range:

  • Slice bounds out of range: Golang Lint (.)
Source of Error:
<file name="core/services/keystore/keys/starkkey/ocr2key.go">
<error column="38" line="116" message="G602: slice bounds out of range" severity="low" source="gosec"></error>
<error column="38" line="117" message="G602: slice bounds out of range" severity="low" source="gosec"></error>
</file>

Why: Accessing slices out of their bounds can cause runtime panics.

Suggested fix: Ensure that the slice indices are within the valid range before accessing them.

11. Use of deprecated fields:

  • core.GenesisAlloc is deprecated: Golang Lint (.)
Source of Error:
<file name="core/services/relay/evm/capabilities/testutils/backend.go">
<error column="17" line="55" message="SA1019: core.GenesisAlloc is deprecated: use types.GenesisAlloc instead. " severity="error" source="staticcheck"></error>
</file>

Why: Using deprecated fields can lead to issues when the field is removed in future versions.

Suggested fix: Replace core.GenesisAlloc with types.GenesisAlloc.

12. Meaningless assertions in tests:

  • Meaningless assertion: Golang Lint (.)
Source of Error:
<file name="core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer_v1_test.go">
<error column="3" line="99" message="useless-assert: meaningless assertion" severity="error" source="testifylint"></error>
<error column="3" line="135" message="useless-assert: meaningless assertion" severity="error" source="testifylint"></error>
</file>

Why: Assertions that do not test meaningful conditions should be removed to avoid confusion.

Suggested fix: Remove or replace the meaningless assertions with meaningful ones.

13. Redefinition of built-in functions:

  • Redefinition of the built-in function min: Golang Lint (.)
Source of Error:
<file name="core/utils/backoff_ticker.go">
<error column="40" line="12" message="redefines-builtin-id: redefinition of the built-in function min" severity="warning" source="revive"></error>
<error column="23" line="37" message="redefines-builtin-id: redefinition of the built-in function min" severity="warning" source="revive"></error>
</file>

Why: Redefining built-in functions can lead to unexpected behavior and confusion.

Suggested fix: Rename the custom function to avoid conflicts with built-in functions.

14. Use of require in inappropriate contexts:

  • Require must only be used in the goroutine running the test function: Golang Lint (.)
Source of Error:
<file name="core/internal/features/ocr2/features_ocr2_test.go">
<error column="4" line="229" message="go-require: require must only be used in the goroutine running the test function" severity="error" source="testifylint"></error>
<error column="4" line="231" message="go-require: require must only be used in the goroutine running the test function" severity="error" source="testifylint"></error>
</file>

Why: Using require in inappropriate contexts can lead to test failures and unexpected behavior.

Suggested fix: Ensure that require is only used in the main test goroutine.

15. Unused functions and fields:

  • Func triggerAllKeys is unused: Golang Lint (.)
  • Field config is unused: Golang Lint (.)
Source of Error:
<file name="core/internal/features/features_test.go">
<error column="6" line="1383" message="func `triggerAllKeys` is unused" severity="error" source="unused"></error>
</file>
<file name="core/services/workflows/models.go">
<error column="2" line="85" message="field `config` is unused" severity="error" source="unused"></error>
</file>

Why: Unused functions and fields add unnecessary complexity to the code.

Suggested fix: Remove the unused functions and fields to clean up the code.

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@jmank88 jmank88 force-pushed the fix-golangci-lint branch 6 times, most recently from 566c827 to a6884f8 Compare January 4, 2025 15:15
@jmank88 jmank88 force-pushed the fix-golangci-lint branch from a6884f8 to ef0b433 Compare January 5, 2025 01:57
@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

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.

1 participant