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

chore: Bump golangci-lint to v1.60.3 #3119

Merged
merged 1 commit into from
Sep 2, 2024
Merged

Conversation

gaby
Copy link
Member

@gaby gaby commented Sep 2, 2024

Description

  • Bump golangci-lint to v1.60.3
  • Always run markdown-lint workflow
  • Add check for Body Content Length to Etag middleware. Return error if greater than MaxUint32
  • Note: There's no easy way to test the 4GB max size other than mocking which is an overkill for this case.

Type of change

  • Code consistency (non-breaking change which improves code reliability and robustness)

@gaby gaby requested a review from a team as a code owner September 2, 2024 13:00
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn and removed request for a team September 2, 2024 13:00
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes consist of updates to GitHub Actions workflows, modifications to linter configurations, and refinements in test files across the codebase. Key updates include version increments for the golangci-lint-action, removal of file path filters in Markdown workflows, and adjustments to variable declarations in various test functions to enhance clarity. Additionally, new validations and comments were added to ensure better code quality and maintainability.

Changes

Files Change Summary
.github/workflows/linter.yml, .github/workflows/markdown.yml, .golangci.yml, Makefile Updated linter versions, modified workflow triggers to include all file types, and adjusted linter configurations.
addon/retry/exponential_backoff_test.go, client/core_test.go, client/hooks_test.go, client/request_test.go, ctx_test.go, middleware/compress/compress_test.go, middleware/encryptcookie/encryptcookie_test.go, middleware/pprof/pprof_test.go, middleware/static/static_test.go Removed redundant variable declarations in test functions for improved readability without altering functionality.
helpers.go, middleware/etag/etag.go, middleware/limiter/limiter_sliding.go, mount.go, router.go Added comments and validation checks to enhance code clarity and robustness without changing the overall logic.
mount_test.go Modified error handling response in a test function to reflect a new expected output.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Linter
    participant Codebase

    User->>GitHub Actions: Push changes
    GitHub Actions->>Linter: Run linting process
    Linter->>Codebase: Analyze code
    Codebase->>Linter: Return results
    Linter->>GitHub Actions: Send linting report
    GitHub Actions->>User: Notify results
Loading

🐰 Hopping through the code so bright,
With lints and tests, all feels right!
A version bump, a comment here,
Clean code brings us all good cheer!
Let's celebrate with a joyful dance,
For every change, we take a chance! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.01%. Comparing base (9541a88) to head (ae624aa).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
middleware/etag/etag.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3119      +/-   ##
==========================================
- Coverage   80.03%   80.01%   -0.02%     
==========================================
  Files         117      117              
  Lines        9035     9038       +3     
==========================================
+ Hits         7231     7232       +1     
- Misses       1373     1374       +1     
- Partials      431      432       +1     
Flag Coverage Δ
unittests 80.01% <80.00%> (-0.02%) ⬇️

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
.github/workflows/markdown.yml (1)

Consider Reintroducing paths Filters in GitHub Actions Workflow

The removal of the paths filters in the GitHub Actions workflow will cause the markdownlint job to run on all changes to the master or main branches and for all pull requests, regardless of the file types involved. Given the presence of a significant number of non-Markdown files in the repository, this could lead to unnecessary workflow runs, potentially increasing the usage of GitHub Actions minutes. Consider reintroducing the paths filters to ensure that the workflow only runs when Markdown files are changed. Additionally, adding a workflow_dispatch event would allow for manual triggering of the workflow when needed, providing flexibility.

  • File: .github/workflows/markdown.yml
  • Suggested Configuration:
    on:
      push:
        branches:
          - master
          - main
        paths:
          - "**/*.md"
      pull_request:
        paths:
          - "**/*.md"
      workflow_dispatch:
Analysis chain

Line range hint 1-24: Verify the impact of removing the paths filters.

Removing the paths filters will trigger the workflow on any changes to the master or main branches for push events and for any pull requests, regardless of the file types involved. This might lead to unnecessary workflow runs for changes that don't involve Markdown files, potentially increasing the usage of GitHub Actions minutes.

To verify the impact of this change, run the following script:

If the repository contains a significant number of non-Markdown files, consider keeping the paths filters and adding an on.workflow_dispatch event to allow manual triggering of the workflow when needed. This will ensure that the workflow runs only for relevant changes while providing flexibility to run it manually.

on:
  push:
    branches:
      - master
      - main
    paths:
      - "**/*.md"
  pull_request:
    paths:
      - "**/*.md"
  workflow_dispatch:
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the `paths` filters.

# Test 1: Search for Markdown files in the repository. 
# Expect: Markdown files are present.
fd --extension md

# Test 2: Search for non-Markdown files in the repository. 
# Expect: Non-Markdown files are present.
fd --exclude '*.md'

Length of output: 7506

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4acdc60 and ae624aa.

Files selected for processing (20)
  • .github/workflows/linter.yml (1 hunks)
  • .github/workflows/markdown.yml (1 hunks)
  • .golangci.yml (4 hunks)
  • Makefile (1 hunks)
  • addon/retry/exponential_backoff_test.go (2 hunks)
  • client/core_test.go (1 hunks)
  • client/hooks_test.go (2 hunks)
  • client/request_test.go (1 hunks)
  • ctx_test.go (3 hunks)
  • helpers.go (3 hunks)
  • middleware/compress/compress_test.go (1 hunks)
  • middleware/encryptcookie/encryptcookie_test.go (2 hunks)
  • middleware/etag/etag.go (2 hunks)
  • middleware/limiter/limiter_sliding.go (1 hunks)
  • middleware/limiter/limiter_test.go (2 hunks)
  • middleware/pprof/pprof_test.go (2 hunks)
  • middleware/static/static_test.go (2 hunks)
  • mount.go (2 hunks)
  • mount_test.go (2 hunks)
  • router.go (1 hunks)
Files skipped from review due to trivial changes (12)
  • .github/workflows/linter.yml
  • Makefile
  • addon/retry/exponential_backoff_test.go
  • client/hooks_test.go
  • client/request_test.go
  • ctx_test.go
  • middleware/compress/compress_test.go
  • middleware/encryptcookie/encryptcookie_test.go
  • middleware/limiter/limiter_sliding.go
  • middleware/limiter/limiter_test.go
  • middleware/pprof/pprof_test.go
  • middleware/static/static_test.go
Additional context used
GitHub Check: codecov/patch
middleware/etag/etag.go

[warning] 65-65: middleware/etag/etag.go#L65
Added line #L65 was not covered by tests

golangci-lint
mount.go

191-191: directive //nolint:gosec // Not a concern is unused for linter "gosec"

(nolintlint)


222-222: directive //nolint:gosec // Not a concern is unused for linter "gosec"

(nolintlint)

router.go

361-361: directive //nolint:gosec // Not a concern is unused for linter "gosec"

(nolintlint)

helpers.go

769-769: directive //nolint:gosec // Casting in this function is not a concern is unused for linter "gosec"

(nolintlint)

Additional comments not posted (12)
middleware/etag/etag.go (1)

60-62: LGTM!

The code changes are approved.

client/core_test.go (1)

Line range hint 45-47: LGTM!

The removal of the line that creates a new variable tt for use within the goroutine is a good change. It eliminates the shadowing of the loop variable tt, which is a best practice to avoid potential data races when using loop variables in concurrent tests. The change improves clarity and reduces unnecessary variable declarations while maintaining the overall functionality of the test.

.golangci.yml (4)

281-281: Approved enabling the dupword linter.

Enabling the dupword linter is a good practice to detect duplicate words in the code.


290-290: Approved replacing the exportloopref linter with the copyloopvar linter.

The exportloopref linter is deprecated and replaced by the copyloopvar linter in newer versions of golangci-lint. The copyloopvar linter detects loop variables that are copied by value instead of by reference, which can lead to unexpected behavior.


301-301: Approved enabling the goconst linter.

Enabling the goconst linter is a good practice to detect repeated string constants in the code.


310-311: Please provide the reason for disabling the gomnd linter.

The gomnd linter detects magic numbers in the code. Disabling it might lead to magic numbers being introduced in the code. Please add a comment to document the reason for disabling the linter.

router.go (1)

361-361: The added //nolint:gosec // Not a concern comment is valid and correctly suppresses the "gosec" linter warning. The static analysis tool's hint about the unused directive seems to be a false positive in this case.

Tools
golangci-lint

361-361: directive //nolint:gosec // Not a concern is unused for linter "gosec"

(nolintlint)

mount_test.go (2)

350-350: LGTM!

The change to the custom error message is consistent with the test case and looks good.


397-397: LGTM!

The assertion has been correctly updated to match the changed custom error message.

helpers.go (3)

329-329: LGTM!

The change of lastElementEndsAt variable type from uint8 to int is approved. It allows the variable to store a broader range of values, which is relevant as the index can exceed the maximum value of uint8 in certain scenarios.


340-340: LGTM!

The change in the assignment of lastElementEndsAt is approved. It is consistent with the change in the type of lastElementEndsAt variable from uint8 to int.


769-769: Keep the clarifying comment.

The comment above the genericParseType function clarifies that the casting within this function is not a security concern. It is relevant and should be kept for future maintainers.

The static analysis hint about the unused //nolint:gosec directive is a false positive and can be ignored.

Tools
golangci-lint

769-769: directive //nolint:gosec // Casting in this function is not a concern is unused for linter "gosec"

(nolintlint)

Comment on lines +63 to +68
bodyLength := len(body)
if bodyLength > math.MaxUint32 {
return c.SendStatus(fiber.StatusRequestEntityTooLarge)
}

bb.B = appendUint(bb.Bytes(), uint32(bodyLength)) //nolint:gosec // Body length is validated above
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM!

The validation logic is correct and enhances the robustness of the ETag generation.

Add a test case for the added line.

The static analysis tool indicates that the added line #L65 is not covered by tests.

Do you want me to generate a test case for this line or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 65-65: middleware/etag/etag.go#L65
Added line #L65 was not covered by tests

@ReneWerner87 ReneWerner87 merged commit f668537 into main Sep 2, 2024
16 of 18 checks passed
@gaby gaby deleted the bump-golangci-lint branch September 2, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants