Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Mar 26, 2025

Negate the result of the existing isNullish function instead.

Summary by CodeRabbit

  • Refactor
    • Enhanced consistency for handling missing or undefined values, ensuring more predictable behavior in visual components.
  • Style
    • Modernized variable declarations to improve code clarity and maintainability.

Negate the result of the existing `isNullish` function instead.
@tbouffard tbouffard added the refactor Code refactoring label Mar 26, 2025
@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2025

Walkthrough

This PR removes the exported isNotNullish function from the utilities module and updates its usage across multiple files. Calls formerly using isNotNullish are now replaced with inverted checks using isNullish. These changes affect view-layer methods—including alternate text handling, attribute checking, shape transformation, and stroke width parsing. Minor improvements, such as updating variable declarations from var to const in one file, are also included.

Changes

File(s) Change Summary
packages/core/.../Utils.ts Removed the exported isNotNullish function and its accompanying documentation.
packages/core/.../[SvgCanvas2D.ts, Cell.ts, Shape.ts, StencilShape.ts] Updated import statements to replace isNotNullish with isNullish; modified conditions by inverting null checks (using !isNullish) in methods (e.g., getAlternateText, createAlternateContent, hasAttribute, cloneValue, shape transformation, stroke width parsing); also refined variable declarations in Cell.ts (from var to const).

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SvgCanvas2D
    Caller->>SvgCanvas2D: getAlternateText(str)
    SvgCanvas2D->>SvgCanvas2D: Evaluate condition (!isNullish(str))
    alt str is not nullish
        SvgCanvas2D-->>Caller: Return foAltText
    else str is nullish
        SvgCanvas2D-->>Caller: Return default text (or undefined)
    end
Loading

Possibly Related PRs


📜 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 2b916d6 and 9f1f2a1.

📒 Files selected for processing (5)
  • packages/core/src/util/Utils.ts (0 hunks)
  • packages/core/src/view/canvas/SvgCanvas2D.ts (4 hunks)
  • packages/core/src/view/cell/Cell.ts (5 hunks)
  • packages/core/src/view/geometry/Shape.ts (2 hunks)
  • packages/core/src/view/geometry/node/StencilShape.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/util/Utils.ts
🧰 Additional context used
🧬 Code Definitions (4)
packages/core/src/view/geometry/Shape.ts (1)
packages/core/src/util/Utils.ts (1)
  • isNullish (60-61)
packages/core/src/view/canvas/SvgCanvas2D.ts (2)
packages/core/src/util/Utils.ts (1)
  • isNullish (60-61)
packages/core/src/view/canvas/XmlCanvas2D.ts (1)
  • text (861-922)
packages/core/src/view/geometry/node/StencilShape.ts (1)
packages/core/src/util/Utils.ts (1)
  • isNullish (60-61)
packages/core/src/view/cell/Cell.ts (1)
packages/core/src/util/Utils.ts (1)
  • isNullish (60-61)
🔇 Additional comments (11)
packages/core/src/view/geometry/node/StencilShape.ts (2)

23-23: Import statement updated to remove redundant utility function.

The import statement has been updated to use isNullish instead of isNotNullish, aligning with the PR objective to remove the redundant utility function.


134-134: Logic correctly converted to use negated isNullish.

The code has been updated to use !isNullish(sw) instead of isNotNullish(sw) while maintaining the original behavior. This is a clean change that preserves the same conditional logic.

packages/core/src/view/canvas/SvgCanvas2D.ts (3)

19-19: Import statement updated to remove redundant utility function.

The import statement has been updated to use isNullish instead of isNotNullish, aligning with the PR objective to remove the redundant utility function.


425-425: Logic correctly converted to use negated isNullish.

The code in the getAlternateText method has been updated to use !isNullish(str) instead of isNotNullish(str) while maintaining the original behavior.


463-463: Logic correctly converted to use negated isNullish.

The code in the createAlternateContent method has been updated to use !isNullish(text) instead of isNotNullish(text) while maintaining the original behavior.

packages/core/src/view/geometry/Shape.ts (2)

20-20: Import statement updated to remove redundant utility function.

The import statement has been updated to use isNullish instead of isNotNullish, aligning with the PR objective to remove the redundant utility function.


652-652: Logic correctly converted to use negated isNullish.

The code has been updated to use !isNullish(c.state.transform) instead of isNotNullish(c.state.transform) while maintaining the original behavior.

packages/core/src/view/cell/Cell.ts (4)

24-24: Import statement updated to remove redundant utility function.

The import statement has been updated to use isNullish instead of isNotNullish, aligning with the PR objective to remove the redundant utility function.


38-60: Code style improvements with template literals.

The code examples in the documentation comments have been updated to use consistent formatting and code style, which improves readability.


565-565: Logic correctly converted to use negated isNullish.

The code in the hasAttribute method has been updated to use !isNullish(userObject.getAttribute?.(name)) instead of isNotNullish(userObject.getAttribute?.(name)) while maintaining the original behavior.


614-617: Logic correctly converted to use negated isNullish.

The code in the cloneValue method has been updated to use !isNullish(value) and !isNullish(value.nodeType) instead of their respective isNotNullish counterparts, while maintaining the original behavior.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit 2a4ecd9 into main Mar 26, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/remove_isNotNullish branch March 26, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant