---
source: crates/oxc_linter/src/tester.rs
---
  ⚠ 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 │ /^foo/.test(bar)
   · ───────────
   ╰────
  help: Replace `/^foo/.test(bar)` with `bar.startsWith("foo")`.

  ⚠ 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 │ /foo$/.test(bar)
   · ───────────
   ╰────
  help: Replace `/foo$/.test(bar)` with `bar.endsWith("foo")`.

  ⚠ 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 │ /^!/.test(bar)
   · ─────────
   ╰────
  help: Replace `/^!/.test(bar)` with `bar.startsWith("!")`.

  ⚠ 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 │ /!$/.test(bar)
   · ─────────
   ╰────
  help: Replace `/!$/.test(bar)` with `bar.endsWith("!")`.

  ⚠ 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 │ /^ /.test(bar)
   · ─────────
   ╰────
  help: Replace `/^ /.test(bar)` with `bar.startsWith(" ")`.

  ⚠ 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 │ / $/.test(bar)
   · ─────────
   ╰────
  help: Replace `/ $/.test(bar)` with `bar.endsWith(" ")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:17]
 1 │ const foo = {}; /^abc/.test(foo);
   ·                 ───────────
   ╰────
  help: Replace `/^abc/.test(foo)` with `foo.startsWith("abc")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:18]
 1 │ const foo = 123; /^abc/.test(foo);
   ·                  ───────────
   ╰────
  help: Replace `/^abc/.test(foo)` with `foo.startsWith("abc")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:22]
 1 │ const foo = "hello"; /^abc/.test(foo);
   ·                      ───────────
   ╰────
  help: Replace `/^abc/.test(foo)` with `foo.startsWith("abc")`.

  ⚠ 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 │ /^b/.test((a))
   · ─────────
   ╰────
  help: Replace `/^b/.test((a))` with `a.startsWith("b")`.

  ⚠ 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 │ (/^b/).test((a))
   · ───────────
   ╰────
  help: Replace `(/^b/).test((a))` with `a.startsWith("b")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:24]
 1 │ const fn = async () => /^b/.test(await foo)
   ·                        ─────────
   ╰────

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:24]
 1 │ const fn = async () => (/^b/).test(await foo)
   ·                        ───────────
   ╰────

  ⚠ 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 │ /^a/.test("string")
   · ─────────
   ╰────
  help: Replace `/^a/.test("string")` with `"string".startsWith("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 │ /^a/.test((0, "string"))
   · ─────────
   ╰────

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:28]
 1 │ async function a() {return /^a/.test(await foo())}
   ·                            ─────────
   ╰────

  ⚠ 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 │ /^a/.test(foo + bar)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(foo || bar)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new SomeString)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new (SomeString))
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new SomeString())
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new new SomeClassReturnsAStringSubClass())
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new SomeString(/* comment */))
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(new SomeString("string"))
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(foo.bar)
   · ─────────
   ╰────
  help: Replace `/^a/.test(foo.bar)` with `foo.bar.startsWith("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 │ /^a/.test(foo.bar())
   · ─────────
   ╰────
  help: Replace `/^a/.test(foo.bar())` with `foo.bar().startsWith("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 │ /^a/.test(foo?.bar)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(foo?.bar())
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(`string`)
   · ─────────
   ╰────
  help: Replace `/^a/.test(`string`)` with ``string`.startsWith("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 │ /^a/.test(tagged`string`)
   · ─────────
   ╰────

  ⚠ 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 │ (/^a/).test((0, "string"))
   · ───────────
   ╰────

  ⚠ 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 │ /^a/.test(true ? a : b)
   · ─────────
   ╰────

  ⚠ 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 │ /a$/.test(a ??= b)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(a || b)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/.test(a && b)
   · ─────────
   ╰────

  ⚠ 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 │ /^a/u.test("string")
   · ──────────
   ╰────
  help: Replace `/^a/u.test("string")` with `"string".startsWith("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 │ /^a/v.test("string")
   · ──────────
   ╰────
  help: Replace `/^a/v.test("string")` with `"string".startsWith("a")`.

  ⚠ 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 │ /a$/.test(`${unknown}`)
   · ─────────
   ╰────
  help: Replace `/a$/.test(`${unknown}`)` with ``${unknown}`.endsWith("a")`.

  ⚠ 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 │ /a$/.test(String(unknown))
   · ─────────
   ╰────
  help: Replace `/a$/.test(String(unknown))` with `String(unknown).endsWith("a")`.

  ⚠ 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:11]
 1 │ const a = /你$/.test('a');
   ·           ──────────
   ╰────
  help: Replace `/你$/.test('a')` with `'a'.endsWith("你")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:11]
 1 │ const a = /^你/.test('a');
   ·           ──────────
   ╰────
  help: Replace `/^你/.test('a')` with `'a'.startsWith("你")`.

  ⚠ eslint-plugin-unicorn(prefer-string-starts-ends-with): Prefer String#startsWith over a regex with a caret.
   ╭─[prefer_string_starts_ends_with.tsx:1:5]
 1 │ if (/^#/i.test(hex)) {}
   ·     ──────────
   ╰────
  help: Replace `/^#/i.test(hex)` with `hex.startsWith("#")`.

  ⚠ 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:5]
 1 │ if (/#$/i.test(hex)) {}
   ·     ──────────
   ╰────
  help: Replace `/#$/i.test(hex)` with `hex.endsWith("#")`.
