-
Notifications
You must be signed in to change notification settings - Fork 78
refactor: use getLocFromIndex
in no-space-in-emphasis
#553
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
refactor: use getLocFromIndex
in no-space-in-emphasis
#553
Conversation
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!
* @param {boolean} checkStrikethrough Whether to include strikethrough markers. | ||
* @returns {RegExp} The marker pattern. | ||
*/ | ||
function createMarkerPattern(checkStrikethrough) { |
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.
Can we also remove the function as part of this refactoring as no regular expression is dynamically created?
"paragraph:exit"(node) { | ||
bufferManager.exit(node); | ||
}, | ||
":matches(heading, paragraph, tableCell):exit"( |
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.
":matches(heading, paragraph, tableCell):exit"( | |
"heading, paragraph, tableCell:exit"( |
The :matches
pseudo-selector is not required.
/** @type {RegExpExecArray | null} */ | ||
let match; | ||
|
||
while ((match = markerPattern.exec(maskedText)) !== null) { |
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.
We could use String#matchAll instead of using while
with exec
:
while ((match = markerPattern.exec(maskedText)) !== null) { | |
for (const match of maskedText.matchAll(markerPattern) { |
Prerequisites checklist
What is the purpose of this pull request?
This PR originated from #536. While working on that, I found the scope had become too large, so I split this refactoring into a separate PR.
In this PR, I've used the native
getLocFromIndex
method added in #376 instead of the customfindOffsets
util.Notable changes:
findOffsets
util with the nativegetLocFromIndex
.findEmphasisMarkers
,checkEmphasis
,bufferManager
, and other helper functions directly into the ESQuery selector to simplify the code.What changes did you make? (Give an overview)
In this PR, I've used the native
getLocFromIndex
method added in #376 instead of the customfindOffsets
util.Related Issues
Ref: #376, #536
Is there anything you'd like reviewers to focus on?
I personally don't prefer large git diffs, but this time there was a lot of room to simplify the logic (resulting in −113 lines of code), so I inevitably produced a large diff.
My main focus while working was reducing unnecessarily nested helper functions and simplifying the line/column <-> offset translation logic.