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

⚡ decode returns Map<String, dynamic> instead of Map #17

Merged
merged 4 commits into from
May 18, 2024

Conversation

techouse
Copy link
Owner

@techouse techouse commented May 18, 2024

Description

QS.decode now decodes an input to Map<String, dynamic> instead of Map<dynamic, dynamic>.

NOTE: This means that all decoded map keys will now be Strings.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

The tests have been updated to reflect the change.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@techouse techouse added the enhancement New feature or request label May 18, 2024
@techouse techouse self-assigned this May 18, 2024
Copy link

coderabbitai bot commented May 18, 2024

Warning

Rate Limit Exceeded

@techouse has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 39 minutes and 3 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 5fb8e6c and 76a2c99.

Walkthrough

The recent changes encompass type annotation updates for functions and variables to ensure type safety, the addition of a new isNumeric extension method for strings, and adjustments to keys in map literals within tests. These modifications enhance code clarity, consistency, and functionality across the library.

Changes

Files/Groups Change Summary
lib/src/extensions/decode.dart Updated type annotations for _parseQueryStringValues function.
lib/src/extensions/extensions.dart Added new isNumeric extension method to StringExtension.
lib/src/methods.dart Changed decode function signature to Map<String, dynamic>.
lib/src/qs.dart Updated QS.decode method signature to Map<String, dynamic>.
lib/src/utils.dart Modified merge and compact methods to use Map<String, dynamic> type annotations.
test/fixtures/data/empty_test_cases.dart Converted integer keys to string keys in dictionaries and lists.
test/unit/decode_test.dart Updated test cases to reflect changes in key types and expected outputs.
test/unit/utils_test.dart Adjusted keys in map literals from integer to string keys for consistency in tests.

In code's vast field, the rabbit hops,
With nimble paws, it never stops.
Type safety blooms, like flowers bright,
Extensions grow, enhancing might.
The tests now sing a clearer tune,
As maps and lists align in June.
🐇✨


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.

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.
  • 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.

@techouse techouse changed the title ⚡ decode to Map<String, dynamic> instead of Map<dynamic, dynamic> ⚡ decode returns Map<String, dynamic> instead of Map May 18, 2024
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

lib/src/utils.dart Dismissed Show dismissed Hide dismissed
lib/src/utils.dart Dismissed Show dismissed Hide dismissed
lib/src/utils.dart Dismissed Show dismissed Hide dismissed
lib/src/qs.dart Dismissed Show dismissed Hide dismissed
Copy link

codacy-production bot commented May 18, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.70% (target: -1.00%) 91.43%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (de9d285) 629 616 97.93%
Head commit (76a2c99) 651 (+22) 633 (+17) 97.24% (-0.70%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#17) 35 32 91.43%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Copy link

codecov bot commented May 18, 2024

Codecov Report

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

Project coverage is 97.63%. Comparing base (de9d285) to head (76a2c99).

Files Patch % Lines
lib/src/utils.dart 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
- Coverage   97.92%   97.63%   -0.30%     
==========================================
  Files          13       13              
  Lines         627      633       +6     
==========================================
+ Hits          614      618       +4     
- Misses         13       15       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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: 4

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between de9d285 and f73caf6.
Files selected for processing (8)
  • lib/src/extensions/decode.dart (4 hunks)
  • lib/src/extensions/extensions.dart (1 hunks)
  • lib/src/methods.dart (1 hunks)
  • lib/src/qs.dart (1 hunks)
  • lib/src/utils.dart (4 hunks)
  • test/fixtures/data/empty_test_cases.dart (3 hunks)
  • test/unit/decode_test.dart (13 hunks)
  • test/unit/utils_test.dart (4 hunks)
Additional Context Used
GitHub Check Runs (2)
codecov/patch failure (2)

lib/src/extensions/extensions.dart: [warning] 30-30: lib/src/extensions/extensions.dart#L30
Added line #L30 was not covered by tests


lib/src/utils.dart: [warning] 129-131: lib/src/utils.dart#L129-L131
Added lines #L129 - L131 were not covered by tests

Dartanalyzer (reported by Codacy) success (4)

lib/src/qs.dart: [warning] 55-55:
Undefined name 'Utils'.


lib/src/utils.dart: [warning] 131-131:
The name 'Undefined' isn't defined, so it can't be used in an 'is' expression.


lib/src/utils.dart: [warning] 94-94:
The name 'Undefined' isn't defined, so it can't be used in an 'is' expression.


lib/src/utils.dart: [warning] 111-111:
The name 'Undefined' isn't defined, so it can't be used in an 'is' expression.

Additional comments not posted (8)
lib/src/methods.dart (1)

6-6: The updated return type of Map<String, dynamic> enhances type safety and clarity.

lib/src/qs.dart (1)

55-55: The use of Utils.merge here raises a concern. Please ensure that Utils is correctly defined and imported in this context to avoid runtime errors.

Verification successful

The Utils.merge and Utils.compact methods are indeed defined in lib/src/utils.dart. Here are the relevant lines:

  • Utils.merge is defined as a static method.
  • Utils.compact is also defined as a static method.

This confirms that the Utils class and its methods are correctly defined and should function as expected in the decode method of lib/src/qs.dart.

  • lib/src/utils.dart: static dynamic merge(
  • lib/src/utils.dart: static Map<String, dynamic> compact(Map<String, dynamic> value) {
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and import of `Utils` in the project.

# Test: Search for the `Utils` definition and import statements. Expect: Definitions and import statements related to `Utils`.
rg --type dart 'Utils'

Length of output: 11348



Script:

#!/bin/bash
# Description: Verify the definition of `Utils.merge` and `Utils.compact` in `lib/src/utils.dart`.

# Test: Extract the definitions of `Utils.merge` and `Utils.compact` methods.
ast-grep --lang dart --pattern 'class Utils { $$$ merge($_, $_) { $$$ } $$$ }' lib/src/utils.dart
ast-grep --lang dart --pattern 'class Utils { $$$ compact($_) { $$$ } $$$ }' lib/src/utils.dart

Length of output: 197



Script:

#!/bin/bash
# Description: Verify the definition of `Utils.merge` and `Utils.compact` in `lib/src/utils.dart`.

# Test: Search for the `merge` and `compact` methods in `lib/src/utils.dart`.
rg 'merge' lib/src/utils.dart
rg 'compact' lib/src/utils.dart

Length of output: 528

lib/src/extensions/decode.dart (1)

16-16: The update to return Map<String, dynamic> in _parseQueryStringValues enhances type safety and consistency with the rest of the project.

test/fixtures/data/empty_test_cases.dart (1)

247-248: The updates in test cases to use string keys are consistent with the changes in the main codebase, ensuring that the tests remain relevant and effective.

Also applies to: 259-260, 295-295

lib/src/utils.dart (1)

90-95: The updates to use Map<String, dynamic> enhance type safety. However, there are repeated concerns about the use of Undefined. Please ensure that Undefined is correctly defined and accessible in this context.

Also applies to: 109-111, 128-137

Verification successful

The Undefined class is correctly defined and accessible in the project. Its usage in the provided code snippet aligns with its intended purpose.

  • lib/src/models/undefined.dart: Definition of Undefined.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and accessibility of `Undefined` in the project.

# Test: Search for the `Undefined` definition. Expect: Definitions related to `Undefined`.
rg --type dart 'Undefined'

Length of output: 6315

test/unit/utils_test.dart (1)

185-186: Ensure consistency in map key types across all test cases.

This test case correctly uses string keys, aligning with the new type requirements for Map<String, dynamic>. Good job on updating this to maintain consistency.

test/unit/decode_test.dart (2)

20-20: Ensure that the test cases reflect the updated type signature of Map<String, dynamic>.

Verification successful

All test cases in decode_test.dart are using string keys as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all test cases in `decode_test.dart` are using string keys as expected.

# Test: Search for non-string keys in test cases. Expect: No occurrences of non-string keys.
rg --type dart --multiline 'QS.decode\((?!.*Map<String, dynamic>).*\)' test/unit/decode_test.dart

Length of output: 355



Script:

#!/bin/bash
# Description: Verify that all test cases in `decode_test.dart` are using string keys as expected.

# Test: Search for `QS.decode` function calls and inspect the keys used in the resulting maps.
ast-grep --lang dart --pattern 'QS.decode($_)' test/unit/decode_test.dart

Length of output: 7501


474-474: Review the handling of list indices and ensure consistency with the new type signature.

Also applies to: 495-495, 508-508, 564-588, 667-688, 708-708, 892-898, 948-948, 961-961, 967-967, 974-980, 992-1001, 1342-1342

test/unit/utils_test.dart Show resolved Hide resolved
test/unit/utils_test.dart Show resolved Hide resolved
test/unit/utils_test.dart Show resolved Hide resolved
lib/src/extensions/extensions.dart Outdated Show resolved Hide resolved
Copy link

@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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f73caf6 and 5fb8e6c.
Files selected for processing (1)
  • test/unit/array_test.dart (1 hunks)
Additional comments not posted (6)
test/unit/array_test.dart (6)

10-15: The test correctly verifies the order of values based on the keys in SplayTreeMap.


21-24: This test appropriately checks the dynamic insertion order and resultant value order in SplayTreeMap.


Line range hint 36-40: The test accurately verifies the behaviour of a growable list initialised with a single null item.


Line range hint 43-49: This test effectively verifies the initialisation and selective replacement in a growable list filled with Undefined.


Line range hint 54-62: The test correctly verifies the removal of Undefined values from a list within a map.


Line range hint 65-73: This test accurately verifies the removal of Undefined values from a nested map structure.

@techouse techouse added this to the v1.2.0 milestone May 18, 2024
@techouse techouse merged commit 5384175 into main May 18, 2024
13 of 15 checks passed
@techouse techouse deleted the chore/decode-to-map-string-dynamic branch May 18, 2024 12:21
techouse added a commit that referenced this pull request May 18, 2024
## 1.2.0

- [FEAT] `QS.decode` returns `Map<String, dynamic>` instead of `Map<dynamic, dynamic>` ([#17](#17))
- [FEAT] add `Uri` extension ([#18](#18))
- [FIX] fix decoding encoded square brackets in key names
@techouse techouse mentioned this pull request May 18, 2024
techouse added a commit that referenced this pull request May 18, 2024
## 1.2.0

- #17
- #18
- fix decoding encoded square brackets in key names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant