0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(unstable): lint plugin regex attribute selector not working (#28340)

The code to support regex matching on attribute values was already
there. I just forgot to wire it up properly in the selector matching
code.

Fixes https://github.com/denoland/deno/issues/28336
This commit is contained in:
Marvin Hagemeister 2025-02-28 12:59:41 +01:00 committed by GitHub
parent 5a0fca9a61
commit b4aa3e6d1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -1008,9 +1008,13 @@ function matchAttrBin(attr, next) {
function matchAttrValue(attr, value) {
switch (attr.op) {
case BinOp.Equal:
return value === attr.value;
return attr.value instanceof RegExp
? attr.value.test(value)
: value === attr.value;
case BinOp.NotEqual:
return value !== attr.value;
return attr.value instanceof RegExp
? !attr.value.test(value)
: value !== attr.value;
case BinOp.Greater:
return typeof value === "number" && typeof attr.value === "number" &&
value > attr.value;

View file

@ -271,6 +271,22 @@ Deno.test("Plugin - visitor attr length special case", () => {
assertEquals(result[1].node.arguments.length, 2);
});
Deno.test("Plugin - visitor attr regex", () => {
let result = testVisit(
"class Foo { get foo() { return 1 } bar() {} }",
"MethodDefinition[kind=/(g|s)et/]",
);
assertEquals(result[0].node.type, "MethodDefinition");
assertEquals(result[0].node.kind, "get");
result = testVisit(
"class Foo { get foo() { return 1 } bar() {} }",
"MethodDefinition[kind!=/(g|s)et/]",
);
assertEquals(result[0].node.type, "MethodDefinition");
assertEquals(result[0].node.kind, "method");
});
Deno.test("Plugin - visitor :first-child", () => {
const result = testVisit(
"{ foo; bar }",