diff --git a/package.json b/package.json index cfde3b5..8a47f07 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-plugin-react": "^7.37.2", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "0.4.14", + "eslint-plugin-regexp": "^2.7.0", "eslint-plugin-testing-library": "7.0.0-beta.6", "eslint-plugin-unicorn": "^56.0.1", "globals": "^15.12.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 60ea91f..0b61caf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,9 @@ importers: eslint-plugin-react-refresh: specifier: 0.4.14 version: 0.4.14(eslint@9.15.0(jiti@2.4.0)) + eslint-plugin-regexp: + specifier: ^2.7.0 + version: 2.7.0(eslint@9.15.0(jiti@2.4.0)) eslint-plugin-testing-library: specifier: 7.0.0-beta.6 version: 7.0.0-beta.6(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3) @@ -1996,6 +1999,10 @@ packages: resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} engines: {node: '>=18'} + comment-parser@1.4.1: + resolution: {integrity: sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg==} + engines: {node: '>= 12.0.0'} + commitlint@19.6.0: resolution: {integrity: sha512-0gOMRBSpnCw3Su0rfVeDqCe4ck/fkhGGC9UxVDeSyyCemFXs4U3BDuwMWvYcw4qsEAkPuDjQNoU8KWyPtHBq/w==} engines: {node: '>=v18'} @@ -2489,6 +2496,12 @@ packages: peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7 + eslint-plugin-regexp@2.7.0: + resolution: {integrity: sha512-U8oZI77SBtH8U3ulZ05iu0qEzIizyEDXd+BWHvyVxTOjGwcDcvy/kEpgFG4DYca2ByRLiVPFZ2GeH7j1pdvZTA==} + engines: {node: ^18 || >=20} + peerDependencies: + eslint: '>=8.44.0' + eslint-plugin-testing-library@7.0.0-beta.6: resolution: {integrity: sha512-TK39+CTbMdkSH0wmnltdjur8tUYz+lnID8o0VZFG45fSeFknLnbn76we3uzDbUltH68bdmoPXk/7w1x3XFQ7+w==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0, npm: '>=6'} @@ -3212,6 +3225,10 @@ packages: resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} hasBin: true + jsdoc-type-pratt-parser@4.1.0: + resolution: {integrity: sha512-Hicd6JK5Njt2QB6XYFS7ok9e37O8AYk3jTcppG4YVQnYjOemymvTcmc7OWsmq/Qqj5TdRFO5/x/tIPmBeRtGHg==} + engines: {node: '>=12.0.0'} + jsesc@0.5.0: resolution: {integrity: sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==} hasBin: true @@ -4223,6 +4240,10 @@ packages: resolution: {integrity: sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==} engines: {node: '>= 14.16.0'} + refa@0.12.1: + resolution: {integrity: sha512-J8rn6v4DBb2nnFqkqwy6/NnTYMcgLA+sLr0iIO41qpv0n+ngb7ksag2tMRl0inb1bbO/esUwzW1vbJi7K0sI0g==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + reflect.getprototypeof@1.0.6: resolution: {integrity: sha512-fmfw4XgoDke3kdI6h4xcUz1dG8uaiv5q9gcEwLS4Pnth2kxT+GZ7YehS1JTMGBQmtV7Y4GFGbs2re2NqhdozUg==} engines: {node: '>= 0.4'} @@ -4239,6 +4260,10 @@ packages: regex@4.4.0: resolution: {integrity: sha512-uCUSuobNVeqUupowbdZub6ggI5/JZkYyJdDogddJr60L764oxC2pMZov1fQ3wM9bdyzUILDG+Sqx6NAKAz9rKQ==} + regexp-ast-analysis@0.7.1: + resolution: {integrity: sha512-sZuz1dYW/ZsfG17WSAG7eS85r5a0dDsvg+7BiiYR5o6lKCAtUrEwdmRmaGF6rwVj3LcmAeYkOWKEPlbPzN3Y3A==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + regexp-tree@0.1.27: resolution: {integrity: sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==} hasBin: true @@ -4371,6 +4396,10 @@ packages: scheduler@0.23.2: resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} + scslre@0.3.0: + resolution: {integrity: sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==} + engines: {node: ^14.0.0 || >=16.0.0} + section-matter@1.0.0: resolution: {integrity: sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==} engines: {node: '>=4'} @@ -6970,6 +6999,8 @@ snapshots: commander@12.1.0: {} + comment-parser@1.4.1: {} + commitlint@19.6.0(@types/node@22.9.1)(typescript@5.6.3): dependencies: '@commitlint/cli': 19.6.0(@types/node@22.9.1)(typescript@5.6.3) @@ -7595,6 +7626,17 @@ snapshots: string.prototype.matchall: 4.0.11 string.prototype.repeat: 1.0.0 + eslint-plugin-regexp@2.7.0(eslint@9.15.0(jiti@2.4.0)): + dependencies: + '@eslint-community/eslint-utils': 4.4.1(eslint@9.15.0(jiti@2.4.0)) + '@eslint-community/regexpp': 4.12.1 + comment-parser: 1.4.1 + eslint: 9.15.0(jiti@2.4.0) + jsdoc-type-pratt-parser: 4.1.0 + refa: 0.12.1 + regexp-ast-analysis: 0.7.1 + scslre: 0.3.0 + eslint-plugin-testing-library@7.0.0-beta.6(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3): dependencies: '@typescript-eslint/scope-manager': 8.15.0 @@ -8425,6 +8467,8 @@ snapshots: dependencies: argparse: 2.0.1 + jsdoc-type-pratt-parser@4.1.0: {} + jsesc@0.5.0: {} jsesc@3.0.2: {} @@ -9462,6 +9506,10 @@ snapshots: readdirp@4.0.2: {} + refa@0.12.1: + dependencies: + '@eslint-community/regexpp': 4.12.1 + reflect.getprototypeof@1.0.6: dependencies: call-bind: 1.0.7 @@ -9482,6 +9530,11 @@ snapshots: regex@4.4.0: {} + regexp-ast-analysis@0.7.1: + dependencies: + '@eslint-community/regexpp': 4.12.1 + refa: 0.12.1 + regexp-tree@0.1.27: {} regexp.prototype.flags@1.5.3: @@ -9700,6 +9753,12 @@ snapshots: dependencies: loose-envify: 1.4.0 + scslre@0.3.0: + dependencies: + '@eslint-community/regexpp': 4.12.1 + refa: 0.12.1 + regexp-ast-analysis: 0.7.1 + section-matter@1.0.0: dependencies: extend-shallow: 2.0.1 diff --git a/src/configs/regexp.ts b/src/configs/regexp.ts new file mode 100644 index 0000000..e9b20c9 --- /dev/null +++ b/src/configs/regexp.ts @@ -0,0 +1,13 @@ +import * as regexpPlugin from "eslint-plugin-regexp"; + +import { regexpRules } from "../rules/regexp"; + +export const regexpConfig = () => { + return [ + { + name: "jimmy.codes/regexp", + plugins: { regexp: regexpPlugin }, + rules: regexpRules, + }, + ]; +}; diff --git a/src/factory.spec.ts b/src/factory.spec.ts index ea0a604..5a53337 100644 --- a/src/factory.spec.ts +++ b/src/factory.spec.ts @@ -15,6 +15,7 @@ describe("jimmyDotCodes", () => { "prettier", "ignores", "javascript", + "regexp", ])("should create configuration w/ %s", async (input) => { await expect(jimmyDotCodes({ autoDetect: false })).resolves.toStrictEqual( expect.arrayContaining([ diff --git a/src/factory.ts b/src/factory.ts index e4cd1ca..ee29813 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -12,6 +12,7 @@ import { nodeConfig } from "./configs/node"; import { perfectionistConfig } from "./configs/perfectionist"; import { prettierConfig } from "./configs/prettier"; import { reactConfig } from "./configs/react"; +import { regexpConfig } from "./configs/regexp"; import { tanstackQuery } from "./configs/tanstack-query"; import { testingConfig } from "./configs/testing"; import { testingLibrary } from "./configs/testing-library"; @@ -64,6 +65,7 @@ export const jimmyDotCodes = async ( nodeConfig(), unicornConfig(), eslintCommentsConfig(), + regexpConfig(), importsConfig({ typescript: isTypescriptEnabled }), isTypescriptEnabled ? typescriptConfig(typescriptOptions) : [], isReactEnabled ? await reactConfig() : [], diff --git a/src/rules.gen.d.ts b/src/rules.gen.d.ts index 06a9a21..131bea0 100644 --- a/src/rules.gen.d.ts +++ b/src/rules.gen.d.ts @@ -3990,6 +3990,416 @@ export interface RuleOptions { * @see https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/void-dom-elements-no-children.md */ 'react/void-dom-elements-no-children'?: Linter.RuleEntry<[]> + /** + * disallow confusing quantifiers + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/confusing-quantifier.html + */ + 'regexp/confusing-quantifier'?: Linter.RuleEntry<[]> + /** + * enforce consistent escaping of control characters + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/control-character-escape.html + */ + 'regexp/control-character-escape'?: Linter.RuleEntry<[]> + /** + * enforce single grapheme in string literal + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/grapheme-string-literal.html + */ + 'regexp/grapheme-string-literal'?: Linter.RuleEntry<[]> + /** + * enforce consistent usage of hexadecimal escape + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/hexadecimal-escape.html + */ + 'regexp/hexadecimal-escape'?: Linter.RuleEntry + /** + * enforce into your favorite case + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/letter-case.html + */ + 'regexp/letter-case'?: Linter.RuleEntry + /** + * enforce match any character style + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/match-any.html + */ + 'regexp/match-any'?: Linter.RuleEntry + /** + * enforce use of escapes on negation + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/negation.html + */ + 'regexp/negation'?: Linter.RuleEntry<[]> + /** + * disallow elements that contradict assertions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-contradiction-with-assertion.html + */ + 'regexp/no-contradiction-with-assertion'?: Linter.RuleEntry<[]> + /** + * disallow control characters + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-control-character.html + */ + 'regexp/no-control-character'?: Linter.RuleEntry<[]> + /** + * disallow duplicate characters in the RegExp character class + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-dupe-characters-character-class.html + */ + 'regexp/no-dupe-characters-character-class'?: Linter.RuleEntry<[]> + /** + * disallow duplicate disjunctions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-dupe-disjunctions.html + */ + 'regexp/no-dupe-disjunctions'?: Linter.RuleEntry + /** + * disallow alternatives without elements + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-alternative.html + */ + 'regexp/no-empty-alternative'?: Linter.RuleEntry<[]> + /** + * disallow capturing group that captures empty. + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-capturing-group.html + */ + 'regexp/no-empty-capturing-group'?: Linter.RuleEntry<[]> + /** + * disallow character classes that match no characters + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-character-class.html + */ + 'regexp/no-empty-character-class'?: Linter.RuleEntry<[]> + /** + * disallow empty group + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-group.html + */ + 'regexp/no-empty-group'?: Linter.RuleEntry<[]> + /** + * disallow empty lookahead assertion or empty lookbehind assertion + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-lookarounds-assertion.html + */ + 'regexp/no-empty-lookarounds-assertion'?: Linter.RuleEntry<[]> + /** + * disallow empty string literals in character classes + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-string-literal.html + */ + 'regexp/no-empty-string-literal'?: Linter.RuleEntry<[]> + /** + * disallow escape backspace (`[\b]`) + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-escape-backspace.html + */ + 'regexp/no-escape-backspace'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary nested lookaround assertions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-extra-lookaround-assertions.html + */ + 'regexp/no-extra-lookaround-assertions'?: Linter.RuleEntry<[]> + /** + * disallow invalid regular expression strings in `RegExp` constructors + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invalid-regexp.html + */ + 'regexp/no-invalid-regexp'?: Linter.RuleEntry<[]> + /** + * disallow invisible raw character + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invisible-character.html + */ + 'regexp/no-invisible-character'?: Linter.RuleEntry<[]> + /** + * disallow lazy quantifiers at the end of an expression + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-lazy-ends.html + */ + 'regexp/no-lazy-ends'?: Linter.RuleEntry + /** + * disallow legacy RegExp features + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-legacy-features.html + */ + 'regexp/no-legacy-features'?: Linter.RuleEntry + /** + * disallow capturing groups that do not behave as one would expect + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-misleading-capturing-group.html + */ + 'regexp/no-misleading-capturing-group'?: Linter.RuleEntry + /** + * disallow multi-code-point characters in character classes and quantifiers + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-misleading-unicode-character.html + */ + 'regexp/no-misleading-unicode-character'?: Linter.RuleEntry + /** + * disallow missing `g` flag in patterns used in `String#matchAll` and `String#replaceAll` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-missing-g-flag.html + */ + 'regexp/no-missing-g-flag'?: Linter.RuleEntry + /** + * disallow non-standard flags + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-non-standard-flag.html + */ + 'regexp/no-non-standard-flag'?: Linter.RuleEntry<[]> + /** + * disallow obscure character ranges + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html + */ + 'regexp/no-obscure-range'?: Linter.RuleEntry + /** + * disallow octal escape sequence + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-octal.html + */ + 'regexp/no-octal'?: Linter.RuleEntry<[]> + /** + * disallow optional assertions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-optional-assertion.html + */ + 'regexp/no-optional-assertion'?: Linter.RuleEntry<[]> + /** + * disallow backreferences that reference a group that might not be matched + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-potentially-useless-backreference.html + */ + 'regexp/no-potentially-useless-backreference'?: Linter.RuleEntry<[]> + /** + * disallow standalone backslashes (`\`) + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-standalone-backslash.html + */ + 'regexp/no-standalone-backslash'?: Linter.RuleEntry<[]> + /** + * disallow exponential and polynomial backtracking + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-super-linear-backtracking.html + */ + 'regexp/no-super-linear-backtracking'?: Linter.RuleEntry + /** + * disallow quantifiers that cause quadratic moves + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-super-linear-move.html + */ + 'regexp/no-super-linear-move'?: Linter.RuleEntry + /** + * disallow trivially nested assertions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-trivially-nested-assertion.html + */ + 'regexp/no-trivially-nested-assertion'?: Linter.RuleEntry<[]> + /** + * disallow nested quantifiers that can be rewritten as one quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-trivially-nested-quantifier.html + */ + 'regexp/no-trivially-nested-quantifier'?: Linter.RuleEntry<[]> + /** + * disallow unused capturing group + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-unused-capturing-group.html + */ + 'regexp/no-unused-capturing-group'?: Linter.RuleEntry + /** + * disallow assertions that are known to always accept (or reject) + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-assertions.html + */ + 'regexp/no-useless-assertions'?: Linter.RuleEntry<[]> + /** + * disallow useless backreferences in regular expressions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-backreference.html + */ + 'regexp/no-useless-backreference'?: Linter.RuleEntry<[]> + /** + * disallow character class with one character + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-character-class.html + */ + 'regexp/no-useless-character-class'?: Linter.RuleEntry + /** + * disallow useless `$` replacements in replacement string + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-dollar-replacements.html + */ + 'regexp/no-useless-dollar-replacements'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary escape characters in RegExp + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-escape.html + */ + 'regexp/no-useless-escape'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary regex flags + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-flag.html + */ + 'regexp/no-useless-flag'?: Linter.RuleEntry + /** + * disallow unnecessarily non-greedy quantifiers + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-lazy.html + */ + 'regexp/no-useless-lazy'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary non-capturing group + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-non-capturing-group.html + */ + 'regexp/no-useless-non-capturing-group'?: Linter.RuleEntry + /** + * disallow quantifiers that can be removed + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-quantifier.html + */ + 'regexp/no-useless-quantifier'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary character ranges + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-range.html + */ + 'regexp/no-useless-range'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary elements in expression character classes + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-set-operand.html + */ + 'regexp/no-useless-set-operand'?: Linter.RuleEntry<[]> + /** + * disallow string disjunction of single characters in `\q{...}` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-string-literal.html + */ + 'regexp/no-useless-string-literal'?: Linter.RuleEntry<[]> + /** + * disallow unnecessary `{n,m}` quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-two-nums-quantifier.html + */ + 'regexp/no-useless-two-nums-quantifier'?: Linter.RuleEntry<[]> + /** + * disallow quantifiers with a maximum of zero + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-zero-quantifier.html + */ + 'regexp/no-zero-quantifier'?: Linter.RuleEntry<[]> + /** + * disallow the alternatives of lookarounds that end with a non-constant quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/optimal-lookaround-quantifier.html + */ + 'regexp/optimal-lookaround-quantifier'?: Linter.RuleEntry<[]> + /** + * require optimal quantifiers for concatenated quantifiers + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/optimal-quantifier-concatenation.html + */ + 'regexp/optimal-quantifier-concatenation'?: Linter.RuleEntry + /** + * enforce using character class + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-character-class.html + */ + 'regexp/prefer-character-class'?: Linter.RuleEntry + /** + * enforce using `\d` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-d.html + */ + 'regexp/prefer-d'?: Linter.RuleEntry + /** + * enforces escape of replacement `$` character (`$$`). + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-escape-replacement-dollar-char.html + */ + 'regexp/prefer-escape-replacement-dollar-char'?: Linter.RuleEntry<[]> + /** + * prefer lookarounds over capturing group that do not replace + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-lookaround.html + */ + 'regexp/prefer-lookaround'?: Linter.RuleEntry + /** + * enforce using named backreferences + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-named-backreference.html + */ + 'regexp/prefer-named-backreference'?: Linter.RuleEntry<[]> + /** + * enforce using named capture groups + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-named-capture-group.html + */ + 'regexp/prefer-named-capture-group'?: Linter.RuleEntry<[]> + /** + * enforce using named replacement + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-named-replacement.html + */ + 'regexp/prefer-named-replacement'?: Linter.RuleEntry + /** + * enforce using `+` quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-plus-quantifier.html + */ + 'regexp/prefer-plus-quantifier'?: Linter.RuleEntry<[]> + /** + * prefer predefined assertion over equivalent lookarounds + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-predefined-assertion.html + */ + 'regexp/prefer-predefined-assertion'?: Linter.RuleEntry<[]> + /** + * enforce using quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-quantifier.html + */ + 'regexp/prefer-quantifier'?: Linter.RuleEntry<[]> + /** + * enforce using `?` quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-question-quantifier.html + */ + 'regexp/prefer-question-quantifier'?: Linter.RuleEntry<[]> + /** + * enforce using character class range + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-range.html + */ + 'regexp/prefer-range'?: Linter.RuleEntry + /** + * enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-regexp-exec.html + */ + 'regexp/prefer-regexp-exec'?: Linter.RuleEntry<[]> + /** + * enforce that `RegExp#test` is used instead of `String#match` and `RegExp#exec` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-regexp-test.html + */ + 'regexp/prefer-regexp-test'?: Linter.RuleEntry<[]> + /** + * enforce using result array `groups` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-result-array-groups.html + */ + 'regexp/prefer-result-array-groups'?: Linter.RuleEntry + /** + * prefer character class set operations instead of lookarounds + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-set-operation.html + */ + 'regexp/prefer-set-operation'?: Linter.RuleEntry<[]> + /** + * enforce using `*` quantifier + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-star-quantifier.html + */ + 'regexp/prefer-star-quantifier'?: Linter.RuleEntry<[]> + /** + * enforce use of unicode codepoint escapes + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-unicode-codepoint-escapes.html + */ + 'regexp/prefer-unicode-codepoint-escapes'?: Linter.RuleEntry<[]> + /** + * enforce using `\w` + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-w.html + */ + 'regexp/prefer-w'?: Linter.RuleEntry<[]> + /** + * enforce the use of the `u` flag + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/require-unicode-regexp.html + */ + 'regexp/require-unicode-regexp'?: Linter.RuleEntry<[]> + /** + * enforce the use of the `v` flag + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/require-unicode-sets-regexp.html + */ + 'regexp/require-unicode-sets-regexp'?: Linter.RuleEntry<[]> + /** + * require simplify set operations + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/simplify-set-operations.html + */ + 'regexp/simplify-set-operations'?: Linter.RuleEntry<[]> + /** + * sort alternatives if order doesn't matter + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/sort-alternatives.html + */ + 'regexp/sort-alternatives'?: Linter.RuleEntry<[]> + /** + * enforces elements order in character class + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/sort-character-class-elements.html + */ + 'regexp/sort-character-class-elements'?: Linter.RuleEntry + /** + * require regex flags to be sorted + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/sort-flags.html + */ + 'regexp/sort-flags'?: Linter.RuleEntry<[]> + /** + * disallow not strictly valid regular expressions + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/strict.html + */ + 'regexp/strict'?: Linter.RuleEntry<[]> + /** + * enforce consistent usage of unicode escape or unicode codepoint escape + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/unicode-escape.html + */ + 'regexp/unicode-escape'?: Linter.RuleEntry + /** + * enforce consistent naming of unicode properties + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/unicode-property.html + */ + 'regexp/unicode-property'?: Linter.RuleEntry + /** + * use the `i` flag if it simplifies the pattern + * @see https://ota-meshi.github.io/eslint-plugin-regexp/rules/use-ignore-case.html + */ + 'regexp/use-ignore-case'?: Linter.RuleEntry<[]> /** * Disallow assignments that can lead to race conditions due to usage of `await` or `yield` * @see https://eslint.org/docs/latest/rules/require-atomic-updates @@ -9468,6 +9878,124 @@ type ReactStylePropObject = []|[{ allow?: string[] [k: string]: unknown | undefined }] +// ----- regexp/hexadecimal-escape ----- +type RegexpHexadecimalEscape = []|[("always" | "never")] +// ----- regexp/letter-case ----- +type RegexpLetterCase = []|[{ + caseInsensitive?: ("lowercase" | "uppercase" | "ignore") + unicodeEscape?: ("lowercase" | "uppercase" | "ignore") + hexadecimalEscape?: ("lowercase" | "uppercase" | "ignore") + controlEscape?: ("lowercase" | "uppercase" | "ignore") +}] +// ----- regexp/match-any ----- +type RegexpMatchAny = []|[{ + + allows?: [("[\\s\\S]" | "[\\S\\s]" | "[^]" | "dotAll"), ...(("[\\s\\S]" | "[\\S\\s]" | "[^]" | "dotAll"))[]] +}] +// ----- regexp/no-dupe-disjunctions ----- +type RegexpNoDupeDisjunctions = []|[{ + report?: ("all" | "trivial" | "interesting") + reportExponentialBacktracking?: ("none" | "certain" | "potential") + reportUnreachable?: ("certain" | "potential") +}] +// ----- regexp/no-lazy-ends ----- +type RegexpNoLazyEnds = []|[{ + ignorePartial?: boolean +}] +// ----- regexp/no-legacy-features ----- +type RegexpNoLegacyFeatures = []|[{ + staticProperties?: ("input" | "$_" | "lastMatch" | "$&" | "lastParen" | "$+" | "leftContext" | "$`" | "rightContext" | "$'" | "$1" | "$2" | "$3" | "$4" | "$5" | "$6" | "$7" | "$8" | "$9")[] + prototypeMethods?: ("compile")[] +}] +// ----- regexp/no-misleading-capturing-group ----- +type RegexpNoMisleadingCapturingGroup = []|[{ + reportBacktrackingEnds?: boolean +}] +// ----- regexp/no-misleading-unicode-character ----- +type RegexpNoMisleadingUnicodeCharacter = []|[{ + fixable?: boolean +}] +// ----- regexp/no-missing-g-flag ----- +type RegexpNoMissingGFlag = []|[{ + strictTypes?: boolean +}] +// ----- regexp/no-obscure-range ----- +type RegexpNoObscureRange = []|[{ + allowed?: (("all" | "alphanumeric") | [("all" | "alphanumeric")] | [("alphanumeric" | string), ...(("alphanumeric" | string))[]]) +}] +// ----- regexp/no-super-linear-backtracking ----- +type RegexpNoSuperLinearBacktracking = []|[{ + report?: ("certain" | "potential") +}] +// ----- regexp/no-super-linear-move ----- +type RegexpNoSuperLinearMove = []|[{ + report?: ("certain" | "potential") + ignoreSticky?: boolean + ignorePartial?: boolean +}] +// ----- regexp/no-unused-capturing-group ----- +type RegexpNoUnusedCapturingGroup = []|[{ + fixable?: boolean + allowNamed?: boolean +}] +// ----- regexp/no-useless-character-class ----- +type RegexpNoUselessCharacterClass = []|[{ + ignores?: string[] +}] +// ----- regexp/no-useless-flag ----- +type RegexpNoUselessFlag = []|[{ + ignore?: ("i" | "m" | "s" | "g" | "y")[] + strictTypes?: boolean +}] +// ----- regexp/no-useless-non-capturing-group ----- +type RegexpNoUselessNonCapturingGroup = []|[{ + allowTop?: (boolean | ("always" | "never" | "partial")) +}] +// ----- regexp/optimal-quantifier-concatenation ----- +type RegexpOptimalQuantifierConcatenation = []|[{ + capturingGroups?: ("ignore" | "report") +}] +// ----- regexp/prefer-character-class ----- +type RegexpPreferCharacterClass = []|[{ + minAlternatives?: number +}] +// ----- regexp/prefer-d ----- +type RegexpPreferD = []|[{ + insideCharacterClass?: ("ignore" | "range" | "d") +}] +// ----- regexp/prefer-lookaround ----- +type RegexpPreferLookaround = []|[{ + lookbehind?: boolean + strictTypes?: boolean +}] +// ----- regexp/prefer-named-replacement ----- +type RegexpPreferNamedReplacement = []|[{ + strictTypes?: boolean +}] +// ----- regexp/prefer-range ----- +type RegexpPreferRange = []|[{ + target?: (("all" | "alphanumeric") | [("all" | "alphanumeric")] | [("alphanumeric" | string), ...(("alphanumeric" | string))[]]) +}] +// ----- regexp/prefer-result-array-groups ----- +type RegexpPreferResultArrayGroups = []|[{ + strictTypes?: boolean +}] +// ----- regexp/sort-character-class-elements ----- +type RegexpSortCharacterClassElements = []|[{ + order?: ("\\s" | "\\w" | "\\d" | "\\p" | "*" | "\\q" | "[]")[] +}] +// ----- regexp/unicode-escape ----- +type RegexpUnicodeEscape = []|[("unicodeCodePointEscape" | "unicodeEscape")] +// ----- regexp/unicode-property ----- +type RegexpUnicodeProperty = []|[{ + generalCategory?: ("always" | "never" | "ignore") + key?: ("short" | "long" | "ignore") + property?: (("short" | "long" | "ignore") | { + binary?: ("short" | "long" | "ignore") + generalCategory?: ("short" | "long" | "ignore") + script?: ("short" | "long" | "ignore") + }) +}] // ----- require-atomic-updates ----- type RequireAtomicUpdates = []|[{ allowProperties?: boolean diff --git a/src/rules/__snapshots__/regexp.spec.ts.snap b/src/rules/__snapshots__/regexp.spec.ts.snap new file mode 100644 index 0000000..31ec74e --- /dev/null +++ b/src/rules/__snapshots__/regexp.spec.ts.snap @@ -0,0 +1,73 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`should create regexp rules 1`] = ` +{ + "no-control-regex": "error", + "no-empty-character-class": "off", + "no-invalid-regexp": "off", + "no-misleading-character-class": "error", + "no-regex-spaces": "error", + "no-useless-backreference": "off", + "prefer-regex-literals": "error", + "regexp/confusing-quantifier": "error", + "regexp/control-character-escape": "error", + "regexp/match-any": "error", + "regexp/negation": "error", + "regexp/no-contradiction-with-assertion": "error", + "regexp/no-dupe-characters-character-class": "error", + "regexp/no-dupe-disjunctions": "error", + "regexp/no-empty-alternative": "error", + "regexp/no-empty-capturing-group": "error", + "regexp/no-empty-character-class": "error", + "regexp/no-empty-group": "error", + "regexp/no-empty-lookarounds-assertion": "error", + "regexp/no-empty-string-literal": "error", + "regexp/no-escape-backspace": "error", + "regexp/no-extra-lookaround-assertions": "error", + "regexp/no-invalid-regexp": "error", + "regexp/no-invisible-character": "error", + "regexp/no-lazy-ends": "error", + "regexp/no-legacy-features": "error", + "regexp/no-misleading-capturing-group": "error", + "regexp/no-misleading-unicode-character": "error", + "regexp/no-missing-g-flag": "error", + "regexp/no-non-standard-flag": "error", + "regexp/no-obscure-range": "error", + "regexp/no-optional-assertion": "error", + "regexp/no-potentially-useless-backreference": "error", + "regexp/no-super-linear-backtracking": "error", + "regexp/no-trivially-nested-assertion": "error", + "regexp/no-trivially-nested-quantifier": "error", + "regexp/no-unused-capturing-group": "error", + "regexp/no-useless-assertions": "error", + "regexp/no-useless-backreference": "error", + "regexp/no-useless-character-class": "error", + "regexp/no-useless-dollar-replacements": "error", + "regexp/no-useless-escape": "error", + "regexp/no-useless-flag": "error", + "regexp/no-useless-lazy": "error", + "regexp/no-useless-non-capturing-group": "error", + "regexp/no-useless-quantifier": "error", + "regexp/no-useless-range": "error", + "regexp/no-useless-set-operand": "error", + "regexp/no-useless-string-literal": "error", + "regexp/no-useless-two-nums-quantifier": "error", + "regexp/no-zero-quantifier": "error", + "regexp/optimal-lookaround-quantifier": "error", + "regexp/optimal-quantifier-concatenation": "error", + "regexp/prefer-character-class": "error", + "regexp/prefer-d": "error", + "regexp/prefer-plus-quantifier": "error", + "regexp/prefer-predefined-assertion": "error", + "regexp/prefer-question-quantifier": "error", + "regexp/prefer-range": "error", + "regexp/prefer-set-operation": "error", + "regexp/prefer-star-quantifier": "error", + "regexp/prefer-unicode-codepoint-escapes": "error", + "regexp/prefer-w": "error", + "regexp/simplify-set-operations": "error", + "regexp/sort-flags": "error", + "regexp/strict": "error", + "regexp/use-ignore-case": "error", +} +`; diff --git a/src/rules/regexp.spec.ts b/src/rules/regexp.spec.ts new file mode 100644 index 0000000..bd729d7 --- /dev/null +++ b/src/rules/regexp.spec.ts @@ -0,0 +1,5 @@ +import { regexpRules } from "./regexp"; + +test("should create regexp rules", () => { + expect(regexpRules).toMatchSnapshot(); +}); diff --git a/src/rules/regexp.ts b/src/rules/regexp.ts new file mode 100644 index 0000000..bd59272 --- /dev/null +++ b/src/rules/regexp.ts @@ -0,0 +1,13 @@ +import * as regexpPlugin from "eslint-plugin-regexp"; + +import type { Rules } from "../types"; + +export const regexpRules = { + ...regexpPlugin.configs["flat/recommended"].rules, + "regexp/confusing-quantifier": "error", + "regexp/no-empty-alternative": "error", + "regexp/no-lazy-ends": "error", + "regexp/no-potentially-useless-backreference": "error", + "regexp/no-useless-flag": "error", + "regexp/optimal-lookaround-quantifier": "error", +} satisfies Rules;