Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rules/no-invalid-named-grid-areas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
*/
const nullCellToken = /^\.+$/u;

/**
* Regular expression to match sequences of CSS whitespace
*/
const cssWhitespace = /[\t\n ]+/u;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const cssWhitespace = /[\t\n ]+/u;
const cssWhitespace = /[\t ]+/u;

CSS in general allows newlines as whitespace but not inside strings (Example)


/**
* Finds non-rectangular grid areas in a 2D grid
* @param {string[][]} grid 2D array representing the grid areas
Expand Down Expand Up @@ -131,7 +136,7 @@ export default /** @satisfies {NoInvalidNamedGridAreasRuleDefinition} */ ({
continue;
}

const row = trimmedValue.split(" ").filter(Boolean);
const row = trimmedValue.split(cssWhitespace);
grid.push(row);

if (firstRowLen === null) {
Expand Down
15 changes: 15 additions & 0 deletions tests/rules/no-invalid-named-grid-areas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ ruleTester.run("no-invalid-named-grid-areas", rule, {
'.grid { grid-template-areas: "a a a" "b b b"; }',
'.grid { grid-template-areas: " a a a " "b b b"; }',
'.grid { GRID-TEMPLATE-AREAS: "a a a" "b b b"; }',
'.grid { grid-template-areas: "a\tb" "a b"; }',
'.grid { grid-template-areas: "a\t b" "a b"; }',

dedent`
.grid { grid-template-areas: "head head"
"nav main"
Expand Down Expand Up @@ -76,6 +79,18 @@ ruleTester.run("no-invalid-named-grid-areas", rule, {
},
],
},
{
code: 'a { grid-template-areas: "a\ta" "a b c"; }',
errors: [
{
messageId: "unevenGridArea",
line: 1,
column: 32,
endLine: 1,
endColumn: 39,
},
],
},
{
code: 'a { grid-template-areas: "a a a" "b b a"; }',
errors: [
Expand Down