Skip to content

Files

Latest commit

 

History

History
24 lines (15 loc) · 383 Bytes

prefer-regexp-test.md

File metadata and controls

24 lines (15 loc) · 383 Bytes

Pattern: Missing use of RegExp#test

Issue: -

Description

This rule is aimed to use RegExp#test to check if a pattern matches a string.

Examples

/* eslint regexp/prefer-regexp-test: "error" */

const text = 'something';
const pattern = /thing/;

/* ✓ GOOD */
if (pattern.test(text)) {}

/* ✗ BAD */
if (pattern.exec(text)) {}
if (text.match(pattern)) {}