-
Notifications
You must be signed in to change notification settings - Fork 2k
add: multiline support in response example #6358
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
add: multiline support in response example #6358
Conversation
WalkthroughThese changes add comprehensive multiline value support to the Bruno language parser and serializer. The parser now dynamically detects indentation in multiline blocks, grammar changes enable multiline content for name and description properties, and the serializer uses a utility function to consistently format values throughout various BRU sections. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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 (3)
packages/bruno-lang/v2/src/common/attributes.js (1)
42-47: Triple-quoted multiline dedent is a solid improvement; consider using minimal indent across all content linesUsing the first non-empty line’s indent fixes many cases, but if later lines are less-indented than the first,
slice(indent)will strip real content from those lines. Computing the minimal leading whitespace across all non-empty lines avoids that and is still compatible with your current usage.You could refactor this block along these lines:
- const lines = multilineString.split('\n'); - // Detect indentation from first non-empty content line - const firstContentLine = lines.find((line) => line.trim().length > 0); - const indent = firstContentLine ? firstContentLine.match(/^(\s*)/)[1].length : 0; - return lines - .map((line) => line.slice(indent)) - .join('\n'); + const lines = multilineString.split('\n'); + // Detect minimal indentation from all non-empty content lines + const contentLines = lines.filter((line) => line.trim().length > 0); + const indent = contentLines.length + ? Math.min(...contentLines.map((line) => line.match(/^(\s*)/)[1].length)) + : 0; + return lines + .map((line) => line.slice(Math.min(indent, line.length))) + .join('\n');packages/bruno-lang/v2/src/example/jsonToBru.js (1)
1-1: Consolidating multiline formatting throughgetValueStringlooks good; consider hardening it for non-string valuesRouting all example-facing values (name/description, params, headers, form-urlencoded, multipart text, response headers) through
getValueStringis a nice way to keep multiline behavior consistent, andindentStringCustomkeeps the BRU layout readable.One thing to watch:
getValueString(inutils.js) currently assumesvalueis a string and usesif (!value)plusvalue.includes(...). If any of these call sites ever pass a number/boolean (or other non-string), you’ll get a runtime error or silently drop falsy-but-legit values.You can make
getValueStringmore robust without changing the call sites, for example:-const getValueString = (value) => { - // Handle null, undefined, and empty strings - if (!value) { - return ''; - } - - const hasNewLines = value.includes('\n') || value.includes('\r'); - - if (!hasNewLines) { - return value; - } - - // Wrap multiline values in triple quotes with 2-space indentation - return `'''\n${indentString(value)}\n'''`; -}; +const getValueString = (value) => { + // Handle null/undefined explicitly and preserve current behavior for '' + if (value === null || value === undefined || value === '') { + return ''; + } + + const stringValue = typeof value === 'string' ? value : String(value); + + const hasNewLines = stringValue.includes('\n') || stringValue.includes('\r'); + + if (!hasNewLines) { + return stringValue; + } + + // Wrap multiline values in triple quotes with 2-space indentation + return `'''\n${indentString(stringValue)}\n'''`; +};This keeps existing behavior for empty strings, but avoids exceptions and data loss if callers ever pass non-string scalar values.
Also applies to: 16-26, 36-42, 60-82, 110-120, 134-152, 190-193
packages/bruno-lang/v2/tests/examples/multiline-values.spec.js (1)
1-504: Multiline example tests are thorough and exercise all key pathsThis suite does a good job covering serialization, parsing, and round-trip behavior for multiline values across headers, params, form-urlencoded, multipart, descriptions, and edge cases (empty lines, special chars, CRLF, disabled fields). It gives strong confidence in the new multiline handling.
If you want to go a bit further, you could extend the carriage-return test to also run
bruToJsonand assert the final description string, but the current checks are already solid.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/bruno-lang/v2/src/common/attributes.js(1 hunks)packages/bruno-lang/v2/src/example/bruToJson.js(2 hunks)packages/bruno-lang/v2/src/example/jsonToBru.js(8 hunks)packages/bruno-lang/v2/tests/examples/multiline-values.spec.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CODING_STANDARDS.md)
**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions.() => {}is good
No space between function name and parentheses.func()notfunc ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
packages/bruno-lang/v2/tests/examples/multiline-values.spec.jspackages/bruno-lang/v2/src/common/attributes.jspackages/bruno-lang/v2/src/example/jsonToBru.jspackages/bruno-lang/v2/src/example/bruToJson.js
🧠 Learnings (3)
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created
Applied to files:
packages/bruno-lang/v2/tests/examples/multiline-values.spec.js
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
Applied to files:
packages/bruno-lang/v2/src/common/attributes.js
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use 2 spaces for indentation. No tabs, just spaces
Applied to files:
packages/bruno-lang/v2/src/example/jsonToBru.js
🧬 Code graph analysis (3)
packages/bruno-lang/v2/tests/examples/multiline-values.spec.js (3)
packages/bruno-lang/v2/src/example/bruToJson.js (1)
require(3-3)packages/bruno-lang/v2/src/example/jsonToBru.js (3)
require(1-1)json(30-30)bru(34-34)packages/bruno-lang/v2/src/common/attributes.js (1)
lines(42-42)
packages/bruno-lang/v2/src/common/attributes.js (2)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)
line(631-631)packages/bruno-lang/v2/src/example/jsonToBru.js (1)
indent(21-21)
packages/bruno-lang/v2/src/example/jsonToBru.js (1)
packages/bruno-lang/v2/src/utils.js (1)
getValueString(34-48)
⏰ 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). (6)
- GitHub Check: Playwright E2E Tests
- GitHub Check: Unit Tests
- GitHub Check: SSL Tests - Linux
- GitHub Check: CLI Tests
- GitHub Check: SSL Tests - Windows
- GitHub Check: SSL Tests - macOS
🔇 Additional comments (1)
packages/bruno-lang/v2/src/example/bruToJson.js (1)
54-55: Root name/description value handling looks correct for multiline supportSwitching
nameanddescriptionto use the fullvaluerule (includingmultilinetextblock) and then trimmingvalue.astwhen it’s a string is a good fit with the new multiline semantics. It keeps existing single-line behavior while allowing triple-quoted blocks without leaking raw delimiters or indentation.Also applies to: 79-87
|
#6325 related |
|
Closing this as this has already been handled in this PR: #6325 |
Description
Fixed multiline value handling in examples for both
bruToJsonandjsonToBruconversions.Contribution Checklist:
Screen.Recording.2025-12-09.at.12.34.56.PM.mov
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.