Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.14 KB

prefer-regexp-test.md

File metadata and controls

38 lines (28 loc) · 1.14 KB

Prefer RegExp#test() over String#match() and RegExp#exec()

This rule is part of the recommended config.

🔧 This rule is auto-fixable.

When you want to know whether a pattern is found in a string, use RegExp#test() instead of String#match() and RegExp#exec().

Fail

if (string.match(/unicorn/)) {}
if (/unicorn/.exec(string)) {}
<template>
	<div v-if="/unicorn/.exec(string)">Vue</div>
</template>

Pass

if (/unicorn/.test(string)) {}
<template>
	<div v-if="/unicorn/.test(string)">Vue</div>
</template>