Skip to content

Conversation

@murataslan1
Copy link

Description

Fixes #6831

The dedent function was using .trimEnd() which removes ALL trailing whitespace including multiple newlines. This is inconsistent with npm:string-dedent which only removes a single trailing newline.

Changes

  • Replace .trimEnd() with .replace(/\n[\t ]*$/, "") to only strip a single trailing newline (with any preceding whitespace on that line)
  • Updated documentation to reflect the new behavior

Before

dedent`
  a

`  // returns 'a' (all trailing newlines stripped)

After

dedent`
  a

`  // returns 'a\n' (only one trailing newline stripped, matching npm:string-dedent)

Testing

The fix ensures consistency with npm:string-dedent@3.0.2 behavior.

Fixes denoland#6831

The dedent function was using `.trimEnd()` which removes ALL trailing
whitespace including multiple newlines. This is inconsistent with
npm:string-dedent which only removes a single trailing newline.

Changes:
- Replace `.trimEnd()` with `.replace(/\n[\t ]*$/, "")` to only strip
  a single trailing newline (with any preceding whitespace on that line)
- Updated documentation to reflect the new behavior

Before:
```ts
dedent\`
  a

\`  // returns 'a' (all trailing newlines stripped)
```

After:
```ts
dedent\`
  a

\`  // returns 'a\n' (only one trailing newline stripped)
```
@murataslan1 murataslan1 requested a review from kt3k as a code owner December 24, 2025 18:57
@github-actions github-actions bot added the text label Dec 24, 2025
@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.14%. Comparing base (dcfb5b3) to head (8963548).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6913   +/-   ##
=======================================
  Coverage   94.14%   94.14%           
=======================================
  Files         583      583           
  Lines       42806    42806           
  Branches     6815     6815           
=======================================
  Hits        40301    40301           
  Misses       2455     2455           
  Partials       50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

Looks in a good direction. Can you format source code with deno fmt? Also can you add a test case to verify the example in #6831 ?

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.

text/unstable-dedent strips too many trailing newlines

2 participants