From 9c709a9ef1d622af39961da9aa5e32765a64c855 Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 5 Jun 2021 19:36:36 +0200 Subject: [PATCH] Mention workaround for the regex escape character --- docs/developer-guide/selectors.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/developer-guide/selectors.md b/docs/developer-guide/selectors.md index afe6600dc8c2..92c43aa984ce 100644 --- a/docs/developer-guide/selectors.md +++ b/docs/developer-guide/selectors.md @@ -31,7 +31,7 @@ The following selectors are supported: * wildcard (matches all nodes): `*` * attribute existence: `[attr]` * attribute value: `[attr="foo"]` or `[attr=123]` -* attribute regex: `[attr=/foo.*/]` +* attribute regex: `[attr=/foo.*/]` (with some [known issues](#known-issues)) * attribute conditions: `[attr!="foo"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]` * nested attribute: `[attr.level2="foo"]` * field: `FunctionDeclaration > Identifier.id` @@ -131,3 +131,7 @@ Or you can enforce that calls to `setTimeout` always have two arguments: ``` Using selectors in the `no-restricted-syntax` rule can give you a lot of control over problematic patterns in your codebase, without needing to write custom rules to detect each pattern. + +### Known issues + +Due to a [bug](https://github.com/estools/esquery/issues/68) in [esquery](https://github.com/estools/esquery), regular expressions that contain a forward-slash character `/` aren't porperly parsed, so `[value=/some\/path/]` will be a syntax error. As a [workaround](https://github.com/estools/esquery/issues/68), you can replace the `/` character with its unicode counterpart, like so: `[value=/some\\u002Fpath/]`.