Skip to content

Commit 5c2165c

Browse files
authored
fix: use v flag in regexes; match emojis for sentence terminator; fixes #1433 (#1437)
BREAKING CHANGE: Uses `v` flag instead of `u` flag by default for regular expressions
1 parent b462e44 commit 5c2165c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+169
-150
lines changed

.README/rules/check-examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ syntax highlighting). The following options determine whether a given
3737
exists or matches, the whole matching expression will be used.
3838
An example might be ````"^```(?:js|javascript)([\\s\\S]*)```\s*$"````
3939
to only match explicitly fenced JavaScript blocks. Defaults to only
40-
using the `u` flag, so to add your own flags, encapsulate your
40+
using the `v` flag, so to add your own flags, encapsulate your
4141
expression as a string, but like a literal, e.g., ````/```js.*```/gi````.
4242
Note that specifying a global regular expression (i.e., with `g`) will
4343
allow independent linting of matched blocks within a single `@example`.
4444
* `rejectExampleCodeRegex` - Regex blacklist which rejects
4545
non-lintable examples (has priority over `exampleCodeRegex`). An example
4646
might be ```"^`"``` to avoid linting fenced blocks which may indicate
4747
a non-JavaScript language. See `exampleCodeRegex` on how to add flags
48-
if the default `u` is not sufficient.
48+
if the default `v` is not sufficient.
4949

5050
If neither is in use, all examples will be matched. Note also that even if
5151
`captionRequired` is not set, any initial `<caption>` will be stripped out

.README/rules/check-values.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ If present as an array, will be used in place of SPDX identifiers.
3434

3535
### `licensePattern`
3636

37-
A string to be converted into a `RegExp` (with `u` flag) and whose first
37+
A string to be converted into a `RegExp` (with `v` flag) and whose first
3838
parenthetical grouping, if present, will match the portion of the license
3939
description to check (if no grouping is present, then the whole portion
40-
matched will be used). Defaults to `/([^\n\r]*)/gu`, i.e., the SPDX expression
40+
matched will be used). Defaults to `/([^\n\r]*)/gv`, i.e., the SPDX expression
4141
is expected before any line breaks.
4242

4343
Note that the `/` delimiters are optional, but necessary to add flags.
4444

45-
Defaults to using the `u` flag, so to add your own flags, encapsulate
46-
your expression as a string, but like a literal, e.g., `/^mit$/ui`.
45+
Defaults to using the `v` flag, so to add your own flags, encapsulate
46+
your expression as a string, but like a literal, e.g., `/^mit$/vi`.
4747

4848
### `numericOnlyVariation`
4949

.README/rules/match-description.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The default is this basic expression to match English sentences (Support
88
for Unicode upper case may be added in a future version when it can be handled
99
by our supported Node versions):
1010

11-
``^\n?([A-Z`\\d_][\\s\\S]*[.?!`]\\s*)?$``
11+
``^\n?([A-Z`\\d_][\\s\\S]*[.?!`\\p{RGI_Emoji}]\\s*)?$``
1212

1313
Applies by default to the jsdoc block description and to the following tags:
1414

@@ -19,9 +19,9 @@ Applies by default to the jsdoc block description and to the following tags:
1919

2020
In addition, the `tags` option (see below) may be used to match other tags.
2121

22-
The default (and all regex options) defaults to using (only) the `u` flag, so
22+
The default (and all regex options) defaults to using (only) the `v` flag, so
2323
to add your own flags, encapsulate your expression as a string, but like a
24-
literal, e.g., `/[A-Z].*\\./ui`.
24+
literal, e.g., `/[A-Z].*\\./vi`.
2525

2626
Note that `/` delimiters are optional, but necessary to add flags (besides
2727
`u`).

.README/rules/require-param.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export const bboxToObj = function ({x, y, width, height}) {
307307
```
308308

309309
By default `checkTypesPattern` is set to
310-
`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/u`,
310+
`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/v`,
311311
meaning that destructuring will be required only if the type of the `@param`
312312
(the text between curly brackets) is a match for "Object" or "Array" (with or
313313
without initial caps), "PlainObject", or "GenericObject", "GenericArray" (or
@@ -317,8 +317,8 @@ parameters.
317317

318318
Note that the `/` delimiters are optional, but necessary to add flags.
319319

320-
Defaults to using (only) the `u` flag, so to add your own flags, encapsulate
321-
your expression as a string, but like a literal, e.g., `/^object$/ui`.
320+
Defaults to using (only) the `v` flag, so to add your own flags, encapsulate
321+
your expression as a string, but like a literal, e.g., `/^object$/vi`.
322322

323323
You could set this regular expression to a more expansive list, or you
324324
could restrict it such that even types matching those strings would not

docs/rules/check-examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ syntax highlighting). The following options determine whether a given
5656
exists or matches, the whole matching expression will be used.
5757
An example might be ````"^```(?:js|javascript)([\\s\\S]*)```\s*$"````
5858
to only match explicitly fenced JavaScript blocks. Defaults to only
59-
using the `u` flag, so to add your own flags, encapsulate your
59+
using the `v` flag, so to add your own flags, encapsulate your
6060
expression as a string, but like a literal, e.g., ````/```js.*```/gi````.
6161
Note that specifying a global regular expression (i.e., with `g`) will
6262
allow independent linting of matched blocks within a single `@example`.
6363
* `rejectExampleCodeRegex` - Regex blacklist which rejects
6464
non-lintable examples (has priority over `exampleCodeRegex`). An example
6565
might be ```"^`"``` to avoid linting fenced blocks which may indicate
6666
a non-JavaScript language. See `exampleCodeRegex` on how to add flags
67-
if the default `u` is not sufficient.
67+
if the default `v` is not sufficient.
6868

6969
If neither is in use, all examples will be matched. Note also that even if
7070
`captionRequired` is not set, any initial `<caption>` will be stripped out

docs/rules/check-values.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ If present as an array, will be used in place of SPDX identifiers.
5252
<a name="check-values-options-licensepattern"></a>
5353
### <code>licensePattern</code>
5454

55-
A string to be converted into a `RegExp` (with `u` flag) and whose first
55+
A string to be converted into a `RegExp` (with `v` flag) and whose first
5656
parenthetical grouping, if present, will match the portion of the license
5757
description to check (if no grouping is present, then the whole portion
58-
matched will be used). Defaults to `/([^\n\r]*)/gu`, i.e., the SPDX expression
58+
matched will be used). Defaults to `/([^\n\r]*)/gv`, i.e., the SPDX expression
5959
is expected before any line breaks.
6060

6161
Note that the `/` delimiters are optional, but necessary to add flags.
6262

63-
Defaults to using the `u` flag, so to add your own flags, encapsulate
64-
your expression as a string, but like a literal, e.g., `/^mit$/ui`.
63+
Defaults to using the `v` flag, so to add your own flags, encapsulate
64+
your expression as a string, but like a literal, e.g., `/^mit$/vi`.
6565

6666
<a name="user-content-check-values-options-numericonlyvariation"></a>
6767
<a name="check-values-options-numericonlyvariation"></a>

docs/rules/match-description.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The default is this basic expression to match English sentences (Support
2020
for Unicode upper case may be added in a future version when it can be handled
2121
by our supported Node versions):
2222

23-
``^\n?([A-Z`\\d_][\\s\\S]*[.?!`]\\s*)?$``
23+
``^\n?([A-Z`\\d_][\\s\\S]*[.?!`\\p{RGI_Emoji}]\\s*)?$``
2424

2525
Applies by default to the jsdoc block description and to the following tags:
2626

@@ -31,9 +31,9 @@ Applies by default to the jsdoc block description and to the following tags:
3131

3232
In addition, the `tags` option (see below) may be used to match other tags.
3333

34-
The default (and all regex options) defaults to using (only) the `u` flag, so
34+
The default (and all regex options) defaults to using (only) the `v` flag, so
3535
to add your own flags, encapsulate your expression as a string, but like a
36-
literal, e.g., `/[A-Z].*\\./ui`.
36+
literal, e.g., `/[A-Z].*\\./vi`.
3737

3838
Note that `/` delimiters are optional, but necessary to add flags (besides
3939
`u`).
@@ -970,7 +970,7 @@ function quux (foo) {
970970
* - the `loadScript` option is set to `true`.
971971
* @param enabled `true` to enable, `false` to disable. Default: `true`.
972972
*/
973-
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"],"mainDescription":"/^[A-Z`-].*\\.$/us","matchDescription":"^([A-Z`-].*(\\.|:)|-\\s.*)$","tags":{"param":true,"returns":true}}]
973+
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"],"mainDescription":"/^[A-Z`\\-].*\\.$/vs","matchDescription":"^([A-Z`\\-].*(\\.|:)|-\\s.*)$","tags":{"param":true,"returns":true}}]
974974

975975
/**
976976
* @constructor
@@ -998,5 +998,10 @@ function foo(): void;
998998
function quux () {
999999
}
10001000
// "jsdoc/match-description": ["error"|"warn", {"nonemptyTags":false}]
1001+
1002+
/**
1003+
* Example text. 🙂
1004+
*/
1005+
export const example = () => { };
10011006
````
10021007

docs/rules/match-name.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function quux () {}
183183
* @template
184184
*/
185185
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^$/","tags":["template"]}]}]
186-
// Message: Only allowing names not matching `/^$/u` but found "".
186+
// Message: Only allowing names not matching `/^$/v` but found "".
187187
````
188188

189189

docs/rules/require-param.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export const bboxToObj = function ({x, y, width, height}) {
362362
```
363363

364364
By default `checkTypesPattern` is set to
365-
`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/u`,
365+
`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/v`,
366366
meaning that destructuring will be required only if the type of the `@param`
367367
(the text between curly brackets) is a match for "Object" or "Array" (with or
368368
without initial caps), "PlainObject", or "GenericObject", "GenericArray" (or
@@ -372,8 +372,8 @@ parameters.
372372

373373
Note that the `/` delimiters are optional, but necessary to add flags.
374374

375-
Defaults to using (only) the `u` flag, so to add your own flags, encapsulate
376-
your expression as a string, but like a literal, e.g., `/^object$/ui`.
375+
Defaults to using (only) the `v` flag, so to add your own flags, encapsulate
376+
your expression as a string, but like a literal, e.g., `/^object$/vi`.
377377

378378
You could set this regular expression to a more expansive list, or you
379379
could restrict it such that even types matching those strings would not

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export default [
3939
'linebreak-style': 0,
4040
'no-inline-comments': 0,
4141
'prefer-named-capture-group': 0,
42+
'require-unicode-regexp': [
43+
'error',
44+
{
45+
requireFlag: 'v',
46+
},
47+
],
4248
'unicorn/import-index': 0,
4349
'unicorn/no-array-reduce': 0,
4450
'unicorn/no-unsafe-regex': 0,

0 commit comments

Comments
 (0)