Skip to content

Conversation

@pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Dec 9, 2025

Description

Fixed multiline value handling in examples for both bruToJson and jsonToBru conversions.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
Screen.Recording.2025-12-09.at.12.34.56.PM.mov

Summary by CodeRabbit

  • New Features

    • Enhanced support for multiline values across headers, parameters, and form fields.
    • Names and descriptions now support multiline content.
    • Improved dynamic indentation detection for multiline blocks.
  • Tests

    • Added comprehensive test coverage for multiline value handling across various formats and round-trip scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Walkthrough

These 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

Cohort / File(s) Summary
Parser and Grammar Updates
packages/bruno-lang/v2/src/common/attributes.js, packages/bruno-lang/v2/src/example/bruToJson.js
Replaced fixed 4-space indentation trimming with dynamic indentation detection in multiline quote blocks. Updated grammar to allow multiline values for name and description properties via value instead of valuechar*, with corresponding AST handling.
Serializer Refactoring
packages/bruno-lang/v2/src/example/jsonToBru.js
Introduced getValueString utility for consistent value formatting across all BRU sections (params, headers, body, response, etc.). Changed indentation default from 4 to 2 spaces. Replaced direct value interpolations with function calls throughout.
Test Coverage
packages/bruno-lang/v2/tests/examples/multiline-values.spec.js
Added comprehensive test suite covering multiline value serialization and parsing for headers, query params, form data, and descriptions. Includes round-trip integrity tests and edge case handling (empty lines, special characters, carriage returns, disabled fields).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring attention:
    • Verify dynamic indentation detection logic correctly handles various edge cases (inconsistent indentation, mixed whitespace)
    • Confirm getValueString utility is applied consistently across all value assignments in jsonToBru.js
    • Validate that indentation default change (4 → 2 spaces) aligns with intended output formatting
    • Check AST handling in bruToJson.js properly distinguishes between string and AST node inputs

Suggested labels

size/M

Suggested reviewers

  • lohit-bruno
  • naman-bruno
  • helloanoop

Poem

Multiline musings now flow free,
Dynamic indents set at last,
Parse and stringify in harmony—
Quotes preserve what came before. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'multiline support in response example' but the PR addresses multiline support across multiple BRU structures (headers, query params, formUrlEncoded, multipartForm, descriptions) and affects both bruToJson and jsonToBru conversions comprehensively, not just response examples. Revise title to reflect the broader scope, such as 'add: multiline value support in BRU format' or 'add: multiline value handling across BRU serialization and parsing'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 lines

Using 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 through getValueString looks good; consider hardening it for non-string values

Routing all example-facing values (name/description, params, headers, form-urlencoded, multipart text, response headers) through getValueString is a nice way to keep multiline behavior consistent, and indentStringCustom keeps the BRU layout readable.

One thing to watch: getValueString (in utils.js) currently assumes value is a string and uses if (!value) plus value.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 getValueString more 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 paths

This 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 bruToJson and assert the final description string, but the current checks are already solid.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e855e5 and fcc0908.

📒 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() not func ()
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.js
  • packages/bruno-lang/v2/src/common/attributes.js
  • packages/bruno-lang/v2/src/example/jsonToBru.js
  • packages/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 support

Switching name and description to use the full value rule (including multilinetextblock) and then trimming value.ast when 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

@sanish-bruno
Copy link
Collaborator

#6325 related

@pooja-bruno pooja-bruno closed this Dec 9, 2025
@pooja-bruno pooja-bruno deleted the add/multiline-support-in-response-example branch December 9, 2025 07:24
@pooja-bruno
Copy link
Collaborator Author

Closing this as this has already been handled in this PR: #6325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants