Files
vibe-kanban/frontend/src/utils/string.ts
Louis Knight-Webb bd96b7c18b Review comments should contain line of code (vibe-kanban) (#731)
* **Changes**
- Capture the relevant code line in each draft/comment so it’s stored alongside metadata and rendered in the Markdown output, with backtick-safe formatting for inline/triple code blocks (`frontend/src/contexts/ReviewProvider.tsx:4-107`).
- Pull the plain line text from the diff when a comment widget opens and stash it on the draft before saving (`frontend/src/components/DiffCard.tsx:140-155`).
- Pass the captured line through when persisting a new review comment (`frontend/src/components/diff/CommentWidgetLine.tsx:28-34`).

- Tests: `pnpm run check`

Consider spot-checking the review markdown in the UI to confirm the new code line snippet displays as expected.

* Line capture now trims trailing newline characters so inline code renders on a single line (`frontend/src/components/DiffCard.tsx:140-154`). `pnpm run check` still passes. Let me know if you spot any other formatting quirks.

* Cleanup script changes for task attempt 93f0100f-256d-4177-839d-53cb700d2a3e

* Pulled the diff-line lookup into a reusable helper so `DiffCard` now grabs and normalizes the raw line content before drafting comments; this keeps the widget payload lean and avoids scattering newline-trimming logic (`frontend/src/components/DiffCard.tsx:1-161`). Added a `stripLineEnding` utility so future callers have a single place to remove CR/LF sequences without touching other whitespace (`frontend/src/utils/string.ts:24-29`).

Tests: `pnpm run check` (fails — TypeScript can’t resolve types for `markdown-to-jsx` in `frontend/src/components/ui/markdown-renderer.tsx`; worth checking that dependency’s types or a module declaration is in place before re-running).
2025-09-15 23:33:44 +01:00

31 lines
1.0 KiB
TypeScript

/**
* Converts SCREAMING_SNAKE_CASE to "Pretty Case"
* @param value - The string to convert
* @returns Formatted string with proper capitalization
*/
export const toPrettyCase = (value: string): string => {
return value
.split('_')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
};
/**
* Generates a pretty project name from a file path
* Converts directory names like "my-awesome-project" to "My Awesome Project"
* @param path - The file path to extract name from
* @returns Formatted project name
*/
export const generateProjectNameFromPath = (path: string): string => {
const dirName = path.split('/').filter(Boolean).pop() || '';
return dirName.replace(/[-_]/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase());
};
/**
* Removes a single trailing newline sequence from a string.
* Handles CRLF/CR/LF endings while leaving other trailing whitespace intact.
*/
export const stripLineEnding = (value: string): string => {
return value.replace(/(?:\r\n|\r|\n)$/, '');
};