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:
parent
3f5cad38aa
commit
cabdfa8c2d
2 changed files with 6 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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)"]);
|
||||
|
|
Loading…
Reference in a new issue