-
-
Notifications
You must be signed in to change notification settings - Fork 476
fix(ui/cli/setup-init/compare-nodes): more styling format support #1594
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
Conversation
…semicolons] - add tests
🦋 Changeset detectedLatest commit: f022631 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughA new utility function, Changes
Sequence Diagram(s)sequenceDiagram
participant SetupInit
participant CompareNodesUtil
participant FileSystem
SetupInit->>FileSystem: Read target file as AST
SetupInit->>FileSystem: Read template file as AST
SetupInit->>CompareNodesUtil: compareNodes(targetAST, templateAST)
CompareNodesUtil-->>SetupInit: Boolean result
alt ASTs differ
SetupInit->>FileSystem: Overwrite target file
else ASTs are equal
SetupInit-->>FileSystem: Do nothing
end
Estimated code review effort2 (~15 minutes) Suggested labels
Suggested reviewers
Poem
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
packages/ui/src/cli/commands/setup-init.tsOops! Something went wrong! :( ESLint: 8.57.0 ESLint couldn't find the plugin "eslint-plugin-react". (The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. packages/ui/src/cli/utils/compare-nodes.test.tsOops! Something went wrong! :( ESLint: 8.57.0 ESLint couldn't find the plugin "eslint-plugin-react". (The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. packages/ui/src/cli/utils/compare-nodes.tsOops! Something went wrong! :( ESLint: 8.57.0 ESLint couldn't find the plugin "eslint-plugin-react". (The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (1)
packages/ui/src/cli/utils/compare-nodes.ts (1)
22-33: Consider adding type safety for the string literal checkThe string literal normalization logic is correct but could benefit from stronger type checking to prevent runtime errors.
Consider this more type-safe approach:
// Handle string literals specially - normalize quotes if ( - "type" in a && - "type" in b && + typeof a === "object" && a !== null && "type" in a && + typeof b === "object" && b !== null && "type" in b && (a.type === "StringLiteral" || a.type === "Literal") && (b.type === "StringLiteral" || b.type === "Literal") && "value" in a && "value" in b && typeof a.value === "string" && typeof b.value === "string" ) { return a.value === b.value; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
.changeset/funny-lights-march.md(1 hunks)packages/ui/src/cli/commands/setup-init.ts(1 hunks)packages/ui/src/cli/utils/compare-nodes.test.ts(1 hunks)packages/ui/src/cli/utils/compare-nodes.ts(1 hunks)
🧬 Code Graph Analysis (1)
packages/ui/src/cli/utils/compare-nodes.test.ts (1)
packages/ui/src/cli/utils/compare-nodes.ts (1)
compareNodes(4-47)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ui/src/cli/utils/compare-nodes.test.ts (1)
packages/ui/src/cli/utils/compare-nodes.ts (1)
compareNodes(4-47)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: 🧰 Build
🔇 Additional comments (11)
packages/ui/src/cli/utils/compare-nodes.ts (4)
4-10: LGTM: Robust early return handlingThe function correctly handles identity comparison and null/undefined cases, providing a solid foundation for the recursive comparison logic.
11-16: LGTM: Correct array comparison logicThe array handling properly checks type, length, and performs element-wise recursive comparison. The logic is sound and handles empty arrays correctly.
43-47: LGTM: Solid recursive object comparisonThe object comparison logic correctly checks key count equality and recursively compares all properties. The type assertions are appropriate for this use case.
36-41: Filter covers all relevant AST metadata propertiesA search across the codebase for common AST metadata keys (
.source,.raw,.innerComments,.extra, etc.) returned no additional properties that need excluding. The existing filter—start,end,loc,range,tokens,comments,leadingComments, andtrailingComments—is complete for our parser output..changeset/funny-lights-march.md (1)
1-12: LGTM: Clear and accurate changeset documentationThe changeset properly describes the patch-level improvements to compareNodes functionality and includes mention of the added test coverage.
packages/ui/src/cli/commands/setup-init.ts (1)
4-4: LGTM: Clean refactoring to use centralized utilityThe extraction of compareNodes to a dedicated utility module improves code organization and reusability. The import is correctly placed and follows TypeScript conventions.
packages/ui/src/cli/utils/compare-nodes.test.ts (5)
5-13: LGTM: Comprehensive basic equality testsThe basic equality tests cover all primitive types and edge cases including null/undefined comparisons and type mismatches.
22-26: LGTM: Core functionality test for quote normalizationThis test directly validates the key feature of the PR - treating different quote styles as equivalent in string literals.
72-78: Excellent edge case coverage for template literalsGood test ensuring template literals are correctly treated as different from regular string literals, maintaining semantic accuracy.
100-120: Thorough semicolon handling verificationThe tests comprehensively cover semicolon presence/absence across different JavaScript constructs - variable declarations, multiple statements, objects, and functions.
122-179: Comprehensive trailing comma test coverageExcellent coverage of trailing commas in various contexts: single-line vs multi-line objects/arrays, and nested structures. This thoroughly validates the PR's key functionality.
Changes
Summary by CodeRabbit