Skip to content

chore: add eslint-plugin-regexp internally (mostly)#109209

Draft
JoshuaKGoldberg wants to merge 2 commits intomasterfrom
add-eslint-plugin-regexp
Draft

chore: add eslint-plugin-regexp internally (mostly)#109209
JoshuaKGoldberg wants to merge 2 commits intomasterfrom
add-eslint-plugin-regexp

Conversation

@JoshuaKGoldberg
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg commented Feb 24, 2026

Note

I'm still onboarding to Sentry (it's my first week!) and testing out developer setup. This PR is part of that testing. It might go nowhere. I haven't discussed this change with anyone. Don't take this as a statement of strong intent! 🙂

Enables most of eslint-plugin-regexp's recommended rules internally, fixing most of the new reports. To avoid stepping into any implicitly held strong opinions, this disables any plugin rule that doesn't seem to result in immediately objectively "better" code.

ota-meshi.github.io/eslint-plugin-regexp/rules has all the rules in the plugin: search for 🟢 to narrow down to just those in the recommended ruleset. Out of those, these rules produced reports:

Rule Description
regexp/negation switches negated character classes to more succinct equivalents, such as /[^\d]/ -> /\D/
regexp/no-dupe-characters-character-class removes characters made redundant by previous classes or ranges, such as /[a-z\\s]/'s s duplicated by a-z
regexp/no-dupe-disjunctions removes disjunctions that are made redundant by a previous one, such as /[ab]|[ba]/'s [ba] duplicating[ab]
regexp/no-trivially-nested-quantifier simplifies multiple nested quantifiers that can be merged into just one simpler one, such as /(?:a{1,2})+/ -> /a+/
regexp/no-useless-character-class simplifies character classes that can be streamlined into just their contents, such as /a[b]c/ -> /abc/
regexp/no-useless-escape removes \ escacpes that are unnecessary and don't do anything, such as /\a/ -> /a/
regexp/no-useless-flag removes flags when they don't change behavior, such as /\w+/i -> /\w+/
regexp/no-useless-lazy removes greedy modifiers that don't change behavior, such as /a{1}?/ -> /a{1}/
regexp/no-useless-non-capturing-group inlines non-capturing groups that can be without changing behavior, such as /(?:a)/.test(str)->/a/.test(str)
regexp/no-useless-quantifier removes quantifiers that don't change behavior, such as /a{1}/ -> /a/
regexp/prefer-character-class switches explicit lists to character classes that do the same thing when possible, such as /[a|b|c]/ -> /[abc]/
regexp/prefer-d switches numeric ranges to an equivalent succinct matcher, such as /[0-9]/ -> /\d/
regexp/prefer-plus-quantifier switches {1,} ranges to an equivalent succinct + quantifier, such as /a{1,}/ -> /a+/
regexp/prefer-question-quantifier switches {0,1} ranges to an equivalent succinct ? quantifier, such as /a{0,}/ -> /a?/
regexp/prefer-w switches alphabetical ranges to an equivalent succinct matcher, such as /[0-9a-zA-Z_]/ -> /\w/

Fun fact: although this diff is +154 / -72, 75 of those added lines are from config/lock-files and 10 are comments. The actual impact to the codebase is +69 / -72. According to my rough character counting of files the actual number of removed characters is approximately 231.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant