1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 15:48:16 -05:00

fix(lint): fix single char selectors being ignored (#27576)

The selector splitting code that's used for JS linting plugins didn't
properly account for selectors being a single character. This can happen
in the case of `*`.

Instead of comparing against the length, we'll now check if the
remaining string portion is not empty, which is more robust. It also
allows us to detect trailing whitespace, which we didn't before.
This commit is contained in:
Marvin Hagemeister 2025-01-08 00:21:50 +01:00 committed by GitHub
parent 3f5cad38aa
commit cabdfa8c2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -406,8 +406,9 @@ export function splitSelectors(input) {
}
}
if (last < input.length - 1) {
out.push(input.slice(last).trim());
const remaining = input.slice(last).trim();
if (remaining.length > 0) {
out.push(remaining);
}
return out;

View file

@ -20,6 +20,9 @@ import {
import { assertThrows } from "@std/assert";
Deno.test("splitSelectors", () => {
assertEquals(splitSelectors("*"), ["*"]);
assertEquals(splitSelectors("*,*"), ["*", "*"]);
assertEquals(splitSelectors("*,* "), ["*", "*"]);
assertEquals(splitSelectors("foo"), ["foo"]);
assertEquals(splitSelectors("foo, bar"), ["foo", "bar"]);
assertEquals(splitSelectors("foo:f(bar, baz)"), ["foo:f(bar, baz)"]);