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

best-practice-rules.mddocs/

Best Practice Rules

Rules that enforce coding standards, performance optimizations, and maintainability improvements for regular expressions. These 25 rules focus on promoting efficient, readable, and maintainable regex patterns.

Rule Interface

All best practice rules implement the standard ESLint rule interface:

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

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

interface RuleListener {
  [key: string]: (node: ESTree.Node) => void;
}

Flag and Pattern Validation

no-missing-g-flag

Disallows missing global flag in patterns where it's likely needed.

// Rule: regexp/no-missing-g-flag
// Type: suggestion
// Fixable: no
// Recommended: false

no-non-standard-flag

Disallows non-standard flags that may not be supported across environments.

// Rule: regexp/no-non-standard-flag
// Type: suggestion
// Fixable: no
// Recommended: false

no-useless-flag

Disallows unnecessary regex flags that have no effect.

// Rule: regexp/no-useless-flag
// Type: suggestion
// Fixable: code
// Recommended: true

Character Class and Range Optimization

no-obscure-range

Disallows obscure character ranges that are hard to understand.

// Rule: regexp/no-obscure-range
// Type: suggestion
// Fixable: no
// Recommended: false

no-octal

Disallows octal escape sequences which are deprecated.

// Rule: regexp/no-octal
// Type: suggestion
// Fixable: no
// Recommended: false

no-useless-character-class

Disallows character classes containing only one character.

// Rule: regexp/no-useless-character-class
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-range

Disallows unnecessary character ranges.

// Rule: regexp/no-useless-range
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-set-operand

Disallows unnecessary elements in expression character classes.

// Rule: regexp/no-useless-set-operand
// Type: suggestion
// Fixable: code
// Recommended: false

Assertion and Lookaround Optimization

no-optional-assertion

Disallows optional assertions that have no effect.

// Rule: regexp/no-optional-assertion
// Type: suggestion
// Fixable: code
// Recommended: true

no-trivially-nested-assertion

Disallows trivially nested assertions that can be simplified.

// Rule: regexp/no-trivially-nested-assertion
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-assertions

Disallows assertions that are known to always accept or reject.

// Rule: regexp/no-useless-assertions
// Type: suggestion
// Fixable: code
// Recommended: true

Backreference and Capture Group Optimization

no-potentially-useless-backreference

Disallows backreferences that reference a group that might not be matched.

// Rule: regexp/no-potentially-useless-backreference
// Type: suggestion
// Fixable: no
// Recommended: true

no-unused-capturing-group

Disallows unused capturing groups that waste memory and processing.

// Rule: regexp/no-unused-capturing-group
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-backreference

Disallows useless backreferences that don't add value.

// Rule: regexp/no-useless-backreference
// Type: suggestion
// Fixable: no
// Recommended: true

no-useless-non-capturing-group

Disallows useless non-capturing groups that can be removed.

// Rule: regexp/no-useless-non-capturing-group
// Type: suggestion
// Fixable: code
// Recommended: true

Quantifier Optimization

no-trivially-nested-quantifier

Disallows nested quantifiers that can be rewritten as one.

// Rule: regexp/no-trivially-nested-quantifier
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-lazy

Disallows unnecessarily non-greedy quantifiers.

// Rule: regexp/no-useless-lazy
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-quantifier

Disallows quantifiers that can be removed without changing behavior.

// Rule: regexp/no-useless-quantifier
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-two-nums-quantifier

Disallows unnecessary {n,m} quantifiers that can be simplified.

// Rule: regexp/no-useless-two-nums-quantifier
// Type: suggestion
// Fixable: code
// Recommended: true

Performance and Safety

no-super-linear-backtracking

Disallows exponential and polynomial backtracking that causes performance issues.

// Rule: regexp/no-super-linear-backtracking
// Type: suggestion
// Fixable: no
// Recommended: true

no-super-linear-move

Disallows quantifiers that cause quadratic moves and performance problems.

// Rule: regexp/no-super-linear-move
// Type: suggestion
// Fixable: no
// Recommended: false

no-standalone-backslash

Disallows standalone backslashes that may cause errors.

// Rule: regexp/no-standalone-backslash
// Type: suggestion
// Fixable: no
// Recommended: true

String and Replacement Optimization

no-useless-dollar-replacements

Disallows useless $ replacements in string replacements.

// Rule: regexp/no-useless-dollar-replacements
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-escape

Disallows useless escape sequences that don't need escaping.

// Rule: regexp/no-useless-escape
// Type: suggestion
// Fixable: code
// Recommended: true

no-useless-string-literal

Disallows string disjunctions of single characters that can be character classes.

// Rule: regexp/no-useless-string-literal
// Type: suggestion
// Fixable: code
// Recommended: false

Usage Examples

Performance Optimization

// ❌ Super-linear backtracking (catastrophic backtracking)
/(a+)+b/  // Can cause exponential time complexity

// ❌ Useless quantifier
/a{1}/  // Same as just /a/

// ❌ Unnecessary non-greedy
/a*?$/  // Non-greedy has no effect at end

// ✅ Optimized patterns
/a+b/      // Direct match, no nested quantifiers
/a/        // Simple quantifier
/a*$/      // Greedy is fine at end

Capture Group Optimization

// ❌ Unused capturing group
/(\d+)-\d+/.exec("123-456")[0]  // Only using full match

// ❌ Useless non-capturing group
/(?:a)/  // Just use /a/

// ✅ Optimized groups
/\d+-\d+/.exec("123-456")[0]     // No capturing group needed
/a/                               // No grouping needed

Character Class Optimization

// ❌ Single character in class
/[a]/  // Same as just /a/

// ❌ Useless range
/[a-a]/  // Same as just /a/

// ❌ String disjunction of single chars
/a|b|c/  // Can be character class

// ✅ Optimized character classes
/a/        // Direct character
/a/        // Direct character  
/[abc]/    // Proper character class

Flag Optimization

// ❌ Useless global flag
/abc/g.test(str)  // test() only finds first match anyway

// ❌ Missing global flag
str.match(/\d+/)  // Only finds first number, likely want all

// ✅ Proper flag usage
/abc/.test(str)           // No global needed for test
str.match(/\d+/g)         // Global flag for finding all matches