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: Update golangci-lint to enable more lint rules #2923

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

nickajacks1
Copy link
Member

@nickajacks1 nickajacks1 commented Mar 18, 2024

Description

Enable a few more low-hanging-fruit lint rules.

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.

Type of change

Please delete options that are not relevant.

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

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.

Summary by CodeRabbit

  • Refactor
    • Improved logging functionality for better clarity and flexibility.
    • Enhanced test cases for more reliable validation of application behavior.
    • Optimized code structure in various components for increased readability and maintainability, including the use of switch statements over multiple if-else blocks.
  • Chores
    • Updated code linting settings for more thorough code quality checks.

@nickajacks1 nickajacks1 requested a review from a team as a code owner March 18, 2024 01:20
@nickajacks1 nickajacks1 requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team March 18, 2024 01:20
Copy link
Contributor

coderabbitai bot commented Mar 18, 2024

Walkthrough

The recent updates focus on refining the codebase for better readability, maintainability, and functionality. Key changes include the adoption of switch statements over multiple conditional blocks, enhancements in error handling and logging, and the removal of outdated code and assertions. These modifications aim to streamline processes and improve the overall code quality, ensuring a more robust and efficient application.

Changes

Files Summary
.golangci.yml Enabled diagnostic for gocritic, added unhandled-error, updated testifylint usage
app.go Updated Printf method signature in disableLogger
app_test.go, bind_test.go Removed outdated test assertions and updated query string in benchmark
.../hooks_test.go, middleware/.../keyauth_test.go, middleware/logger/..., middleware/session/... Refactored to use switch statements, improving logic flow
ctx_test.go, helpers.go Commented out assertions, refactored logic using switch, enhanced string handling

🐇✨
Changes abound, the code does leap,
Through switch and case, the logic we keep.
Gone are the ifs, so cluttered and tight,
Now clearer, more graceful, a developer's delight.
🌟📜 In bytes and in bits, our tale unfolds,
A story of code, ever so bold.
🐾🥕 Cheers to the changes, to progress we hop,
With every commit, to excellence, nonstop.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@nickajacks1 nickajacks1 changed the title feat: enable more lint rules chore: Update golangci-lint to enable more lint rules Mar 18, 2024
@gaby gaby added the v3 label Mar 18, 2024
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

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

Project coverage is 82.77%. Comparing base (5449b04) to head (b152867).

Files Patch % Lines
middleware/session/store.go 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2923      +/-   ##
==========================================
+ Coverage   82.75%   82.77%   +0.01%     
==========================================
  Files         116      116              
  Lines        8374     8377       +3     
==========================================
+ Hits         6930     6934       +4     
- Misses       1101     1102       +1     
+ Partials      343      341       -2     
Flag Coverage Δ
unittests 82.77% <87.50%> (+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.

@nickajacks1 nickajacks1 added the v3 label Mar 18, 2024
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5449b04 and b152867.
Files selected for processing (10)
  • .golangci.yml (3 hunks)
  • app.go (1 hunks)
  • app_test.go (1 hunks)
  • bind_test.go (1 hunks)
  • client/hooks_test.go (1 hunks)
  • ctx_test.go (5 hunks)
  • helpers.go (2 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
  • middleware/logger/default_logger.go (1 hunks)
  • middleware/session/store.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • bind_test.go
Additional comments: 9
middleware/session/store.go (1)
  • 75-88: The refactor to use a switch statement in the Get method improves readability and maintainability by clearly handling different cases of err and raw values. However, there are a couple of points to consider:
  • Test Coverage: The added lines (76-77) handling the error case are not covered by tests. It's crucial to ensure that all code paths, especially error handling, are tested to maintain code reliability.
  • Concurrency: The use of mux.Lock() and mux.Unlock() around the session data decoding ensures thread safety. This is a good practice when dealing with shared resources in a concurrent environment.

Please ensure to add test coverage for the error handling case. Additionally, verify that the locking mechanism does not introduce any performance bottlenecks under high load.

middleware/logger/default_logger.go (1)
  • 111-116: The refactor to use a switch statement in the defaultLoggerInstance function for handling logFunc and TemplateChain is a positive change for readability and maintainability. It makes the logic for executing log functions and handling template parts more explicit. However, ensure that:
  • Error Handling: The error handling within the loop is straightforward, but it's important to verify that all possible errors from logFunc are appropriately handled and logged.
  • Performance: While the refactor improves readability, ensure that the performance impact is minimal, especially in high-throughput logging scenarios.

The changes are approved, but please verify error handling completeness and assess any potential performance impacts.

.golangci.yml (2)
  • 75-76: Enabling the diagnostic tag for gocritic in the lint configuration is a positive step towards improving code quality by catching more potential issues. This change aligns with the PR's objective to enhance code reliability and robustness.

The adjustment to the lint configuration is approved as it contributes to the overall goal of improving code quality.

  • 193-194: Adding the unhandled-error check with specific arguments (bytes.Buffer.Write) to the lint configuration is a good practice. It helps in identifying places where errors are not properly handled, which is crucial for maintaining a robust codebase.

The addition of the unhandled-error check is approved as it enhances error handling practices in the code.

middleware/keyauth/keyauth_test.go (1)
  • 92-101: The refactor to use a switch statement in the TestAuthSources function for setting up API keys based on different authentication sources improves readability and maintainability. It makes the setup process more explicit and easier to understand. However, ensure that:
  • Test Coverage: All authentication sources (header, cookie, query, form, and param) are thoroughly tested, including edge cases.
  • Correctness: The handling of the param case seems to append the API key directly to the URL path without a separator, which might not align with the intended test setup. Verify that this setup accurately reflects the intended test scenarios.

The changes are approved, but please verify the correctness of the param case setup and ensure comprehensive test coverage for all authentication sources.

client/hooks_test.go (1)
  • 186-191: The switch statement introduced for setting flags based on query parameter values is a good improvement in terms of readability and maintainability. It simplifies the logic compared to multiple if-else statements and makes it easier to understand the conditions being checked. This change aligns well with the PR's objective of improving code quality and consistency.
app.go (1)
  • 991-991: The update to the Printf method in the disableLogger struct, making it accept a string and variadic arguments, is a positive change that aligns with the PR's objectives of improving code quality and maintainability. Ensure that this change integrates well with the rest of the application's logging mechanism.
helpers.go (1)
  • 464-471: The refactoring of the getOffer function to use a switch statement instead of multiple if conditions is a positive change for readability and maintainability. This approach simplifies the logic for determining the specificity of an accepted type, making it easier to understand and modify in the future. Good job on applying this best practice.
app_test.go (1)
  • 1316-1326: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1000]

Assertions related to the "Location" header have been removed in the test cases for /test/v1/ and /test/v1/UsErS. It's important to ensure that this change aligns with the updated application behavior and does not unintentionally reduce test coverage. If the "Location" header is no longer relevant or its behavior has changed, this adjustment is justified. However, if the "Location" header still plays a role in the application's functionality, consider adding relevant assertions or tests to cover its new behavior.

@@ -1435,6 +1435,7 @@ func Test_Ctx_Parsers(t *testing.T) {
})
t.Run("ParamsParser", func(t *testing.T) {
t.Skip("ParamsParser is not ready for v3")
//nolint:gocritic // TODO: uncomment
Copy link
Contributor

Choose a reason for hiding this comment

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

The ParamsParser test is skipped with a comment indicating it's not ready for v3. This might be an oversight or an unfinished task.

Would you like me to help finalize the implementation or remove the placeholder if it's no longer needed?

@ReneWerner87 ReneWerner87 merged commit 82070cb into gofiber:main Mar 18, 2024
15 of 16 checks passed
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 18, 2024
@nickajacks1 nickajacks1 deleted the lint-more branch March 18, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants