Skip to content

Commit ca97441

Browse files
authored
Add regexp/no-invisible-character rule and regexp/no-useless-two-nums-quantifier rule and refactor (#2)
1 parent 7136b07 commit ca97441

Some content is hidden

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

44 files changed

+948
-213
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ module.exports = {
6363

6464
This plugin provides one config:
6565

66-
- `plugin:regexp/recommended` ... This is the recommended configuration for this plugin.
66+
- `plugin:regexp/recommended` ... This is the recommended configuration for this plugin.
67+
See [lib/configs/recommended.ts](https://github.com/ota-meshi/eslint-plugin-regexp/blob/master/lib/configs/recommended.ts) for details.
6768

6869
<!--USAGE_SECTION_END-->
6970

@@ -84,8 +85,10 @@ The rules with the following star :star: are included in the `plugin:regexp/reco
8485
| [regexp/no-empty-group](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-group.html) | disallow empty group | :star: |
8586
| [regexp/no-empty-lookarounds-assertion](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-lookarounds-assertion.html) | disallow empty lookahead assertion or empty lookbehind assertion | :star: |
8687
| [regexp/no-escape-backspace](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-escape-backspace.html) | disallow escape backspace (`[\b]`) | :star: |
88+
| [regexp/no-invisible-character](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invisible-character.html) | disallow invisible raw character | :star::wrench: |
8789
| [regexp/no-octal](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-octal.html) | disallow octal escape sequence | :star: |
8890
| [regexp/no-useless-exactly-quantifier](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-exactly-quantifier.html) | disallow unnecessary exactly quantifier | :star: |
91+
| [regexp/no-useless-two-nums-quantifier](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-two-nums-quantifier.html) | disallow unnecessary `{n,m}` quantifier | :star: |
8992
| [regexp/prefer-d](https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-d.html) | enforce using `\d` | :star::wrench: |
9093
| [regexp/prefer-plus-quantifier](https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-plus-quantifier.html) | enforce using `+` quantifier | :star::wrench: |
9194
| [regexp/prefer-question-quantifier](https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-question-quantifier.html) | enforce using `?` quantifier | :star::wrench: |

docs/rules/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ The rules with the following star :star: are included in the `plugin:regexp/reco
1717
| [regexp/no-empty-group](./no-empty-group.md) | disallow empty group | :star: |
1818
| [regexp/no-empty-lookarounds-assertion](./no-empty-lookarounds-assertion.md) | disallow empty lookahead assertion or empty lookbehind assertion | :star: |
1919
| [regexp/no-escape-backspace](./no-escape-backspace.md) | disallow escape backspace (`[\b]`) | :star: |
20+
| [regexp/no-invisible-character](./no-invisible-character.md) | disallow invisible raw character | :star::wrench: |
2021
| [regexp/no-octal](./no-octal.md) | disallow octal escape sequence | :star: |
2122
| [regexp/no-useless-exactly-quantifier](./no-useless-exactly-quantifier.md) | disallow unnecessary exactly quantifier | :star: |
23+
| [regexp/no-useless-two-nums-quantifier](./no-useless-two-nums-quantifier.md) | disallow unnecessary `{n,m}` quantifier | :star: |
2224
| [regexp/prefer-d](./prefer-d.md) | enforce using `\d` | :star::wrench: |
2325
| [regexp/prefer-plus-quantifier](./prefer-plus-quantifier.md) | enforce using `+` quantifier | :star::wrench: |
2426
| [regexp/prefer-question-quantifier](./prefer-question-quantifier.md) | enforce using `?` quantifier | :star::wrench: |

docs/rules/match-any.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ e.g. `[\s\S]`, `[^]`, `/./s` (dotAll) and more.
2222
/* eslint regexp/match-any: "error" */
2323

2424
/* ✓ GOOD */
25-
var foo = /[\s\S]/
26-
var foo = /./s
25+
var foo = /[\s\S]/;
26+
var foo = /./s;
2727

2828
/* ✗ BAD */
29-
var foo = /[\S\s]/
30-
var foo = /[^]/
31-
var foo = /[\d\D]/
32-
var foo = /[\w\W]/
29+
var foo = /[\S\s]/;
30+
var foo = /[^]/;
31+
var foo = /[\d\D]/;
32+
var foo = /[\w\W]/;
3333
```
3434

3535
</eslint-code-block>
@@ -55,14 +55,14 @@ var foo = /[\w\W]/
5555
/* eslint regexp/match-any: ["error", { "allows": ["[^]"] }] */
5656

5757
/* ✓ GOOD */
58-
var foo = /[^]/
58+
var foo = /[^]/;
5959

6060
/* ✗ BAD */
61-
var foo = /[\s\S]/
62-
var foo = /[\S\s]/
63-
var foo = /./s
64-
var foo = /[\d\D]/
65-
var foo = /[\w\W]/
61+
var foo = /[\s\S]/;
62+
var foo = /[\S\s]/;
63+
var foo = /./s;
64+
var foo = /[\d\D]/;
65+
var foo = /[\w\W]/;
6666
```
6767

6868
</eslint-code-block>

docs/rules/no-assertion-capturing-group.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ This rule reports capturing group that captures assertions.
2020
/* eslint regexp/no-assertion-capturing-group: "error" */
2121

2222
/* ✓ GOOD */
23-
var foo = /(a)/
24-
var foo = /a(?:\b)/
25-
var foo = /a(?:$)/
26-
var foo = /(?:^)a/
23+
var foo = /(a)/;
24+
var foo = /a(?:\b)/;
25+
var foo = /a(?:$)/;
26+
var foo = /(?:^)a/;
2727

2828
/* ✗ BAD */
29-
var foo = /a(\b)/
30-
var foo = /a($)/
31-
var foo = /(^)a/
29+
var foo = /a(\b)/;
30+
var foo = /a($)/;
31+
var foo = /(^)a/;
3232
```
3333

3434
</eslint-code-block>

docs/rules/no-dupe-characters-character-class.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description: "disallow duplicate characters in the RegExp character class"
1313
Because multiple same character classes in regular expressions only one is useful, they might be typing mistakes.
1414

1515
```js
16-
var foo = /\\(\\)/
16+
var foo = /\\(\\)/;
1717
```
1818

1919
## :book: Rule Details
@@ -26,18 +26,18 @@ This rule disallows duplicate characters in the RegExp character class.
2626
/* eslint regexp/no-dupe-characters-character-class: "error" */
2727

2828
/* ✓ GOOD */
29-
var foo = /[\(\)]/
29+
var foo = /[\(\)]/;
3030

31-
var foo = /[a-z\s]/
31+
var foo = /[a-z\s]/;
3232

33-
var foo = /[\w]/
33+
var foo = /[\w]/;
3434

3535
/* ✗ BAD */
36-
var foo = /[\\(\\)]/
36+
var foo = /[\\(\\)]/;
3737
// ^^ ^^ "\\" are duplicated
38-
var foo = /[a-z\\s]/
38+
var foo = /[a-z\\s]/;
3939
// ^^^ ^ "s" are duplicated
40-
var foo = /[\w0-9]/
40+
var foo = /[\w0-9]/;
4141
// ^^^^^ "0-9" are duplicated
4242
```
4343

docs/rules/no-empty-group.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ This rule reports empty groups.
2020
/* eslint regexp/no-empty-group: "error" */
2121

2222
/* ✓ GOOD */
23-
var foo = /(a)/
24-
var foo = /(?:a)/
23+
var foo = /(a)/;
24+
var foo = /(?:a)/;
2525

2626
/* ✗ BAD */
2727
// capturing group
28-
var foo = /()/
29-
var foo = /(|)/
28+
var foo = /()/;
29+
var foo = /(|)/;
3030
// non-capturing group
31-
var foo = /(?:)/
32-
var foo = /(?:|)/
31+
var foo = /(?:)/;
32+
var foo = /(?:|)/;
3333
```
3434

3535
</eslint-code-block>

docs/rules/no-empty-lookarounds-assertion.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ This rule reports empty lookahead assertion or empty lookbehind assertion.
2020
/* eslint regexp/no-empty-lookarounds-assertion: "error" */
2121

2222
/* ✓ GOOD */
23-
var foo = /x(?=y)/
24-
var foo = /x(?!y)/
25-
var foo = /(?<=y)x/
26-
var foo = /(?<!y)x/
23+
var foo = /x(?=y)/;
24+
var foo = /x(?!y)/;
25+
var foo = /(?<=y)x/;
26+
var foo = /(?<!y)x/;
2727

2828
/* ✗ BAD */
29-
var foo = /x(?=)/
30-
var foo = /x(?!)/
31-
var foo = /(?<=)x/
32-
var foo = /(?<!)x/
29+
var foo = /x(?=)/;
30+
var foo = /x(?!)/;
31+
var foo = /(?<=)x/;
32+
var foo = /(?<!)x/;
3333
```
3434

3535
</eslint-code-block>

docs/rules/no-escape-backspace.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ The word boundaries (`\b`) and the escape backspace (`[\b]`) are indistinguishab
2121
/* eslint regexp/no-escape-backspace: "error" */
2222

2323
/* ✓ GOOD */
24-
var foo = /\b/
25-
var foo = /\u0008/
26-
var foo = /\cH/
27-
var foo = /\x08/
24+
var foo = /\b/;
25+
var foo = /\u0008/;
26+
var foo = /\cH/;
27+
var foo = /\x08/;
2828

2929
/* ✗ BAD */
30-
var foo = /[\b]/
30+
var foo = /[\b]/;
3131
```
3232

3333
</eslint-code-block>

docs/rules/no-invisible-character.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "regexp/no-invisible-character"
5+
description: "disallow invisible raw character"
6+
---
7+
# regexp/no-invisible-character
8+
9+
> disallow invisible raw character
10+
11+
- :gear: This rule is included in `"plugin:regexp/recommended"`.
12+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
13+
14+
## :book: Rule Details
15+
16+
This rule disallows using invisible characters other than SPACE (`U+0020`) without using escapes.
17+
18+
<eslint-code-block fix>
19+
20+
```js
21+
/* eslint regexp/no-invisible-character: "error" */
22+
23+
/* ✓ GOOD */
24+
var foo = /\t/;
25+
var foo = /\v/;
26+
var foo = /\f/;
27+
var foo = /\u3000/;
28+
var foo = / /; // SPACE (`U+0020`)
29+
30+
/* ✗ BAD */
31+
var foo = / /;
32+
var foo = / /;
33+
var foo = / /;
34+
var foo = / /;
35+
```
36+
37+
</eslint-code-block>
38+
39+
## :wrench: Options
40+
41+
Nothing.
42+
43+
## Implementation
44+
45+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-regexp/blob/master/lib/rules/no-invisible-character.ts)
46+
- [Test source](https://github.com/ota-meshi/eslint-plugin-regexp/blob/master/tests/lib/rules/no-invisible-character.js)

docs/rules/no-octal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ This rule reports octal escape.
2222
/* eslint regexp/no-octal: "error" */
2323

2424
/* ✓ GOOD */
25-
var foo = /\0/
26-
var foo = /=/
25+
var foo = /\0/;
26+
var foo = /=/;
2727

2828
/* ✗ BAD */
29-
var foo = /\075/
29+
var foo = /\075/;
3030
```
3131

3232
</eslint-code-block>

0 commit comments

Comments
 (0)