fix: align no-reversed-media-syntax masking with UTF-16 offsets#640
Merged
lumirlumir merged 1 commit intomainfrom Mar 30, 2026
Merged
fix: align no-reversed-media-syntax masking with UTF-16 offsets#640lumirlumir merged 1 commit intomainfrom
lumirlumir merged 1 commit intomainfrom
Conversation
3 tasks
3 tasks
There was a problem hiding this comment.
Pull request overview
Fixes no-reversed-media-syntax masking so it stays aligned with ESLint/JS UTF-16 source offsets when the markdown contains surrogate-pair characters (e.g., emoji), preventing incorrect scanning/masking behavior.
Changes:
- Build the rule’s masking buffer using UTF-16 code units (
split("")) instead of Unicode code points (Array.from(...)). - Add regression tests covering valid/invalid cases with surrogate-pair characters before reversed syntax.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/rules/no-reversed-media-syntax.js |
Switch masking buffer construction to UTF-16 code units to match getRange/offset indexing. |
tests/rules/no-reversed-media-syntax.test.js |
Add emoji-based regression tests to validate correct detection and fix ranges with surrogate pairs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lumirlumir
approved these changes
Mar 30, 2026
Member
lumirlumir
left a comment
There was a problem hiding this comment.
LGTM, thanks!
Indeed, Array.from treats emojis as a single character, so the following problem arises:
console.log(Array.from("🎉"), "🎉".length); // [ '�' ] 2
console.log("🎉".split(""), "🎉".length); // [ '\ud83c', '\udf89' ] 2Just for reference, a similar issue occurred in #551 regarding handling code units.
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
AI acknowledgment
What is the purpose of this pull request?
This PR fixes
no-reversed-media-syntaxso it handles text containing characters represented by surrogate pairs correctly. The rule was building its masking buffer by Unicode code points while using source offsets in UTF-16 code units, which could misalign masking and lead to incorrect internal scanning on inputs with emoji-like characters.What changes did you make? (Give an overview)
no-reversed-media-syntaxto build its masking buffer with UTF-16 code units by replacingArray.from(sourceCode.getText(node))withsourceCode.getText(node).split("").Related Issues
Fixes #639
Is there anything you'd like reviewers to focus on?