Skip to content

docs: improve JSDoc of styleUtils#727

Merged
tbouffard merged 3 commits intomainfrom
docs/improve_styleutils_jsdoc
Mar 25, 2025
Merged

docs: improve JSDoc of styleUtils#727
tbouffard merged 3 commits intomainfrom
docs/improve_styleutils_jsdoc

Conversation

@tbouffard
Copy link
Copy Markdown
Member

@tbouffard tbouffard commented Mar 25, 2025

Also add tests for the parseCssNumber and setStyleFlag functions.

Summary by CodeRabbit

  • Tests

    • Introduced a new test suite for validating the parseCssNumber function with various CSS inputs.
    • Expanded tests for setStyleFlag to ensure proper preservation of style properties and correct handling of multiple flags.
  • Documentation

    • Improved clarity and consistency of comments and documentation strings related to style utility functions.

Also add tests for the `parseCssNumber` and `setStyleFlag` functions.
@tbouffard tbouffard added the documentation Improvements or additions to documentation label Mar 25, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2025

Walkthrough

The changes introduce a new test suite for the parseCssNumber function, validating its behavior with various CSS number inputs, including keywords, numeric strings, invalid strings, and units. The setStyleFlag test suite is expanded to include tests for preserving style properties and combining multiple flags. Additionally, comments and documentation in the styleUtils.ts file have been refined for clarity and consistency, and import statements have been updated to include additional type references. A new public function, parseCssNumber, has also been added.

Changes

File(s) Change Summary
packages/core/tests/…/styleUtils.test.ts Added tests for parseCssNumber covering keywords, numeric strings, and unit values. Expanded tests for setStyleFlag to ensure other style properties are preserved and multiple flags combine correctly; updated import statements with additional types.
packages/core/src/…/styleUtils.ts Refactored and condensed comments/documentation for functions (e.g., removeCursors, parseCssNumber, setPrefixedStyle, and others) to improve clarity without altering functionality.

📜 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 b034760 and 2528dea.

📒 Files selected for processing (2)
  • packages/core/__tests__/util/styleUtils.test.ts (2 hunks)
  • packages/core/src/util/styleUtils.ts (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/util/styleUtils.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/core/__tests__/util/styleUtils.test.ts (1)
packages/core/src/util/styleUtils.ts (2)
  • parseCssNumber (71-87)
  • setStyleFlag (386-407)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (4)
packages/core/__tests__/util/styleUtils.test.ts (4)

20-20: Good addition of the parseCssNumber import.

The import statement correctly includes the new parseCssNumber function from the styleUtils module, which is necessary for the new test suite being added.


44-60: Great comprehensive test suite for parseCssNumber function.

The test suite effectively covers all edge cases for the parseCssNumber function including:

  • CSS keyword values ('thin', 'medium', 'thick')
  • Various numeric strings (positive, negative, decimal)
  • Invalid inputs (empty string, non-numeric text)
  • Values with different units ('px', 'em')

Using test.each is the ideal approach for this parameterized testing and makes the test cases very readable.


63-71: Good test for style property preservation.

This test effectively verifies that setStyleFlag correctly modifies only the targeted property while preserving other style properties. This is an important aspect that wasn't covered in the existing tests.


73-79: Well-structured test for combining multiple flags.

This test properly validates that multiple flags can be combined on the same style property through sequential calls to setStyleFlag. The test confirms the bitwise operations work as expected when applying multiple style flags.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown

@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

🧹 Nitpick comments (2)
packages/core/src/util/styleUtils.ts (2)

68-71: Remove TODO comment since tests have been added

The TODO comment mentions adding tests, but comprehensive tests for the parseCssNumber function have been added in this PR.

-// TODO add tests
/**
 * Parses the given CSS numeric value adding handling for the values thin, medium and thick (2, 4 and 6).
 */

378-379: Remove redundant TODO comment

This TODO comment for adding tests can be removed since tests for both parseCssNumber and setStyleFlag have been implemented in this PR.

-// TODO add tests
-
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ebac765 and b034760.

📒 Files selected for processing (2)
  • packages/core/__tests__/util/styleUtils.test.ts (2 hunks)
  • packages/core/src/util/styleUtils.ts (13 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/core/__tests__/util/styleUtils.test.ts (1)
packages/core/src/util/styleUtils.ts (2)
  • parseCssNumber (72-88)
  • setStyleFlag (389-410)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (5)
packages/core/__tests__/util/styleUtils.test.ts (4)

18-30: Good addition of necessary imports

The imports have been updated to include parseCssNumber and the relevant type definitions needed for the new tests.


48-64: Well-structured comprehensive test suite for parseCssNumber

The test suite for parseCssNumber is thorough and covers all edge cases:

  • CSS keywords ('thin', 'medium', 'thick')
  • Numeric values with and without decimal points
  • Negative numbers
  • Empty strings and invalid values
  • Values with different units ('px', 'em')

Using test.each makes the test suite concise and readable.


67-75: Good test for property preservation

This test ensures that setStyleFlag properly preserves other style properties when modifying a specific flag, which is an important behavior to verify.


77-83: Excellent test for flag combination

This test confirms that multiple style flags can be combined correctly in the fontStyle property, which is crucial for ensuring the bitwise operations in setStyleFlag work as expected.

packages/core/src/util/styleUtils.ts (1)

37-40: JSDoc improvements enhance documentation quality

The documentation changes across multiple functions improve clarity and readability by:

  1. Making descriptions more concise
  2. Clearly indicating default values for parameters
  3. Removing unnecessary line breaks
  4. Improving formatting of examples
  5. Using more consistent language

These changes will make the API documentation more user-friendly.

Also applies to: 91-96, 152-154, 179-184, 222-223, 242-247, 285-294, 306-312, 433-448, 501-502, 530-536

@sonarqubecloud
Copy link
Copy Markdown

@tbouffard tbouffard merged commit 9d259ee into main Mar 25, 2025
@tbouffard tbouffard deleted the docs/improve_styleutils_jsdoc branch March 25, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant