Skip to content

e18e/prefer-static-regex: Inacurate error message #127

Description

@gkubisa

e18e/prefer-static-regex shows the error "Move this regular expression to module scope to avoid re-compilation on every call." but that message is inaccurate because literal regexes are compiled once and cached, and the per-use cost is just a thin object wrapper (pointer to the compiled regex and lastIndex). It's the same as with nested functions - compiled once, thin wrapper on use. So, the rule is actually more about a preference to define all literal regexes at the module level because the performance improvement is negligible. Could we adjust the error message accordingly, please?

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#creating_a_regular_expression

Regular expression literals provide compilation of the regular expression when the script is loaded. If the regular expression remains constant, using this can improve performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions