or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

best-practice-rules.mdconfiguration.mderror-rules.mdindex.mdmetadata.mdstylistic-rules.md
tile.json

stylistic-rules.mddocs/

Stylistic Rules

Rules that enforce consistent formatting, naming conventions, and stylistic choices for regular expressions to improve code readability and maintainability. These 32 rules focus on code style and consistency rather than correctness.

Rule Interface

All stylistic rules implement the standard ESLint rule interface:

interface RuleModule {
  meta: RuleMeta;
  create: (context: RuleContext) => RuleListener;
}

interface RuleMeta {
  type: "layout";
  docs: {
    description: string;
    category: "Stylistic Issues";
    recommended: boolean;
    url: string;
    ruleName: string;
  };
  fixable?: "code" | "whitespace";
  schema: JSONSchema4;
  messages: Record<string, string>;
}

Quantifier Style Rules

no-zero-quantifier

Disallows quantifiers with a maximum of zero, which never match.

// Rule: regexp/no-zero-quantifier
// Type: layout
// Fixable: no
// Recommended: false

prefer-plus-quantifier

Prefer + quantifier over {1,} for better readability.

// Rule: regexp/prefer-plus-quantifier
// Type: layout
// Fixable: code
// Recommended: false

prefer-question-quantifier

Prefer ? quantifier over {0,1} for better readability.

// Rule: regexp/prefer-question-quantifier
// Type: layout
// Fixable: code
// Recommended: false

prefer-star-quantifier

Prefer * quantifier over {0,} for better readability.

// Rule: regexp/prefer-star-quantifier
// Type: layout
// Fixable: code
// Recommended: false

prefer-quantifier

Enforces using quantifier shorthand when possible.

// Rule: regexp/prefer-quantifier
// Type: layout
// Fixable: code
// Recommended: false

optimal-quantifier-concatenation

Requires optimal quantifiers for concatenated quantifiers.

// Rule: regexp/optimal-quantifier-concatenation
// Type: layout
// Fixable: code
// Recommended: false

optimal-lookaround-quantifier

Disallows alternatives of lookarounds that end with non-constant quantifier.

// Rule: regexp/optimal-lookaround-quantifier
// Type: layout
// Fixable: no
// Recommended: false

Character Class Style Rules

prefer-character-class

Prefer character class over alternatives for single characters.

// Rule: regexp/prefer-character-class
// Type: layout
// Fixable: code
// Recommended: false

prefer-d

Prefer \d over [0-9] for digit matching.

// Rule: regexp/prefer-d
// Type: layout
// Fixable: code
// Recommended: false

prefer-w

Prefer \w over [a-zA-Z0-9_] for word character matching.

// Rule: regexp/prefer-w
// Type: layout
// Fixable: code
// Recommended: false

prefer-range

Enforces using character class ranges when appropriate.

// Rule: regexp/prefer-range
// Type: layout
// Fixable: code
// Recommended: false

prefer-set-operation

Prefer set operations over character classes when available.

// Rule: regexp/prefer-set-operation
// Type: layout
// Fixable: code
// Recommended: false

simplify-set-operations

Simplifies set operations to their most readable form.

// Rule: regexp/simplify-set-operations
// Type: layout
// Fixable: code
// Recommended: false

Naming and Reference Style Rules

prefer-named-backreference

Prefer named backreferences over numbered ones for clarity.

// Rule: regexp/prefer-named-backreference
// Type: layout
// Fixable: no
// Recommended: false

prefer-named-capture-group

Prefer named capture groups over anonymous ones for maintainability.

// Rule: regexp/prefer-named-capture-group
// Type: layout
// Fixable: no
// Recommended: false

prefer-named-replacement

Prefer named replacements in replacement strings for clarity.

// Rule: regexp/prefer-named-replacement
// Type: layout
// Fixable: code
// Recommended: false

prefer-result-array-groups

Prefer result array groups property over indexed access.

// Rule: regexp/prefer-result-array-groups
// Type: layout
// Fixable: code
// Recommended: false

Assertion and Lookaround Style Rules

prefer-lookaround

Prefer lookaround over negated character class when applicable.

// Rule: regexp/prefer-lookaround
// Type: layout
// Fixable: code
// Recommended: false

prefer-predefined-assertion

Prefer predefined assertions over equivalent lookarounds.

// Rule: regexp/prefer-predefined-assertion
// Type: layout
// Fixable: code
// Recommended: false

Unicode and Escape Style Rules

prefer-unicode-codepoint-escapes

Prefer Unicode codepoint escapes over other Unicode escape forms.

// Rule: regexp/prefer-unicode-codepoint-escapes
// Type: layout
// Fixable: code
// Recommended: false

unicode-escape

Enforces consistent Unicode escape style.

// Rule: regexp/unicode-escape
// Type: layout
// Fixable: code
// Recommended: false

unicode-property

Enforces consistent Unicode property escape style.

// Rule: regexp/unicode-property
// Type: layout
// Fixable: code
// Recommended: false

prefer-escape-replacement-dollar-char

Enforces escape of replacement $ character for consistency.

// Rule: regexp/prefer-escape-replacement-dollar-char
// Type: layout
// Fixable: code
// Recommended: false

Method and Flag Style Rules

prefer-regexp-exec

Enforces that RegExp#exec is used instead of String#match when appropriate.

// Rule: regexp/prefer-regexp-exec
// Type: layout
// Fixable: no
// Recommended: false

prefer-regexp-test

Enforces that RegExp#test is used instead of String#match for boolean checks.

// Rule: regexp/prefer-regexp-test
// Type: layout
// Fixable: code
// Recommended: false

require-unicode-regexp

Requires Unicode flag for proper Unicode handling.

// Rule: regexp/require-unicode-regexp
// Type: layout
// Fixable: no
// Recommended: false

require-unicode-sets-regexp

Requires Unicode sets flag when using set operations.

// Rule: regexp/require-unicode-sets-regexp
// Type: layout
// Fixable: no
// Recommended: false

use-ignore-case

Use ignore case flag instead of case-insensitive alternatives.

// Rule: regexp/use-ignore-case
// Type: layout
// Fixable: code
// Recommended: false

Sorting and Organization Rules

sort-alternatives

Sorts alternatives in disjunctions for consistency.

// Rule: regexp/sort-alternatives
// Type: layout
// Fixable: code
// Recommended: false

sort-character-class-elements

Sorts character class elements for consistency.

// Rule: regexp/sort-character-class-elements
// Type: layout
// Fixable: code
// Recommended: false

sort-flags

Sorts flags in consistent order.

// Rule: regexp/sort-flags
// Type: layout
// Fixable: code
// Recommended: false

Strictness Rules

strict

Disallows patterns that are not strictly valid regular expressions.

// Rule: regexp/strict
// Type: layout
// Fixable: no
// Recommended: false

Usage Examples

Quantifier Style

// ❌ Verbose quantifiers
/a{1,}/     // Could be a+
/a{0,1}/    // Could be a?  
/a{0,}/     // Could be a*

// ✅ Preferred quantifier style
/a+/        // Clear and concise
/a?/        // Clear and concise
/a*/        // Clear and concise

Character Class Style

// ❌ Verbose character classes
/[0-9]/           // Could be \d
/[a-zA-Z0-9_]/    // Could be \w
/a|b|c/           // Could be character class

// ✅ Preferred character class style  
/\d/              // Concise digit class
/\w/              // Concise word class
/[abc]/           // Proper character class

Named References Style

// ❌ Anonymous capture groups and numeric references
const regex = /(\d{4})-(\d{2})-(\d{2})/;
const match = "2023-12-25".match(regex);
const year = match[1];  // Not clear what [1] represents

// ✅ Named capture groups and named references  
const regex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const match = "2023-12-25".match(regex);
const year = match.groups.year;  // Clear what year represents

Method Usage Style

// ❌ Using String#match for boolean checks
if ("test".match(/t/)) { }

// ❌ Using String#match when you need exec behavior
const match = "test".match(/t/);

// ✅ Using appropriate methods
if (/t/.test("test")) { }     // Better for boolean checks
const match = /t/.exec("test"); // Better when you need match details

Unicode Style

// ❌ Inconsistent Unicode handling
/café/              // May not handle accents properly
/[\u0041-\u005A]/   // Verbose Unicode escapes

// ✅ Consistent Unicode style
/café/u             // Proper Unicode handling
/[A-Z]/u            // Clear range with Unicode flag
/\p{L}/u            // Unicode property for letters