feat: handle CR and CRLF in no-missing-atx-heading-space#555
Merged
mdjermanovic merged 20 commits intomainfrom Oct 22, 2025
Merged
feat: handle CR and CRLF in no-missing-atx-heading-space#555mdjermanovic merged 20 commits intomainfrom
no-missing-atx-heading-space#555mdjermanovic merged 20 commits intomainfrom
Conversation
Member
Author
|
Pending until #554 is merged. |
…ndle-cr-in-no-missing-atx-heading-space
This comment was marked as resolved.
This comment was marked as resolved.
1 task
…ndle-cr-in-no-missing-atx-heading-space
This was referenced Oct 14, 2025
…ndle-cr-in-no-missing-atx-heading-space
Member
Author
|
friendly ping @mdjermanovic |
…ndle-cr-in-no-missing-atx-heading-space
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
no-missing-atx-heading-spaceno-missing-atx-heading-space
Comment on lines
+481
to
+494
| { | ||
| code: "Text before\r#Heading with ``` code markers\rText after", | ||
| output: "Text before\r# Heading with ``` code markers\rText after", | ||
| errors: [ | ||
| { | ||
| messageId: "missingSpace", | ||
| data: { position: "after" }, | ||
| line: 2, | ||
| column: 1, | ||
| endLine: 2, | ||
| endColumn: 3, | ||
| }, | ||
| ], | ||
| }, |
Member
There was a problem hiding this comment.
I changed the tag to feat because this change can produce more lint errors. For example, the code from this test case was valid before this change.
Merged
1 task
This was referenced Oct 24, 2025
This was referenced Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites checklist
What is the purpose of this pull request?
Which language are you using?
CommonMark and GFM.
What did you do?
I expect the
no-missing-atx-heading-spacerule to correctly recognize CRLF and CR line endings, but it currently does not.What did you expect to happen?
I expect the
no-missing-atx-heading-spacerule to correctly recognize CRLF and CR line endings.Link to minimal reproducible Example
Adding the following test cases to
tests/rules/no-missing-atx-heading-space.test.jswould help identify the problem:What changes did you make? (Give an overview)
This PR originated from #493. While working on that, I found the scope had become too large, so I split this fix into a separate PR.
In this PR, I've fixed an issue where the
no-missing-atx-heading-spacerule did not recognize CRLF and CR line endings.The previous logic relied on a custom line breaker pattern using
const newLinePattern = /\r?\n/u;, but this is no longer necessary now that thegetLocFromIndexmethod has been added. So, I've removed it.Also, the previous logic required a lot of calculations to convert "offset" into "line, column", but that's no longer necessary, so I refactored the code. (The larger git diff was unavoidable.)
I consistently used the pattern
let match; while ((match = pattern.exec(text)) !== null)when visitingParagraphandHeadingnodes. Since this pattern is used in over 10 places throughout the Markdown rule implementations, using it consistently would make the codebase easier to understand.Notable changes:
mflag toleadingAtxHeadingHashPatternto avoid custom line break logic.findMissingSpaceBeforeClosingHashhelper function into theParagraphvisitor, since this logic was only needed before there was no direct "offset" to "line, column" conversion.let match; while ((match = pattern.exec(text)) !== null)pattern consistently when visitingParagraphandHeadingnodes.Related Issues
Ref: #493, eslint/css#280
Is there anything you'd like reviewers to focus on?
I'll update the other rules and processors to recognize CR in #493. This PR is separate from that one to keep the scope smaller.