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

♻️ Refactor: Rename the Method Names of FormData and FormDatas (#3251) #3255

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

ksw2000
Copy link
Contributor

@ksw2000 ksw2000 commented Dec 18, 2024

Fixes #3251

Description

Preserved AddFormData and SetFormData:
I kept AddFormData and SetFormData unchanged because "FormData" is an HTTP-specific term. Moreover, the term aligns with the existing formData field, making it consistent.

Renamed *FormDatas to *FormDataWithMap:
Since there is already a method called *FormDatasWithStruct, I renamed *FormDatas to *FormDataWithMap for better clarity and intuitiveness during usage. The WithMap and WithStruct suffixes provide a clear indication that these methods can handle multiple key-value pairs.

Renamed AddData and SetData (in FormData) to Add and Set:
The methods AddData and SetData in FormData were renamed to Add and Set to align with the naming convention in fasthttp.Args, which also uses Add and Set.

  • func (r *Request) AddFormData → Not changed
  • func (r *Request) AddFormDatasfunc (r *Request) AddFormDataWithMap
  • func (r *Request) SetFormData → Not changed
  • func (r *Request) SetFormDatasfunc (r *Request) SetFormDataWithMap
  • func (r *Request) SetFormDatasWithStructfunc (r *Request) SetFormDataWithStruct (remove s)
  • func (r *Request) DelFormDatasfunc (r *Request) DelFormData (remove s)
  • func (f *FormData) AddDatafunc (f *FormData) Add (keep consistent with fasthttp.Args)
  • func (f *FormData) SetDatafunc (f *FormData) Set (keep consistent with fasthttp.Args)
  • func (f *FormData) AddDatasfunc (f *FormData) AddWithMap
  • func (f *FormData) SetDatasfunc (f *FormData) SetWithMap
  • func (f *FormData) SetDatasWithStructfunc (f *FormData) SetWithStruct
  • func (f *FormData) DelDatasfunc (f *FormData) DelData (remove s)

Type of change

Please delete options that are not relevant.

  • Documentation update (changes to documentation)
  • 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:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • 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.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces a comprehensive renaming of methods related to form data handling across multiple files in the Gofiber HTTP client. The changes focus on improving method naming conventions, making them more consistent and clear. The modifications span client/client.go, client/hooks_test.go, client/request.go, client/request_test.go, and docs/client/request.md, updating method names to provide better clarity around form data manipulation methods.

Changes

File Change Summary
client/client.go Updated setConfigToRequest to use req.SetFormDataWithMap(cfg.FormData)
client/hooks_test.go Renamed SetFormDatas to SetFormDataWithMap in test cases
client/request.go Renamed multiple form data methods:
- AddFormDatasAddFormDataWithMap
- SetFormDatasSetFormDataWithMap
- DelFormDatasDelFormData
- Various FormData struct methods renamed for consistency
client/request_test.go Updated test cases to use new method names
docs/client/request.md Updated documentation to reflect new method names

Assessment against linked issues

Objective Addressed Explanation
Rename methods for clarity [#3251] The PR did not fully implement the suggested renaming to "Item/Items" as proposed in the issue
Improve method naming conventions

Possibly related PRs

Suggested labels

✏️ Feature, v3

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • gaby

Poem

🐰 A Rabbit's Ode to Method Renaming 🐰

With whiskers twitching and code so bright,
We dance through methods, making naming right!
From Datas to Map, we hop with glee,
Clarity springs forth, as clear as can be!
A code refactor, both subtle and neat! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2b557c and 25fcc8c.

📒 Files selected for processing (5)
  • client/client.go (1 hunks)
  • client/hooks_test.go (3 hunks)
  • client/request.go (2 hunks)
  • client/request_test.go (7 hunks)
  • docs/client/request.md (2 hunks)
🔇 Additional comments (11)
client/hooks_test.go (2)

282-285: LGTM! Test case updated to use the new method name.

The test case has been correctly updated to use SetFormDataWithMap instead of SetFormDatas, maintaining consistency with the new naming convention.


488-490: LGTM! Form data test cases updated consistently.

Both test cases have been updated to use the new method name SetFormDataWithMap, maintaining consistency across the test suite.

Also applies to: 501-503

client/client.go (1)

611-611: LGTM! Method call updated to use the new name.

The setConfigToRequest function has been correctly updated to use SetFormDataWithMap instead of SetFormDatas, maintaining consistency with the new naming convention.

client/request.go (3)

463-464: LGTM! Simplified method names in Request struct.

Methods have been simplified by removing redundant "Data" suffix:

  • AddDataAdd
  • SetDataSet

This change improves readability while maintaining functionality.

Also applies to: 470-471


475-498: LGTM! Improved clarity in method names for map operations.

Methods have been renamed to clearly indicate they operate on maps:

  • AddFormDatasAddFormDataWithMap
  • SetFormDatasSetFormDataWithMap
  • SetFormDatasWithStructSetFormDataWithStruct
  • DelFormDatasDelFormData

The new names better describe their functionality and maintain consistency with the existing WithStruct pattern.


848-883: LGTM! Consistent method naming in FormData struct.

FormData struct methods have been renamed to follow the same pattern:

  • Simplified base methods (Add, Set)
  • Clear indication of map operations (AddWithMap, SetWithMap)
  • Consistent use of WithStruct suffix
  • Simplified deletion method name (DelData)

The changes improve code clarity and maintain consistency across the codebase.

docs/client/request.md (2)

828-857: Documentation updates look good!

The documentation for the renamed form data methods is clear, consistent, and properly reflects the new method names while maintaining the same functionality:

  • AddFormDataWithMap
  • SetFormDataWithMap
  • SetFormDataWithStruct
  • DelFormData

1314-1359: FormData struct method documentation is well organized!

The documentation for the FormData struct methods is clear and follows a consistent pattern:

  • Add and Set for single field operations
  • AddWithMap, SetWithMap, and SetWithStruct for bulk operations
  • DelData for deletion operations
client/request_test.go (3)

Line range hint 618-708: Test cases properly updated for renamed methods!

The test cases have been correctly updated to use the new method names while maintaining comprehensive test coverage for form data operations.


Line range hint 1365-1381: AllFormData tests and benchmarks properly updated!

The tests and benchmarks for AllFormData have been correctly updated to use the new method names while maintaining proper test coverage and performance testing.


Line range hint 1-1700: Verify consistent method naming across the codebase

The test file changes look good. Let's verify that all occurrences of the old method names have been updated consistently across the codebase.

✅ Verification successful

Based on the search results, I can see that there are no occurrences of the old method names in the codebase, and the new method names are consistently used. The changes appear to be complete and consistent.

All method renames have been properly implemented
The changes are consistent across the codebase with no remaining instances of the old method names, confirming that the test file changes align with the broader codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining occurrences of old method names

# Check for old method names
echo "Checking for old method names..."
rg -i "AddFormDatas|SetFormDatas|SetFormDatasWithStruct|DelFormDatas|AddData|SetData|AddDatas|SetDatas|SetDatasWithStruct|DelDatas"

# Check for new method names to confirm changes
echo "Verifying new method names..."
rg -i "AddFormDataWithMap|SetFormDataWithMap|SetFormDataWithStruct|DelFormData|Add|Set|AddWithMap|SetWithMap|SetWithStruct|DelData"

Length of output: 99445


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@ksw2000 ksw2000 changed the title ♻️ Refactor: ♻️ Refactor: Rename the Method Name of FormData and FormDatas (#3251) Dec 18, 2024
@ksw2000 ksw2000 changed the title ♻️ Refactor: Rename the Method Name of FormData and FormDatas (#3251) ♻️ Refactor: Rename the Method Names of FormData and FormDatas (#3251) Dec 18, 2024
@ksw2000 ksw2000 marked this pull request as ready for review December 18, 2024 16:57
@ksw2000 ksw2000 requested a review from a team as a code owner December 18, 2024 16:57
@ksw2000 ksw2000 requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team December 18, 2024 16:58
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.63%. Comparing base (c2b557c) to head (25fcc8c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3255      +/-   ##
==========================================
- Coverage   82.72%   82.63%   -0.10%     
==========================================
  Files         115      115              
  Lines       11365    11365              
==========================================
- Hits         9402     9391      -11     
- Misses       1557     1565       +8     
- Partials      406      409       +3     
Flag Coverage Δ
unittests 82.63% <100.00%> (-0.10%) ⬇️

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.

@gaby gaby added this to the v3 milestone Dec 19, 2024
Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@ReneWerner87 ReneWerner87 merged commit 69e5ccd into gofiber:main Dec 19, 2024
14 of 15 checks passed
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.

Suggestion: Rename AddData and AddDatas for clarity
4 participants