Skip to content

Commit d15dec7

Browse files
Merge branch 'master' into unicode-escape
2 parents f219467 + a7689af commit d15dec7

File tree

112 files changed

+1035
-531
lines changed

Some content is hidden

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

112 files changed

+1035
-531
lines changed

Diff for: .changeset/brown-dragons-dance.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/no-non-standard-flag` rule

Diff for: .changeset/clever-jobs-clap.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Improve `regexp/strict` rule to ignore patterns with v flag

Diff for: .changeset/curvy-shoes-kiss.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/prefer-d` rule

Diff for: .changeset/heavy-rings-reply.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/negation` rule

Diff for: .changeset/loud-flowers-search.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Improve `regexp/require-unicode-regexp` rule to allow patterns with v flag

Diff for: .changeset/pre.json

+9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55
"eslint-plugin-regexp": "1.15.0"
66
},
77
"changesets": [
8+
"brown-dragons-dance",
89
"calm-onions-yell",
10+
"clever-jobs-clap",
11+
"curvy-shoes-kiss",
912
"cyan-waves-notice",
13+
"heavy-rings-reply",
1014
"hungry-spoons-mix",
1115
"khaki-colts-tell",
16+
"loud-flowers-search",
1217
"lovely-brooms-explode",
1318
"short-dingos-dance",
19+
"six-squids-look",
1420
"small-doors-lie",
21+
"smart-chefs-poke",
22+
"tasty-penguins-cheat",
1523
"thin-ears-relax",
24+
"warm-ladybugs-wonder",
1625
"wicked-rules-rhyme"
1726
]
1827
}

Diff for: .changeset/six-squids-look.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/no-useless-escape` rule

Diff for: .changeset/smart-chefs-poke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/no-misleading-unicode-character` rule

Diff for: .changeset/tasty-penguins-cheat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
`prefer-w`: Add support for `v` flag

Diff for: .changeset/warm-ladybugs-wonder.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Improve `regexp/no-invalid-regexp` rule to check for unknown pattern flags.

Diff for: .eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
"plugin:regexp/recommended",
1818
],
1919
rules: {
20-
"require-jsdoc": "error",
20+
"require-jsdoc": "off",
2121
"no-warning-comments": "warn",
2222
"no-lonely-if": "off",
2323
complexity: "off",

Diff for: CHANGELOG.md

+30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# eslint-plugin-regexp
22

3+
## 2.0.0-next.5
4+
5+
### Minor Changes
6+
7+
- Add support for v flag to `regexp/prefer-d` rule ([#602](https://github.com/ota-meshi/eslint-plugin-regexp/pull/602))
8+
9+
- Add support for v flag to `regexp/negation` rule ([#560](https://github.com/ota-meshi/eslint-plugin-regexp/pull/560))
10+
11+
- Improve `regexp/require-unicode-regexp` rule to allow patterns with v flag ([#586](https://github.com/ota-meshi/eslint-plugin-regexp/pull/586))
12+
13+
- Add support for v flag to `regexp/no-useless-escape` rule ([#585](https://github.com/ota-meshi/eslint-plugin-regexp/pull/585))
14+
15+
- Add support for v flag to `regexp/no-misleading-unicode-character` rule ([#584](https://github.com/ota-meshi/eslint-plugin-regexp/pull/584))
16+
17+
- `prefer-w`: Add support for `v` flag ([#578](https://github.com/ota-meshi/eslint-plugin-regexp/pull/578))
18+
19+
## 2.0.0-next.4
20+
21+
### Minor Changes
22+
23+
- Add support for v flag to `regexp/no-non-standard-flag` rule ([#596](https://github.com/ota-meshi/eslint-plugin-regexp/pull/596))
24+
25+
- Improve `regexp/strict` rule to ignore patterns with v flag ([#591](https://github.com/ota-meshi/eslint-plugin-regexp/pull/591))
26+
27+
## 2.0.0-next.3
28+
29+
### Minor Changes
30+
31+
- Improve `regexp/no-invalid-regexp` rule to check for unknown pattern flags. ([#583](https://github.com/ota-meshi/eslint-plugin-regexp/pull/583))
32+
333
## 2.0.0-next.2
434

535
### Patch Changes

Diff for: docs/.vitepress/theme/components/components/EslintPluginEditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default {
8686
rules: this.rules,
8787
parserOptions: {
8888
sourceType: "module",
89-
ecmaVersion: 2022,
89+
ecmaVersion: "latest",
9090
},
9191
}
9292
},

Diff for: docs/rules/no-useless-non-capturing-group.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ since: "v0.4.0"
1313

1414
<!-- end auto-generated rule header -->
1515

16-
> disallow unnecessary Non-capturing group
16+
> disallow unnecessary non-capturing group
1717
1818
## :book: Rule Details
1919

Diff for: docs/rules/no-useless-range.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ since: "v0.3.0"
1313

1414
<!-- end auto-generated rule header -->
1515

16-
> disallow unnecessary range of characters by using a hyphen
16+
> disallow unnecessary character ranges
1717
1818
## :book: Rule Details
1919

Diff for: docs/rules/prefer-d.md

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var foo = /[^0-9]/;
5353
This option control how character class element equivalent to `\d` will be treated.
5454

5555
*Note:* This option does not affect character classes equivalent to `\d`. E.g. `[\d]`, `[0-9]`, and `[0123456789]` are unaffected.
56+
It also does not affect expression non-nested operands equivalent to `\d`. E.g. `[\d&&x]`, and `[\d--x]` are unaffected.
5657

5758
- `insideCharacterClass: "d"` (*default*)
5859

@@ -88,6 +89,11 @@ This option control how character class element equivalent to `\d` will be treat
8889
/* ✗ BAD */
8990
var foo = /[\da-z]/;
9091
var foo = /[0-9]/;
92+
93+
/* Ignore */
94+
var foo = /[\d--0]/v;
95+
/* ✗ BAD */
96+
var foo = /[[\da-z]--0]/v;
9197
```
9298

9399
</eslint-code-block>
@@ -107,6 +113,7 @@ This option control how character class element equivalent to `\d` will be treat
107113

108114
/* ✗ BAD */
109115
var foo = /[0-9]/;
116+
var foo = /[[0-9a-z]--0]/v;
110117
```
111118

112119
</eslint-code-block>

Diff for: lib/rules/confusing-quantifier.ts

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ export default createRule("confusing-quantifier", {
2424
type: "problem",
2525
},
2626
create(context) {
27-
/**
28-
* Create visitor
29-
*/
3027
function createVisitor({
3128
node,
3229
flags,

Diff for: lib/rules/control-character-escape.ts

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ export default createRule("control-character-escape", {
5858
type: "suggestion", // "problem",
5959
},
6060
create(context) {
61-
/**
62-
* Create visitor
63-
*/
6461
function createVisitor(
6562
regexpContext: RegExpContext,
6663
): RegExpVisitor.Handlers {

Diff for: lib/rules/hexadecimal-escape.ts

-9
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export default createRule("hexadecimal-escape", {
3232
create(context) {
3333
const always = context.options[0] !== "never"
3434

35-
/**
36-
* Verify for always
37-
*/
3835
function verifyForAlways(
3936
{ node, getRegexpLocation, fixReplaceNode }: RegExpContext,
4037
kind: EscapeSequenceKind,
@@ -62,9 +59,6 @@ export default createRule("hexadecimal-escape", {
6259
})
6360
}
6461

65-
/**
66-
* Verify for never
67-
*/
6862
function verifyForNever(
6963
{ node, getRegexpLocation, fixReplaceNode }: RegExpContext,
7064
kind: EscapeSequenceKind,
@@ -86,9 +80,6 @@ export default createRule("hexadecimal-escape", {
8680

8781
const verify = always ? verifyForAlways : verifyForNever
8882

89-
/**
90-
* Create visitor
91-
*/
9283
function createVisitor(
9384
regexpContext: RegExpContext,
9485
): RegExpVisitor.Handlers {

Diff for: lib/rules/letter-case.ts

-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const DEFAULTS = {
2424
controlEscape: "uppercase" as const,
2525
}
2626

27-
/** Parse option */
2827
function parseOptions(option?: {
2928
caseInsensitive?: Case
3029
unicodeEscape?: Case
@@ -89,9 +88,6 @@ export default createRule("letter-case", {
8988
create(context) {
9089
const options = parseOptions(context.options[0])
9190

92-
/**
93-
* Report
94-
*/
9591
function report(
9692
{ node, getRegexpLocation, fixReplaceNode }: RegExpContext,
9793
reportNode: CharacterClassRange | Character,
@@ -112,7 +108,6 @@ export default createRule("letter-case", {
112108
})
113109
}
114110

115-
/** Verify for Character in case insensitive */
116111
function verifyCharacterInCaseInsensitive(
117112
regexpContext: RegExpContext,
118113
cNode: Character,
@@ -135,7 +130,6 @@ export default createRule("letter-case", {
135130
)
136131
}
137132

138-
/** Verify for CharacterClassRange in case insensitive */
139133
function verifyCharacterClassRangeInCaseInsensitive(
140134
regexpContext: RegExpContext,
141135
ccrNode: CharacterClassRange,
@@ -166,7 +160,6 @@ export default createRule("letter-case", {
166160
)
167161
}
168162

169-
/** Verify for Character in unicode escape */
170163
function verifyCharacterInUnicodeEscape(
171164
regexpContext: RegExpContext,
172165
cNode: Character,
@@ -193,7 +186,6 @@ export default createRule("letter-case", {
193186
)
194187
}
195188

196-
/** Verify for Character in hexadecimal escape */
197189
function verifyCharacterInHexadecimalEscape(
198190
regexpContext: RegExpContext,
199191
cNode: Character,
@@ -217,7 +209,6 @@ export default createRule("letter-case", {
217209
)
218210
}
219211

220-
/** Verify for Character in control escape */
221212
function verifyCharacterInControl(
222213
regexpContext: RegExpContext,
223214
cNode: Character,
@@ -239,9 +230,6 @@ export default createRule("letter-case", {
239230
)
240231
}
241232

242-
/**
243-
* Create visitor
244-
*/
245233
function createVisitor(
246234
regexpContext: RegExpContext,
247235
): RegExpVisitor.Handlers {

Diff for: lib/rules/match-any.ts

-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ export default createRule("match-any", {
129129
return range?.replace(fixer, preference) ?? null
130130
}
131131

132-
/**
133-
* Create visitor
134-
*/
135132
function createVisitor(
136133
regexpContext: RegExpContext,
137134
): RegExpVisitor.Handlers {

Diff for: lib/rules/negation.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toCharSet } from "regexp-ast-analysis"
1+
import { toCharSet, toUnicodeSet } from "regexp-ast-analysis"
22
import type {
33
EscapeCharacterSet,
44
UnicodePropertyCharacterSet,
@@ -23,9 +23,6 @@ export default createRule("negation", {
2323
type: "suggestion", // "problem",
2424
},
2525
create(context) {
26-
/**
27-
* Create visitor
28-
*/
2926
function createVisitor({
3027
node,
3128
getRegexpLocation,
@@ -42,8 +39,18 @@ export default createRule("negation", {
4239
if (element.type !== "CharacterSet") {
4340
return
4441
}
42+
if (element.kind === "property" && element.strings) {
43+
// Unicode property escape with property of strings.
44+
// Actually the pattern passing through this branch is an invalid pattern,
45+
// but it has to be checked because of the type guards.
46+
return
47+
}
4548

46-
if (flags.ignoreCase && element.kind === "property") {
49+
if (
50+
flags.ignoreCase &&
51+
!flags.unicodeSets &&
52+
element.kind === "property"
53+
) {
4754
// The ignore case canonicalization affects negated
4855
// Unicode property escapes in a weird way. In short,
4956
// /\p{Foo}/i is not the same as /[^\P{Foo}]/i if
@@ -52,14 +59,9 @@ export default createRule("negation", {
5259
// Note: This only affects Unicode property escapes.
5360
// All other character sets are either case-invariant
5461
// (/./, /\s/, /\d/) or inconsistent (/\w/).
55-
56-
// FIXME: TS Error
57-
// @ts-expect-error -- FIXME
58-
const ccSet = toCharSet(ccNode, flags)
62+
const ccSet = toUnicodeSet(ccNode, flags)
5963

6064
const negatedElementSet = toCharSet(
61-
// FIXME: TS Error
62-
// @ts-expect-error -- FIXME
6365
{
6466
...element,
6567
negate: !element.negate,

Diff for: lib/rules/no-contradiction-with-assertion.ts

-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ export default createRule("no-contradiction-with-assertion", {
249249
type: "problem",
250250
},
251251
create(context) {
252-
/** Create visitor */
253252
function createVisitor(
254253
regexpContext: RegExpContext,
255254
): RegExpVisitor.Handlers {

Diff for: lib/rules/no-control-character.ts

-5
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ export default createRule("no-control-character", {
3636
hasSuggestions: true,
3737
},
3838
create(context) {
39-
/**
40-
* Create visitor
41-
*/
4239
function createVisitor(
4340
regexpContext: RegExpContext,
4441
): RegExpVisitor.Handlers {
4542
const { node, patternSource, getRegexpLocation, fixReplaceNode } =
4643
regexpContext
4744

48-
/** */
4945
function isBadEscapeRaw(raw: string, cp: number): boolean {
5046
return (
5147
raw.codePointAt(0)! === cp ||
@@ -54,7 +50,6 @@ export default createRule("no-control-character", {
5450
)
5551
}
5652

57-
/** */
5853
function isAllowedEscapeRaw(raw: string): boolean {
5954
return (
6055
ALLOWED_CONTROL_CHARS.test(raw) ||

0 commit comments

Comments
 (0)