Skip to content

Enum inline fixes#190

Merged
eviltester merged 1 commit into
masterfrom
enum-inline-fixes
Jun 12, 2026
Merged

Enum inline fixes#190
eviltester merged 1 commit into
masterfrom
enum-inline-fixes

Conversation

@eviltester

Copy link
Copy Markdown
Owner

Summary

  • preserve authored whitespace after : for inline schema rules when parsing and rendering rule text
  • extract inline rule detection helpers into a shared inline-schema-rule module used by both parser paths
  • add a regression test covering round-tripping inline separator spacing

Why

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

Copilot AI review requested due to automatic review settings June 12, 2026 11:01
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@eviltester, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2927877e-ae55-4e20-9480-4b1f58ff7e72

📥 Commits

Reviewing files that changed from the base of the PR and between d54008b and dcdfc9c.

📒 Files selected for processing (4)
  • packages/core/js/data_generation/inline-schema-rule.js
  • packages/core/js/data_generation/rulesParser.js
  • packages/core/src/index.js
  • packages/core/src/tests/data_generation/unit/rulesParser.test.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enum-inline-fixes

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 startsConstraint and inline-rule detection into a shared inline-schema-rule module and reuse it from both RulesParser and the src/index.js parsing 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-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes inline schema rules losing their authored whitespace during a parse/render round-trip by capturing the exact characters between : and the rule value as the separator token instead of hard-coding ": ". It also consolidates the two independent copies of looksLikeInlineRuleSpec / startsConstraint into a new shared inline-schema-rule.js module.

  • inline-schema-rule.js — new shared module that exports startsConstraint and looksLikeInlineRuleSpec, eliminating the duplicate implementations in rulesParser.js and src/index.js.
  • rulesParser.jsparseInlineRuleDefinition now stores separator as : plus any leading whitespace from the raw source, so Name:value and Role: value both round-trip faithfully; the fallback token.separator || ': ' in the renderer preserves backward compatibility with tokens that predate this field.
  • Regression test — covers no-space (:) and multi-space (": ") separator variants in a single round-trip assertion.

Confidence Score: 5/5

Safe 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

Filename Overview
packages/core/js/data_generation/inline-schema-rule.js New shared module that extracts startsConstraint and looksLikeInlineRuleSpec from both rulesParser.js and src/index.js; logic is identical to what was in both places.
packages/core/js/data_generation/rulesParser.js Removes duplicate helper functions, imports them from the shared module, and preserves the original authored whitespace after ':' in the separator token instead of hard-coding ': '.
packages/core/src/index.js Removes the locally-defined looksLikeInlineSchemaRule and inline startsConstraint usage, replacing both with imports from the new shared module; behaviour is unchanged.
packages/core/src/tests/data_generation/unit/rulesParser.test.js Adds a regression test that verifies both the zero-space and multi-space separator variants are preserved through a parse/render round-trip.

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)' ✓"]
Loading

Reviews (1): Last reviewed commit: "enum inline fixes" | Re-trigger Greptile

@eviltester eviltester merged commit 82d778c into master Jun 12, 2026
15 checks passed
@eviltester eviltester deleted the enum-inline-fixes branch June 13, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants