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
* `id`: An optional `string` representing the **Pattern Id**.
216
223
* `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
224
* `files`: An optional `object` specifying which files to analyze:
@@ -236,6 +243,48 @@ It is specified by an `object`, with the following fields:
236
243
> * When `ignore` and `inspect` are present, `ignore` takes precedence.
237
244
> * Global ignore file pattern, takes precedence over `files` patterns.
238
245
246
+
> [1] In order to fix issues `eslint` must be run with `--fix` option.
247
+
248
+
##### Definition of the Function used to replace **invalid** found pattern
249
+
250
+
Definition of the function must be done as a `string` in 1 line, and the following rules apply:
251
+
252
+
* It must return a `string` value, if not, return value will be ignored, i.e. it will silently fail.
253
+
* Its definition must be only the body of the function.
254
+
* If the function has invalid Javascript code, the function will be ignored, i.e. it will silently fail.
255
+
256
+
Function will receive only 1 parameter with the name `text`, with the value of the invalid text found.
257
+
258
+
e.g.
259
+
260
+
`"return text.trim()"` => only the body of the function + return a `string` value
261
+
262
+
`.eslintrc.json`:`
263
+
264
+
```json
265
+
{
266
+
"id": "regexIdN",
267
+
"regex": "\\serror\\w*\\s",
268
+
"replacement": {
269
+
"function": "return text.trim()"
270
+
}
271
+
}
272
+
```
273
+
274
+
then, given:
275
+
276
+
`example.js`
277
+
278
+
```js
279
+
const exception = " error19 "
280
+
```
281
+
282
+
when linting with fix, the result will be:
283
+
284
+
```js
285
+
const exception = "error19"
286
+
```
287
+
239
288
#### Mixing definitions
240
289
241
290
It is possible to use both type of definitions, 'Short pattern definition' with 'Detailed pattern definition', in the array of patterns.
@@ -335,7 +384,13 @@ Array of patterns represent different logical operation for each rule:
335
384
336
385
### Examples
337
386
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)
0 commit comments