Enum inline fixes#190
Conversation
|
Warning Review limit reached
More reviews will be available in 51 minutes and 32 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR improves round-tripping of inline schema rules by preserving the exact whitespace authored after the : separator (e.g., Role: enum(...)), and consolidates inline-rule detection logic into a shared helper module used by both parsing paths.
Changes:
- Preserve authored whitespace after
:when parsing inline rule definitions so rendering matches the original text exactly. - Extract
startsConstraintand inline-rule detection into a sharedinline-schema-rulemodule and reuse it from bothRulesParserand thesrc/index.jsparsing path. - Add a regression test to verify inline separator spacing is retained through parse/render.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/core/src/tests/data_generation/unit/rulesParser.test.js | Adds a regression test asserting per-rule separator tokens and full round-trip text equality. |
| packages/core/src/index.js | Replaces duplicated inline-rule/constraint detection with shared helpers. |
| packages/core/js/data_generation/rulesParser.js | Captures and stores the exact post-: whitespace for inline rules via a computed separator. |
| packages/core/js/data_generation/inline-schema-rule.js | New shared module containing startsConstraint and looksLikeInlineRuleSpec used across both parser paths. |
Greptile SummaryThis PR fixes inline schema rules losing their authored whitespace during a parse/render round-trip by capturing the exact characters between
Confidence Score: 5/5Safe to merge — the change is a targeted whitespace-preservation fix with a matching regression test, and the shared-module refactor is a pure extraction with no logic changes. The separator is now captured directly from the raw source characters, which is correct for zero-space, single-space, and multi-space variants. The fallback token.separator || ': ' in the renderer handles any older serialized tokens that lack the field. The two previously-separate copies of the detection helpers were byte-for-byte identical to the new shared module, so no behaviour has changed in either consumer. The new regression test covers both edge cases (no space and multiple spaces) in a single round-trip assertion. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Input schema text\ne.g. 'Role: enum(admin,user)'"] --> B["parseInlineRuleDefinition(line)"]
B --> C["rawRulePortion = source.slice(index + 1)\n= ' enum(admin,user)'"]
C --> D["rule = rawRulePortion.trim()\n= 'enum(admin,user)'"]
D --> E{"looksLikeInlineRuleSpec(rule)?"}
E -- "No" --> F["continue to next ':' index"]
E -- "Yes" --> G["leadingWhitespaceLength = 3"]
G --> H["separator = ': '"]
H --> I["Schema token { kind:'rule', separator:': ', inline:true }"]
I --> J["renderSpecFromRulesWithTokens()"]
J --> K["'Role: enum(admin,user)' ✓"]
Reviews (1): Last reviewed commit: "enum inline fixes" | Re-trigger Greptile |
Summary
:for inline schema rules when parsing and rendering rule textinline-schema-rulemodule used by both parser pathsWhy
The remaining local change fixes inline enum-style schema definitions that should preserve authored separator spacing instead of normalizing it during a parse/render round trip.
Impact
Users keep their original inline rule formatting, and the inline rule detection logic now lives in one shared place instead of being duplicated.
Root Cause
Inline rule parsing rebuilt rule tokens with a hard-coded
": "separator, which lost the original spacing authored in the schema text.Validation
pnpm run verify:local