|
| 1 | +import pluginRegexp from 'eslint-plugin-regexp'; |
| 2 | + |
| 3 | +export function getRegexpConfig({files}) { |
| 4 | + return { |
| 5 | + name: 'xo/regexp', |
| 6 | + plugins: { |
| 7 | + regexp: pluginRegexp, |
| 8 | + }, |
| 9 | + files, |
| 10 | + rules: { |
| 11 | + // The plugin provides better versions of these core rules. |
| 12 | + 'no-invalid-regexp': 'off', |
| 13 | + 'no-useless-backreference': 'off', |
| 14 | + 'no-empty-character-class': 'off', |
| 15 | + |
| 16 | + // Possible Errors |
| 17 | + 'regexp/no-contradiction-with-assertion': 'error', |
| 18 | + 'regexp/no-control-character': 'error', |
| 19 | + 'regexp/no-dupe-disjunctions': 'error', |
| 20 | + 'regexp/no-empty-alternative': 'error', |
| 21 | + 'regexp/no-empty-capturing-group': 'error', |
| 22 | + 'regexp/no-empty-character-class': 'error', |
| 23 | + 'regexp/no-empty-group': 'error', |
| 24 | + 'regexp/no-empty-lookarounds-assertion': 'error', |
| 25 | + 'regexp/no-escape-backspace': 'error', |
| 26 | + 'regexp/no-invalid-regexp': 'error', |
| 27 | + 'regexp/no-lazy-ends': 'error', |
| 28 | + 'regexp/no-misleading-capturing-group': 'error', |
| 29 | + 'regexp/no-misleading-unicode-character': 'error', |
| 30 | + 'regexp/no-missing-g-flag': 'error', |
| 31 | + 'regexp/no-optional-assertion': 'error', |
| 32 | + 'regexp/no-potentially-useless-backreference': 'error', |
| 33 | + 'regexp/no-super-linear-backtracking': 'error', |
| 34 | + 'regexp/no-super-linear-move': 'error', |
| 35 | + 'regexp/no-useless-assertions': 'error', |
| 36 | + 'regexp/no-useless-backreference': 'error', |
| 37 | + 'regexp/no-useless-dollar-replacements': 'error', |
| 38 | + 'regexp/strict': 'error', |
| 39 | + |
| 40 | + // Best Practices |
| 41 | + 'regexp/confusing-quantifier': 'error', |
| 42 | + 'regexp/control-character-escape': 'error', |
| 43 | + 'regexp/negation': 'error', |
| 44 | + 'regexp/no-dupe-characters-character-class': 'error', |
| 45 | + 'regexp/no-empty-string-literal': 'error', |
| 46 | + 'regexp/no-extra-lookaround-assertions': 'error', |
| 47 | + 'regexp/no-invisible-character': 'error', |
| 48 | + 'regexp/no-legacy-features': 'error', |
| 49 | + 'regexp/no-non-standard-flag': 'error', |
| 50 | + 'regexp/no-obscure-range': 'error', |
| 51 | + 'regexp/no-octal': 'error', |
| 52 | + 'regexp/no-standalone-backslash': 'error', |
| 53 | + 'regexp/no-trivially-nested-assertion': 'error', |
| 54 | + 'regexp/no-trivially-nested-quantifier': 'error', |
| 55 | + 'regexp/no-unused-capturing-group': 'error', |
| 56 | + 'regexp/no-useless-character-class': 'error', |
| 57 | + 'regexp/no-useless-flag': 'error', |
| 58 | + 'regexp/no-useless-lazy': 'error', |
| 59 | + 'regexp/no-useless-quantifier': 'error', |
| 60 | + 'regexp/no-useless-range': 'error', |
| 61 | + 'regexp/no-useless-set-operand': 'error', |
| 62 | + 'regexp/no-useless-string-literal': 'error', |
| 63 | + 'regexp/no-useless-two-nums-quantifier': 'error', |
| 64 | + 'regexp/no-zero-quantifier': 'error', |
| 65 | + 'regexp/optimal-lookaround-quantifier': 'error', |
| 66 | + 'regexp/optimal-quantifier-concatenation': 'error', |
| 67 | + 'regexp/prefer-escape-replacement-dollar-char': 'error', |
| 68 | + 'regexp/prefer-predefined-assertion': 'error', |
| 69 | + |
| 70 | + // I needs an option to only activate when at least 3 components. |
| 71 | + // 'regexp/prefer-quantifier': [ |
| 72 | + // 'off', |
| 73 | + // { |
| 74 | + // allows: [ |
| 75 | + // 'www', |
| 76 | + // '\\d\\d', |
| 77 | + // ], |
| 78 | + // }, |
| 79 | + // ], |
| 80 | + |
| 81 | + 'regexp/prefer-range': 'error', |
| 82 | + 'regexp/prefer-regexp-exec': 'error', |
| 83 | + 'regexp/prefer-regexp-test': 'error', |
| 84 | + 'regexp/prefer-set-operation': 'error', |
| 85 | + 'regexp/require-unicode-regexp': 'off', // Conflicts with `require-unicode-regexp`. |
| 86 | + 'regexp/require-unicode-sets-regexp': 'off', // Conflicts with `require-unicode-regexp`. |
| 87 | + 'regexp/simplify-set-operations': 'error', |
| 88 | + 'regexp/sort-alternatives': 'off', // Too opinionated about ordering. |
| 89 | + 'regexp/use-ignore-case': 'error', |
| 90 | + |
| 91 | + // Stylistic |
| 92 | + 'regexp/grapheme-string-literal': 'error', |
| 93 | + 'regexp/hexadecimal-escape': [ |
| 94 | + 'error', |
| 95 | + 'always', |
| 96 | + ], |
| 97 | + 'regexp/letter-case': [ |
| 98 | + 'error', |
| 99 | + { |
| 100 | + caseInsensitive: 'lowercase', |
| 101 | + unicodeEscape: 'lowercase', |
| 102 | + hexadecimalEscape: 'lowercase', |
| 103 | + controlEscape: 'uppercase', |
| 104 | + }, |
| 105 | + ], |
| 106 | + 'regexp/match-any': 'error', |
| 107 | + 'regexp/no-useless-escape': 'error', |
| 108 | + 'regexp/no-useless-non-capturing-group': 'error', |
| 109 | + 'regexp/prefer-character-class': 'error', |
| 110 | + 'regexp/prefer-d': 'error', |
| 111 | + 'regexp/prefer-lookaround': [ |
| 112 | + 'error', |
| 113 | + { |
| 114 | + lookbehind: true, |
| 115 | + strictTypes: true, |
| 116 | + }, |
| 117 | + ], |
| 118 | + 'regexp/prefer-named-backreference': 'error', |
| 119 | + 'regexp/prefer-named-capture-group': 'error', |
| 120 | + 'regexp/prefer-named-replacement': 'error', |
| 121 | + 'regexp/prefer-plus-quantifier': 'error', |
| 122 | + 'regexp/prefer-question-quantifier': 'error', |
| 123 | + 'regexp/prefer-result-array-groups': 'error', |
| 124 | + 'regexp/prefer-star-quantifier': 'error', |
| 125 | + 'regexp/prefer-unicode-codepoint-escapes': 'error', |
| 126 | + 'regexp/prefer-w': 'error', |
| 127 | + 'regexp/sort-character-class-elements': 'error', |
| 128 | + 'regexp/sort-flags': 'error', |
| 129 | + 'regexp/unicode-escape': 'error', |
| 130 | + 'regexp/unicode-property': [ |
| 131 | + 'error', |
| 132 | + { |
| 133 | + generalCategory: 'never', |
| 134 | + key: 'ignore', |
| 135 | + property: { |
| 136 | + binary: 'long', |
| 137 | + generalCategory: 'long', |
| 138 | + script: 'long', |
| 139 | + }, |
| 140 | + }, |
| 141 | + ], |
| 142 | + }, |
| 143 | + }; |
| 144 | +} |
0 commit comments