You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[`regex/invalid`](docs/rules/invalid-regex-rule.md) | Yes | checks that specified patterns are not found
115
+
[`regex/required`](docs/rules/required-regex-rule.md) | No | checks that specified patterns are found
115
116
116
117
### `regex/invalid`
117
118
@@ -209,10 +210,11 @@ It is specified by just a regular expression `string`, i.e. `"regex"`
209
210
210
211
It is specified by an `object`, with the following fields:
211
212
212
-
* `id`: A `string` representing the **Pattern Id**.
213
-
* `regex`: A `string` representing the **Regular expression to look for**.
214
-
* `message`: A `string` specifying the **Message to be shown when an error happens** (invalid `regex` is found or required `regex` is not found).
215
-
* `files`: An `object` specifying which files to analyze:
213
+
* `regex`: A **required** `string` representing the **Regular expression to look for**.
214
+
* `replacement`: If present this `string` will use to replace **invalid** found pattern.
215
+
* `id`: An optional `string` representing the **Pattern Id**.
216
+
* `message`: An optional `string` specifying the **Message to be shown when an error happens** (invalid `regex` is found or required `regex` is not found).
217
+
* `files`: An optional `object` specifying which files to analyze:
216
218
* `ignore`: A `string` representing **Regular expression of the files to be ignored** when validating this specific pattern.
217
219
* `inspect`: A `string` representing **Regular expression of the files to be inspected** when validating this specific pattern.
218
220
@@ -228,8 +230,10 @@ It is specified by an `object`, with the following fields:
228
230
}
229
231
```
230
232
231
-
> * `regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/` define the following string `"\bhttp:"` when using `.eslintrc.js` or `"\\bhttp:"` when using `.eslintrc.json` (backslash needs to de double in a json file).
232
-
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
233
+
> * `regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/`:
234
+
> * when using `.eslintrc.js`, define the following string `"\bhttp:"`, or
235
+
> * when using `.eslintrc.json`, define `"\\bhttp:"` (backslash needs to de double in a json file).
236
+
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
233
237
> * Global ignore file pattern, takes precedence over `files` patterns.
234
238
235
239
#### Mixing definitions
@@ -329,6 +333,16 @@ Array of patterns represent different logical operation for each rule:
329
333
* `regex/invalid`: **OR** => the presence in a file of *any* of the patterns defined in the *array* is invalid.
330
334
* `regex/required`: **AND** => the presence in file of *all* of the patterns defined in the *array* is required.
331
335
336
+
### Examples
337
+
338
+
[For a set of Regex Rules examples check `eslint-plugin-base-style-config`](https://github.com/gmullerb/base-style-config/tree/master/js#regex-rules)
Copy file name to clipboardExpand all lines: docs/rules/invalid-regex-rule.md
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,15 +56,18 @@ It is specified by just a regular expression `string`, i.e. `"regex"`
56
56
57
57
It is specified by an `object`, with the following fields:
58
58
59
-
*`id`: A `string` representing the **Pattern Id**.
60
-
*`regex`: A `string` representing the **Regular expression to look for**.
61
-
*`message`: A `string` specifying the **Message to be shown when an error happens** (invalid `regex` is found or required `regex` is not found).
62
-
*`files`: An `object` specifying which files to analyze:
59
+
*`regex`: A **required**`string` representing the **Regular expression to look for**.
60
+
*`replacement`: An optional `string` used to replace invalid found pattern.
61
+
*`id`: An optional `string` representing the **Pattern Id**.
62
+
*`message`: An optional `string` specifying the **Message to be shown when an invalid `regex` is found**.
63
+
*`files`: An optional `object` specifying which files to analyze:
63
64
*`ignore`: A `string` representing **Regular expression of the files to be ignored** when validating this specific pattern.
64
65
*`inspect`: A `string` representing **Regular expression of the files to be inspected** when validating this specific pattern.
65
66
66
-
> *`regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/` define the following string `"\bhttp:"` when using `.eslintrc.js` or `"\\bhttp:"` when using `.eslintrc.json` (backslash needs to de double in a json file).
67
-
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
67
+
> *`regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/`:
68
+
> * when using `.eslintrc.js`, define the following string `"\bhttp:"`, or
69
+
> * when using `.eslintrc.json`, define `"\\bhttp:"` (backslash needs to de double in a json file).
70
+
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
68
71
> * Global ignore file pattern, takes precedence over `files` patterns.
69
72
70
73
`.eslintrc.json`:
@@ -79,6 +82,7 @@ It is specified by an `object`, with the following fields:
79
82
"error", [{
80
83
"regex": "invalidRegex1",
81
84
"message": "errorMessage1",
85
+
"replacement": "newValue"
82
86
}, {
83
87
"id": "regexIdN",
84
88
"regex": "invalidRegexN",
@@ -98,13 +102,7 @@ Internally, each string from the array will be converted into a Regular Expressi
98
102
99
103
`"invalidRegex1"` will be transformed into `/invalidRegex1/gm`
100
104
101
-
When the pattern is found splitting in more the one line the error message will not reflect the location (i.e. `1:1` will be shown), e.g.:
102
-
103
-
```bash
104
-
1:1 error Invalid regular expression /invalidRegex1/gm found in file regex/invalid
105
-
```
106
-
107
-
When the pattern is found inside an specific line the error message will reflect the exact location, e.g.:
105
+
When the pattern is found, the error message will reflect the exact location, e.g.:
108
106
109
107
```bash
110
108
34:25 error Invalid regular expression /invalidRegex1/gm found regex/invalid
@@ -116,4 +114,5 @@ When the pattern is found inside an specific line the error message will reflect
116
114
117
115
## More information
118
116
119
-
[Back](../README.md)
117
+
*[`eslint-plugin-regex`](../README.md)
118
+
*[For a set of Regex Rules examples check `eslint-plugin-base-style-config`](https://github.com/gmullerb/base-style-config/tree/master/js#regex-rules)
Copy file name to clipboardExpand all lines: docs/rules/required-regex-rule.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,15 +57,17 @@ It is specified by just a regular expression `string`, i.e. `"regex"`
57
57
58
58
It is specified by an `object`, with the following fields:
59
59
60
-
*`id`: A `string` representing the **Pattern Id**.
61
-
*`regex`: A `string` representing the **Regular expression to look for**.
62
-
*`message`: A `string` specifying the **Message to be shown when an error happens** (invalid `regex` is found or required `regex` is not found).
63
-
*`files`: An `object` specifying which files to analyze:
60
+
*`regex`: A **required**`string` representing the **Regular expression to look for**.
61
+
*`id`: An optional `string` representing the **Pattern Id**.
62
+
*`message`: An optional `string` specifying the **Message to be shown when a required `regex` is not found**.
63
+
*`files`: An optional `object` specifying which files to analyze:
64
64
*`ignore`: A `string` representing **Regular expression of the files to be ignored** when validating this specific pattern.
65
65
*`inspect`: A `string` representing **Regular expression of the files to be inspected** when validating this specific pattern.
66
66
67
-
> *`regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/` define the following string `"\bhttp:"` when using `.eslintrc.js` or `"\\bhttp:"` when using `.eslintrc.json` (backslash needs to de double in a json file).
68
-
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
67
+
> *`regex` is the only Required field. Slashes (`/`) are not required in the string, e.g. To get the following regex `/\bhttp:/`:
68
+
> * when using `.eslintrc.js`, define the following string `"\bhttp:"`, or
69
+
> * when using `.eslintrc.json`, define `"\\bhttp:"` (backslash needs to de double in a json file).
70
+
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
69
71
> * Global ignore file pattern, takes precedence over `files` patterns.
70
72
71
73
`.eslintrc.json`:
@@ -109,4 +111,5 @@ Internally, each string from the array will be converted into a Regular Expressi
109
111
110
112
## More information
111
113
112
-
[Back](../README.md)
114
+
*[`eslint-plugin-regex`](../README.md)
115
+
*[For a set of Regex Rules examples check `eslint-plugin-base-style-config`](https://github.com/gmullerb/base-style-config/tree/master/js#regex-rules)
0 commit comments