Skip to content

Preserve explicit start in Warning#toString() - #2177

Open
Don-Yin wants to merge 1 commit into
postcss:mainfrom
Don-Yin:fix-warning-explicit-start
Open

Don-Yin wants to merge 1 commit into
postcss:mainfrom
Don-Yin:fix-warning-explicit-start

Conversation

@Don-Yin

@Don-Yin Don-Yin commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning already uses an explicit start for its line and column, but toString() drops it and reports the node's start instead.

const postcss = require('postcss')
const root = postcss.parse('a b{}', { from: 'a.css' })
const warning = new postcss.Warning('text', {
  node: root.first,
  start: { line: 1, column: 3 }
})

warning.column // 3
warning.toString() // ends with a.css:1:1: text, rather than a.css:1:3: text

This forwards start to the existing node.error() call, leaving position calculation and source-map handling there.

I added two regression cases in test/warning.test.ts, covering a same-line start and a start on another line. Both fail before the fix and pass with it. pnpm test passes: 723 tests, coverage, lint, types, version, integration and size checks.

The measured positions for those two cases are below; each circle is the requested start.

Requested and formatted warning positions before and after the fix

Forward start to node.error() so the formatted warning agrees with its
line and column. Cover same-line and multiline positions.

Signed-off-by: Don Yin <Don_Yin@outlook.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6858f331-e559-42b5-be9e-8d08f3634dc5
📥 Commits

Reviewing files that changed from the base of the PR and between d190857 and 64a5094.

📒 Files selected for processing: 2
  • lib/warning.js
  • test/warning.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

Warning.toString() now passes this.start to node.error(). Tests cover explicit start positions in single-line and multiline CSS, including the reported line, column, and formatted warning string.

Changes: Warning start coordinates

Layer / File(s) Summary
Pass warning start coordinates
lib/warning.js, test/warning.test.ts
Warning.toString() passes this.start to node.error(). Tests check line and column values and the formatted warning string for single-line and multiline CSS.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 64a50

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving an explicit start position in Warning#toString().
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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.

1 participant