8000 chore: enable `eslint-plugin-regexp` (#9948) · ronami/typescript-eslint@7919b60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7919b60

Browse files
authored
chore: enable eslint-plugin-regexp (typescript-eslint#9948)
* eslint-plugin-regexp * no-dupe-disjunctions: Unexpected useless alternative. This alternative is a strict subset of '\/?' and can be removed. * no-useless-character-class: Unexpected character class with one character. Can remove brackets * no-useless-flag: The 'm' flag is unnecessary because the pattern does not contain start (^) or end ($) assertions * no-useless-lazy: Unexpected non-greedy constant quantifier. The quantifier is effectively possessive, so it doesn't matter whether it is greedy or not * no-useless-non-capturing-group: Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex * prefer-quantifier: Unexpected consecutive same characters. Use '{4}' instead * prefer-question-quantifier: Unexpected group '(?:...|)'. Use '(?:...)? instead * prefer-w: Unexpected character class ranges '[a-z0-9_]'. Use '\w' instead
1 parent dbcade8 commit 7919b60

File tree

9 files changed

+75
-12
lines changed

9 files changed

+75
-12
lines changed

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
1515
import perfectionistPlugin from 'eslint-plugin-perfectionist';
1616
import reactPlugin from 'eslint-plugin-react';
1717
import reactHooksPlugin from 'eslint-plugin-react-hooks';
18+
import regexpPlugin from 'eslint-plugin-regexp';
1819
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
1920
import sonarjsPlugin from 'eslint-plugin-sonarjs';
2021
import unicornPlugin from 'eslint-plugin-unicorn';
@@ -43,6 +44,7 @@ export default tseslint.config(
4344
['react-hooks']: fixupPluginRules(reactHooksPlugin),
4445
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
4546
['react']: fixupPluginRules(reactPlugin),
47+
['regexp']: regexpPlugin,
4648
['simple-import-sort']: simpleImportSortPlugin,
4749
['sonarjs']: sonarjsPlugin,
4850
['unicorn']: unicornPlugin,
@@ -318,6 +320,15 @@ export default tseslint.config(
318320
'jsdoc/require-yields': 'off',
319321
'jsdoc/tag-lines': 'off',
320322

323+
'regexp/no-dupe-disjunctions': 'error',
324+
'regexp/no-useless-character-class': 'error',
325+
'regexp/no-useless-flag': 'error',
326+
'regexp/no-useless-lazy': 'error',
327+
'regexp/no-useless-non-capturing-group': 'error',
328+
'regexp/prefer-quantifier': 'error',
329+
'regexp/prefer-question-quantifier': 'error',
330+
'regexp/prefer-w': 'error',
331+
321332
'sonarjs/no-duplicated-branches': 'error',
322333

323334
//

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"eslint-plugin-perfectionist": "^3.2.0",
103103
"eslint-plugin-react": "^7.34.1",
104104
"eslint-plugin-react-hooks": "^4.6.0",
105+
"eslint-plugin-regexp": "^2.6.0",
105106
"eslint-plugin-simple-import-sort": "^10.0.0",
106107
"eslint-plugin-sonarjs": "^1.0.4",
107108
"eslint-plugin-unicorn": "^55.0.0",

packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const a = 1;
4646
*/
4747

4848
const prettierConfig = prettier.resolveConfig(__dirname) ?? {};
49-
const START_OF_LINE_WHITESPACE_MATCHER = /^([ ]*)/;
49+
const START_OF_LINE_WHITESPACE_MATCHER = /^( *)/;
5050
const BACKTICK_REGEX = /`/g;
5151
const TEMPLATE_EXPR_OPENER = /\$\{/g;
5252

packages/rule-tester/src/utils/flat-config-schema.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ function assertIsRuleSeverity(ruleId: string, value: unknown): void {
216216
function assertIsPluginMemberName(
217217
value: unknown,
218218
): asserts value is PluginMemberName {
219-
if (
220-
typeof value !== 'string' ||
221-
!/[@a-z0-9-_$]+(?:\/(?:[a-z0-9-_$]+))+$/iu.test(value)
222-
) {
219+
if (typeof value !== 'string' || !/[@\w$-]+(?:\/[\w$-]+)+$/iu.test(value)) {
223220
throw new TypeError(
224221
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
225222
`Expected string in the form "pluginName/objectName" but found "${value}".`,

packages/rule-tester/src/utils/interpolate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ReportDescriptorMessageData } from '@typescript-eslint/utils/ts-es
66
* Returns a global expression matching placeholders in messages.
77
*/
88
export function getPlaceholderMatcher(): RegExp {
9-
return /\{\{([^{}]+?)\}\}/gu;
9+
return /\{\{([^{}]+)\}\}/gu;
1010
}
1111

1212
export function interpolate(

packages/scope-manager/tests/fixtures.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const fixtures = glob
3636
};
3737
});
3838

39-
const FOUR_SLASH = /^\/\/\/\/[ ]+@(\w+)[ ]*=[ ]*(.+)$/;
39+
const FOUR_SLASH = /^\/{4} +@(\w+) *= *(.+)$/;
4040
const QUOTED_STRING = /^["'](.+?)['"]$/;
4141
type ALLOWED_VALUE = ['boolean' | 'number' | 'string', Set<unknown>?];
4242
co 37C3 nst ALLOWED_OPTIONS: Map<string, ALLOWED_VALUE> = new Map<

packages/typescript-estree/tests/lib/parse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const fastGlobSyncMock = jest.mocked(fastGlobModule.sync);
5858
* Aligns paths between environments, node for windows uses `\`, for linux and mac uses `/`
5959
*/
6060
function alignErrorPath(error: Error): never {
61-
error.message = error.message.replaceAll(/\\(?!["])/gm, '/');
61+
error.message = error.message.replaceAll(/\\(?!")/g, '/');
6262
throw error;
6363
}
6464

packages/website-eslint/src/mock/path.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ function normalizeArray(parts, allowAboveRoot) {
5151

5252
// Split a filename into [root, dir, basename, ext], unix version
5353
// 'root' is just a slash, or nothing.
54-
const splitPathRe =
55-
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
54+
const splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^/]+?)?(\.[^./]*|))\/*$/;
5655
const splitPath = function (filename) {
5756
return splitPathRe.exec(filename).slice(1);
5857
};

yarn.lock

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ __metadata:
33593359
languageName: node
33603360
linkType: hard
33613361

3362-
"@eslint-community/regexpp@npm:^4.10.0, @eslint-community/regexpp@npm:^4.6.1":
3362+
"@eslint-community/regexpp@npm:^4.10.0, @eslint-community/regexpp@npm:^4.6.1, @eslint-community/regexpp@npm:^4.8.0, @eslint-community/regexpp@npm:^4.9.1":
33633363
version: 4.11.0
33643364
resolution: "@eslint-community/regexpp@npm:4.11.0"
33653365
checksum: 97d2fe46690b69417a551bd19a3dc53b6d9590d2295c43cc4c4e44e64131af541e2f4a44d5c12e87de990403654d3dae9d33600081f3a2f0386b368abc9111ec
@@ -5875,6 +5875,7 @@ __metadata:
58755875
eslint-plugin-perfectionist: ^3.2.0
58765876
eslint-plugin-react: ^7.34.1
58775877
eslint-plugin-react-hooks: ^4.6.0
5878+
eslint-plugin-regexp: ^2.6.0
58785879
eslint-plugin-simple-import-sort: ^10.0.0
58795880
eslint-plugin-sonarjs: ^1.0.4
58805881
eslint-plugin-unicorn: ^55.0.0
@@ -7908,7 +7909,7 @@ __metadata:
79087909
languageName: node
79097910
linkType: hard
79107911

7911-
"comment-parser@npm:1.4.1":
7912+
"comment-parser@npm:1.4.1, comment-parser@npm:^1.4.0":
79127913
version: 1.4.1
79137914
resolution: "comment-parser@npm:1.4.1"
79147915
checksum: e0f6f60c5139689c4b1b208ea63e0730d9195a778e90dd909205f74f00b39eb0ead05374701ec5e5c29d6f28eb778cd7bc41c1366ab1d271907f1def132d6bf1
@@ -9917,6 +9918,23 @@ __metadata:
99179918
languageName: node
99189919
linkType: hard
99199920

9921+
"eslint-plugin-regexp@npm:^2.6.0":
9922+
version: 2.6.0
9923+
resolution: "eslint-plugin-regexp@npm:2.6.0"
9924+
dependencies:
9925+
"@eslint-community/eslint-utils": ^4.2.0
9926+
"@eslint-community/regexpp": ^4.9.1
9927+
comment-parser: ^1.4.0
9928+
jsdoc-type-pratt-parser: ^4.0.0
9929+
refa: ^0.12.1
9930+
regexp-ast-analysis: ^0.7.1
9931+
scslre: ^0.3.0
9932+
peerDependencies:
9933+
eslint: ">=8.44.0"
9934+
checksum: 35063ed6cefaee69bf92591591c2477430ad0ff68aa08201408fc5d19088b021e96bf1b6535af27d9675708ef1594950454463c88ad252b6b7fd9c1e5b832e7c
9935+
languageName: node
9936+
linkType: hard
9937+
99209938
"eslint-plugin-simple-import-sort@npm:^10.0.0":
99219939
version: 10.0.0
99229940
resolution: "eslint-plugin-simple-import-sort@npm:10.0.0"
@@ -13240,6 +13258,13 @@ __metadata:
1324013258
languageName: node
1324113259
linkType: hard
1324213260

13261+
"jsdoc-type-pratt-parser@npm:^4.0.0":
13262+
version: 4.1.0
13263+
resolution: "jsdoc-type-pratt-parser@npm:4.1.0"
13264+
checksum: e7642a508b090b1bdf17775383000ed71013c38e1231c1e576e5374636e8baf7c3fae8bf0252f5e1d3397d95efd56e8c8a5dd1a0de76d05d1499cbcb3c325bc3
13265+
languageName: node
13266+
linkType: hard
13267+
1324313268
"jsdoc-type-pratt-parser@npm:~4.0.0":
1324413269
version: 4.0.0
1324513270
resolution: "jsdoc-type-pratt-parser@npm:4.0.0"
@@ -17167,6 +17192,15 @@ __metadata:
1716717192
languageName: node
1716817193
linkType: hard
1716917194

17195+
"refa@npm:^0.12.0, refa@npm:^0.12.1":
17196+
version: 0.12.1
17197+
resolution: "refa@npm:0.12.1"
17198+
dependencies:
17199+
"@eslint-community/regexpp": ^4.8.0
17200+
checksum: 845cef54786884d5f09558dd600cec20ee354ebbcabd206503d5cc5d63d22bb69dee8b66bf8411de622693fc5c2b9d42b9cf1e5e6900c538ee333eefb5cc1b41
17201+
languageName: node
17202+
linkType: hard
17203+
1717017204
"reflect.getprototypeof@npm:^1.0.4":
1717117205
version: 1.0.4
1717217206
resolution: "reflect.getprototypeof@npm:1.0.4"
@@ -17213,6 +17247,16 @@ __metadata:
1721317247
languageName: node
1721417248
linkType: hard
1721517249

17250+
"regexp-ast-analysis@npm:^0.7.0, regexp-ast-analysis@npm:^0.7.1":
17251+
version: 0.7.1
17252+
resolution: "regexp-ast-analysis@npm:0.7.1"
17253+
dependencies:
17254+
"@eslint-community/regexpp": ^4.8.0
17255+
refa: ^0.12.1
17256+
checksum: c1c47fea637412d8362a9358b1b2952a6ab159daaede2244c05e79c175844960259c88e30072e4f81a06e5ac1c80f590b14038b17bc8cff09293f752cf843b1c
17257+
languageName: node
17258+
linkType: hard
17259+
1721617260
"regexp-tree@npm:^0.1.27":
1721717261
version: 0.1.27
1721817262
resolution: "regexp-tree@npm:0.1.27"
@@ -17806,6 +17850,17 @@ __metadata:
1780617850
languageName: node
1780717851
linkType: hard
1780817852

17853+
"scslre@npm:^0.3.0":
17854+
version: 0.3.0
17855+
resolution: "scslre@npm:0.3.0"
17856+
dependencies:
17857+
"@eslint-community/regexpp": ^4.8.0
17858+
refa: ^0.12.0
17859+
regexp-ast-analysis: ^0.7.0
17860+
checksum: a89d4fe5dbf632cae14cc1e53c9d18012924cc88d6615406ad90190d2b9957fc8db16994c2023235af1b6a6c25290b089eb4c26e47d21b05073b933be5ca9d33
17861+
languageName: node
17862+
linkType: hard
17863+
1780917864
"section-matter@npm:^1.0.0":
1781017865
version: 1.0.0
1781117866
resolution: "section-matter@npm:1.0.0"

0 commit comments

Comments
 (0)
0