Skip to content

Files

Latest commit

 

History

History
26 lines (19 loc) · 646 Bytes

simplify-set-operations.md

File metadata and controls

26 lines (19 loc) · 646 Bytes

Pattern: Unnecessarily complex set operation

Issue: -

Description

This rule aims to optimize patterns by simplifying set operations in character classes (with v flag).

This rule uses De Morgan's laws and conversion between intersection and subtraction to simplify character class operations.

Examples

/* eslint regexp/simplify-set-operations: "error" */
/* ✓ GOOD */
var re = /[a--b]/v;
var re = /[a&&b]/v;
var re = /[^ab]/v;
var re = /[^a&&b]/v;

/* ✗ BAD */
var re = /[a&&[^b]]/v; // -> /[a--b]/v
var re = /[[^b]&&a]/v; // -> /[a--b]/v
var re = /[a--[^b]]/v; // -> /[a&&b]/v
var re = /[[^a]&&[^b]]/v; // -> /[^ab]/v