Skip to content

Commit

Permalink
fix(lint): fix single char selectors being ignored (#27576)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marvinhagemeister authored Jan 7, 2025
1 parent 3f5cad3 commit cabdfa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cli/js/40_lint_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/lint_selectors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)"]);
Expand Down

0 comments on commit cabdfa8

Please sign in to comment.