Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Latest commit

 

History

History
45 lines (31 loc) · 1.26 KB

no-unnecessary-flag.md

File metadata and controls

45 lines (31 loc) · 1.26 KB

no-unnecessary-flag 🔧

Disallow unnecessary regex flags.

configuration in plugin:clean-regex/recommended: "warn"

Source file
Test file

Description

This will point out present regex flags that do not change the pattern.

The i flag is only necessary if the pattern contains any characters with case variations. If no such characters are part of the pattern, the flag is unnecessary. E.g. /\.{3}/i

The m flag changes the meaning of the ^ and $ anchors, so if the pattern doesn't contain these anchors, it's unnecessary. E.g. /foo|[^\r\n]*/m

The s flag makes the dot (.) match all characters instead of the usually non-line-terminator characters, so if the pattern doesn't contain a dot character set, it will be unnecessary. E.g. /[.:]/s

No other flags will be checked.

Examples

Examples of valid code for this rule:

/a|b/i
/^foo$/m
/a.*?b/s

Examples of invalid code for this rule:

/\w+/i
/a|b/m
/^foo$/s