-
-
Notifications
You must be signed in to change notification settings - Fork 504
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(linter): noMisleadingCharacterClass #909
feat(linter): noMisleadingCharacterClass #909
Conversation
38493ce
to
11e307b
Compare
@togami2864 Could you execute just codegen and commit/push changes? |
@togami2864 cc: @ematipico ref:
We may not have to be so particular now. I'd like anyone to share any opinions. |
Oh, this is a WIP pull request. I see. |
11e307b
to
0e69ea1
Compare
✅ Deploy Preview for rad-torte-839a59 canceled.
|
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.
As a first look, this looks good! I need more time to review your PR, I was nnot expecting that it also handle nons-static regex. I just left a first comment for the docs.
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
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 left some suggestions, and the usage of global_identifier
for the globalThis
.
I think we should add more test cases:
window.RegExp
globalThis.globalThis
I leave the decision to you @togami2864 , this is a nursery rule, so you can decide make a second PR after we merge this one. Let us know what you want to do and we're happy to help.
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/semantic_analyzers/nursery/no_misleading_character_class.rs
Outdated
Show resolved
Hide resolved
let is_global_this = match callee.object().ok()? { | ||
AnyJsExpression::JsIdentifierExpression(e) => { | ||
e.name().ok()?.has_name("globalThis") | ||
} | ||
_ => false, | ||
}; |
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 have an utility called global_identifier
for these cases, and you use this one. That's needed because it handles recursive cases of global identifiers, like this:
globalThis.globalThis.globalThis.RegExp
@ematipico |
Thank you @togami2864 ! When you merge this PR, please make sure to open a new task (issue) to track your work :) |
Summary
close: #52
implement no-misleading-character-class
This rule isn't 100% compatible with ESLint because it requires an ECMAScript regex parser for certain cases.
Test Plan
add snaps for valid/invalid cases