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

Feat: Rules - Props type #131 #132

Merged
merged 2 commits into from
Nov 28, 2024
Merged

Feat: Rules - Props type #131 #132

merged 2 commits into from
Nov 28, 2024

Conversation

black7375
Copy link
Contributor

@black7375 black7375 commented Nov 28, 2024

Description

This is the type for rules's prop.

Related Issue

Summary by CodeRabbit

  • New Features

    • Enhanced type definitions for handling complex properties in CSS rules.
    • Added new types to improve flexibility in property definitions.
  • Bug Fixes

    • Updated existing types to ensure better type-checking and usability.
  • Documentation

    • Improved export visibility of key types and interfaces for broader accessibility.

Additional context

The API types handled by Prop have been reduced due to TypeScript inference and autocompletion.

Checklist

Copy link

changeset-bot bot commented Nov 28, 2024

⚠️ No Changeset found

Latest commit: d0991f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes in this pull request focus on enhancing type definitions within the CSS rules handling system. Key modifications include the introduction of a new generic type parameter Props in the rules function, allowing for complex property definitions. The PatternOptions type is also updated to accommodate this new parameter, alongside the addition of several new types related to property definitions. Furthermore, an export statement for NonNullableString is added, and the ResolvedProperties interface is made exportable to improve accessibility across modules.

Changes

File Path Change Summary
packages/css/src/rules/index.ts Updated rules function signature to include new generic type parameter Props for complex property definitions.
packages/css/src/rules/types.ts Updated PatternOptions type to include Props, added new types: PropTarget, ComplexPropDefinitions, etc.
packages/transform-to-vanilla/src/index.ts Added export for NonNullableString type from ./types/string module.
packages/transform-to-vanilla/src/types/style-rule.ts Changed ResolvedProperties interface from local to exported to enhance accessibility.

Possibly related PRs

Suggested labels

dependencies

🐇 In the garden of code, I hop with glee,
New types and rules, oh what a spree!
Props now dance in the function's embrace,
Complex definitions, a beautiful space.
With exports and interfaces, we grow and we play,
Enhancing our types, hip-hip-hooray! 🌼

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error Couldn't find any versions for "eslint-config-custom" that matches "workspace:^"


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

Copy link
Contributor

Triggered from #132 by @​black7375.

Checking if we can fast forward main (c1a1e2d) to props-type (d0991f5).

Target branch (main):

commit c1a1e2d6a1af293560bda8961dbbe05b3f30189b (HEAD -> main, origin/main, origin/HEAD)
Author: JeongJun <[email protected]>
Date:   Mon Oct 7 19:59:25 2024 +0900

    Test: RuntimeFn Type Test
    
    Co-authored-by: alstjr7375 <[email protected]>

Pull request (props-type):

commit d0991f539e651abf074aea91ca2dcd3078a0cd08 (pull_request/props-type)
Author: alstjr7375 <[email protected]>
Date:   Sat Nov 23 22:51:35 2024 +0900

    Fix: Rules - Prop expression type limitation #131

It is possible to fast forward main (c1a1e2d) to props-type (d0991f5). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to props-type.

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

🧹 Outside diff range and nitpick comments (4)
packages/transform-to-vanilla/src/types/style-rule.ts (1)

247-248: LGTM! Consider adding JSDoc documentation.

The export modification improves type accessibility and aligns with the PR objectives. The interface properly extends Properties with appropriate type parameters.

Consider adding JSDoc documentation to describe the purpose and usage of this interface:

+/**
+ * Resolves CSS properties to either numeric values or non-nullable strings.
+ * This interface is used to provide type safety for CSS property values in style rules.
+ */
export interface ResolvedProperties
  extends Properties<number | NonNullableString> {}
packages/css/src/rules/index.ts (1)

Line range hint 109-411: Consider adding test cases for Props type parameter

While the existing tests thoroughly cover the core functionality, consider adding test cases that specifically verify the new Props type parameter behavior.

Would you like me to help generate test cases for the Props type parameter?

packages/css/src/rules/types.ts (2)

65-75: Consider documenting complex type definitions for maintainability

The introduction of PropTarget, ComplexPropDefinitions, and PropDefinition adds significant flexibility in defining complex property configurations. However, their complexity may pose challenges for future maintainers or new contributors. Consider adding comprehensive comments or documentation to explain the purpose and usage of these types.


603-630: Extend test coverage for edge cases in Props

While the added test cases cover various usages of the props field, consider adding tests for edge cases, such as invalid inputs or unexpected property combinations, to ensure the robustness of the new functionality.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c1a1e2d and d0991f5.

📒 Files selected for processing (4)
  • packages/css/src/rules/index.ts (2 hunks)
  • packages/css/src/rules/types.ts (6 hunks)
  • packages/transform-to-vanilla/src/index.ts (1 hunks)
  • packages/transform-to-vanilla/src/types/style-rule.ts (1 hunks)
🔇 Additional comments (8)
packages/transform-to-vanilla/src/index.ts (1)

8-8: LGTM! Verify the imported type implementation.

The new type export follows TypeScript best practices and aligns with the PR's objective of improving type definitions.

Let's verify the implementation of the imported type:

✅ Verification successful

Type implementation and usage verified successfully

The NonNullableString type is properly implemented in src/types/string.ts as string & NonNullable<unknown> and is being used consistently across the codebase, particularly in style rule types and font-face rule definitions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the NonNullableString type implementation and its usage

# Check the implementation of NonNullableString
ast-grep --pattern 'type NonNullableString = $_'

# Check where NonNullableString is being used
rg -t ts "NonNullableString"

Length of output: 3675

packages/css/src/rules/index.ts (3)

17-18: LGTM: Type imports are well-organized

The addition of ComplexPropDefinitions and PropTarget types enhances the type safety of the rules function.


31-35: LGTM: Type parameter addition improves type safety

The addition of the Props generic type parameter enhances type safety while maintaining backward compatibility.


Line range hint 71-72: Verify if @ts-expect-error can be removed

The comment indicates a temporary type issue. Let's verify if this can be resolved with the new type definitions.

✅ Verification successful

@ts-expect-error can be removed

The type system is now properly defined with:

  • PatternResult type having a well-defined variantClassNames property of type VariantsClassNames<Variants>
  • ConditionalVariants type correctly handling both regular variants and toggle variants
  • The type errors in types.ts are intentional test cases and not related to the PatternResult type definition
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if PatternResult type is now properly defined
# and if @ts-expect-error can be removed

# Search for PatternResult type definition
ast-grep --pattern 'type PatternResult<$_> = $_'

# Search for related type definitions that might affect PatternResult
rg -l "PatternResult|variantClassNames" --type ts

Length of output: 692


Script:

#!/bin/bash
# Let's check the actual usage context of PatternResult in index.ts
rg -A 5 -B 5 "@ts-expect-error" packages/css/src/rules/index.ts

# Also check how PatternResult is used in createRuntimeFn.ts for comparison
ast-grep --pattern 'PatternResult<$_>'

Length of output: 613


Script:

#!/bin/bash
# Let's check the type definition of CombinedVariants and related types
rg -A 3 "type CombinedVariants" packages/css/src/rules/index.ts

# And check the definition of ConditionalVariants
ast-grep --pattern 'type ConditionalVariants<$_> = $_'

# Also check if there are any type errors in the file
rg "type.*error" packages/css/src/rules/index.ts

Length of output: 343


Script:

#!/bin/bash
# Let's check the definition of ConditionalVariants in types.ts
rg -A 5 "ConditionalVariants" packages/css/src/rules/types.ts

# And check how variantClassNames is used in the PatternResult type
rg -A 5 "variantClassNames" packages/css/src/rules/types.ts

# Check for any type errors or related comments in types.ts
rg "error|TODO|FIXME" packages/css/src/rules/types.ts

Length of output: 1669

packages/css/src/rules/types.ts (4)

1-6: Imports are appropriate and necessary

The imported types (ComplexCSSRule, CSSRule, ResolvedProperties, NonNullableString) are used effectively in the code and are essential for the new type definitions and enhancements.


18-23: Utility type UnionToIntersection is correctly implemented

The UnionToIntersection utility type is accurately defined to convert a union type into an intersection type, which is beneficial for complex type manipulations later in the code.


77-113: Type definitions are well-structured and handle various cases effectively

The complex type definitions for PropDefinitionOutput and related utility types are carefully constructed to handle multiple scenarios in property definitions, ensuring robust type checking and flexibility.


139-143: ⚠️ Potential issue

Verify that adding Props generic parameter does not introduce breaking changes

Adding the new generic parameter Props to PatternOptions might affect existing code that uses PatternOptions without specifying Props. It is crucial to ensure that default values are provided or existing usages are updated to prevent potential breaking changes in the codebase.

Run the following script to find all usages of PatternOptions and check for potential issues:

✅ Verification successful

No breaking changes introduced by the Props generic parameter

The verification shows that:

  1. The Props parameter is defined as optional with undefined as a valid type: Props extends ComplexPropDefinitions<PropTarget> | undefined
  2. In the implementation, it has a default value: Props extends ComplexPropDefinitions<PropTarget> | undefined = undefined
  3. The props field in the PatternOptions type is also optional: props?: Props
  4. All usages found in the codebase are within test cases and the core implementation, where the Props parameter is properly handled

Since the parameter is optional with proper default values, and the implementation maintains backward compatibility, this change does not introduce breaking changes to existing code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of `PatternOptions` that may be affected by the new `Props` parameter.

# Find all TypeScript files using `PatternOptions` without the `Props` parameter
rg 'PatternOptions<[^,]*,[^,]*>' -t ts --word-regexp

Length of output: 54


Script:

#!/bin/bash
# Let's try a broader search to find all usages of PatternOptions
rg "PatternOptions" -t ts -A 2 -B 2

Length of output: 3166


Script:

#!/bin/bash
# Let's also check the type definition to understand if Props is optional
ast-grep --pattern 'type PatternOptions<$_,$_,$_> = $_'

Length of output: 1133


Script:

#!/bin/bash
# Search for any pattern function calls that might use PatternOptions
rg "pattern\(" -t ts -A 2 -B 2

Length of output: 32

@black7375
Copy link
Contributor Author

/fast-forward

Copy link
Contributor

Triggered from #132 (comment) by @​black7375.

Trying to fast forward main (c1a1e2d) to props-type (d0991f5).

Target branch (main):

commit c1a1e2d6a1af293560bda8961dbbe05b3f30189b (HEAD -> main, origin/main, origin/HEAD)
Author: JeongJun <[email protected]>
Date:   Mon Oct 7 19:59:25 2024 +0900

    Test: RuntimeFn Type Test
    
    Co-authored-by: alstjr7375 <[email protected]>

Pull request (props-type):

commit d0991f539e651abf074aea91ca2dcd3078a0cd08 (pull_request/props-type)
Author: alstjr7375 <[email protected]>
Date:   Sat Nov 23 22:51:35 2024 +0900

    Fix: Rules - Prop expression type limitation #131

Fast forwarding main (c1a1e2d) to props-type (d0991f5).

$ git push origin d0991f539e651abf074aea91ca2dcd3078a0cd08:main
To https://github.com/mincho-js/mincho.git
   c1a1e2d..d0991f5  d0991f539e651abf074aea91ca2dcd3078a0cd08 -> main

@github-actions github-actions bot merged commit d0991f5 into main Nov 28, 2024
7 checks passed
@github-actions github-actions bot deleted the props-type branch November 28, 2024 14:25
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant