Skip to content

fix: handle all CSS newline types in CSSSourceCode#275

Merged
nzakas merged 1 commit into
eslint:mainfrom
sethamus:css-newline-handling
Sep 29, 2025
Merged

fix: handle all CSS newline types in CSSSourceCode#275
nzakas merged 1 commit into
eslint:mainfrom
sethamus:css-newline-handling

Conversation

@sethamus

@sethamus sethamus commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

Prerequisites checklist

What did you do?

a {\r/* CR */\f/* FF */\n/* LF */\r\n/* CRLF */}

What did you expect to happen?

  • CSSSourceCode.lines returns the correct array of lines.
  • getLocFromIndex and getIndexFromLoc return correct line/column positions.

What actually happened?

Lines containing CR or FF were not split, causing incorrect line/column calculations.

What is the purpose of this pull request?

According to the CSS Syntax Module Level 3, CSS defines newline as one of:

  • Line Feed (\n)
  • Carriage Return + Line Feed (\r\n)
  • Carriage Return (\r)
  • Form Feed (\f)

CSSSourceCode previously only handled LF and CRLF correctly because it relied on the default lineEndingPattern from TextSourceCodeBase (/\r?\n/).

This PR ensures CSSSourceCode aligns with the CSS specification for newline handling.

What changes did you make? (Give an overview)

  • Updated CSSSourceCode to pass lineEndingPattern: /\r\n|[\r\n\f]/u to TextSourceCodeBase.
  • Added tests to verify correct behavior for LF, CRLF, CR, FF.

Related Issues

fixes #276

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Sep 26, 2025
@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Sep 26, 2025

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks!

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

Labels

bug Something isn't working contributor pool

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Bug: Update rules to handle all newline types

2 participants