Skip to content
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

fix(noMisleadingCharacterClass): properly handle escaping and improve diagnostics #4112

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Sep 28, 2024

Summary

This PR fixes erroneous handling of escape sequence.
This was a hard fix/refactor because Unicode escape sequence is hard to handle in both regex strings and regex literals. I still think that we should remove support for string regexes in this rule and noControlCharacterInRegex. This brings a lot of complexity for a minor improvement in linting.

Also, I fixed noControlCharacterInRegex: the rule no longer panics on incomplete Unicode escape sequences.

I also improved the diagnostics message and refactored the code to allow reporting the precise range of the problematic characters.
To do that I had to compute codepoint on demand instead of “evaluating” the string.
This also avoids a string allocation.

I added missing combining characters: Mongolian Free Variation Selector and Variation Selectors Supplement.

There are more room for improvements. Notably, we could reduce the number of false positives by ensuring that a modifier/combining character actually modifies the preceding character.

Test Plan

I added tests and I updated the snapshots.

@github-actions github-actions bot added A-Core Area: core A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels Sep 28, 2024
Copy link

codspeed-hq bot commented Sep 28, 2024

CodSpeed Performance Report

Merging #4112 will not alter performance

Comparing conaclos/noMisleadingCharacterClass-ignore-characters-outside-of-classes (21d12ff) with main (fc5947f)

Summary

✅ 103 untouched benchmarks

@Conaclos Conaclos requested review from a team September 28, 2024 16:35
Comment on lines +86 to 93
pub const fn at(offset: TextSize, len: TextSize) -> TextRange {
TextRange {
start: offset,
end: TextSize {
raw: offset.raw + len.raw,
},
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change? I think I didn't see anything mentioned in the description

Copy link
Member Author

@Conaclos Conaclos Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required anymore. I kept it because this makes all constructors const fn. This seems more consistent with the API of TextRange because there are already many methods that are const fn.

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
@Conaclos Conaclos merged commit cb126db into main Sep 30, 2024
14 checks passed
@Conaclos Conaclos deleted the conaclos/noMisleadingCharacterClass-ignore-characters-outside-of-classes branch September 30, 2024 11:37
branberry pushed a commit to branberry/biome that referenced this pull request Sep 30, 2024
… diagnostics (biomejs#4112)

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Core Area: core A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants