-
Couldn't load subscription status.
- Fork 79
feat: 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
feat: handle CR and CRLF in no-missing-atx-heading-space
#555
Conversation
|
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.
…ndle-cr-in-no-missing-atx-heading-space
…ndle-cr-in-no-missing-atx-heading-space
|
friendly ping @mdjermanovic |
…ndle-cr-in-no-missing-atx-heading-space
Co-authored-by: Milos Djermanovic <[email protected]>
no-missing-atx-heading-spaceno-missing-atx-heading-space
| { | ||
| 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, | ||
| }, | ||
| ], | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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.