-
Notifications
You must be signed in to change notification settings - Fork 79
fix: handle CR and CRLF in no-missing-atx-heading-space
#555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lumirlumir
wants to merge
18
commits into
main
Choose a base branch
from
fix-handle-cr-in-no-missing-atx-heading-space
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
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
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-space
rule 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-space
rule 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.js
would 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-space
rule 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 thegetLocFromIndex
method 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 visitingParagraph
andHeading
nodes. 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:
m
flag toleadingAtxHeadingHashPattern
to avoid custom line break logic.findMissingSpaceBeforeClosingHash
helper function into theParagraph
visitor, 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 visitingParagraph
andHeading
nodes.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.