mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter): Panic in prefer string starts, ends with (#1684)
Closes #1683
This commit is contained in:
parent
0f77e5dc52
commit
0a8746c751
2 changed files with 15 additions and 1 deletions
|
|
@ -102,7 +102,7 @@ fn check_regex(regexp_lit: &RegExpLiteral) -> Option<ErrorKind> {
|
|||
|
||||
if regexp_lit.regex.pattern.ends_with('$')
|
||||
&& is_simple_string(
|
||||
®exp_lit.regex.pattern.as_str()[0..regexp_lit.regex.pattern.len() - 2],
|
||||
®exp_lit.regex.pattern.as_str()[0..regexp_lit.regex.pattern.len() - 1],
|
||||
)
|
||||
{
|
||||
return Some(ErrorKind::EndsWith);
|
||||
|
|
@ -167,6 +167,8 @@ fn test() {
|
|||
r#"/^a/v.test("string")"#,
|
||||
r"/a$/.test(`${unknown}`)",
|
||||
r"/a$/.test(String(unknown))",
|
||||
r"const a = /你$/.test('a');",
|
||||
r"const a = /^你/.test('a');",
|
||||
];
|
||||
|
||||
Tester::new_without_config(PreferStringStartsEndsWith::NAME, pass, fail).test_and_snapshot();
|
||||
|
|
|
|||
|
|
@ -200,4 +200,16 @@ expression: prefer_string_starts_ends_with
|
|||
· ──────────────────────────
|
||||
╰────
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#endsWith over a regex with a dollar sign.
|
||||
╭─[prefer_string_starts_ends_with.tsx:1:1]
|
||||
1 │ const a = /你$/.test('a');
|
||||
· ───────────────
|
||||
╰────
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
|
||||
╭─[prefer_string_starts_ends_with.tsx:1:1]
|
||||
1 │ const a = /^你/.test('a');
|
||||
· ───────────────
|
||||
╰────
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue