Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix declaration-block-no-redundant-longhand-properties autofix for grid-template with repeat() #7230

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-horses-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-redundant-longhand-properties` autofix for `grid-template` with `repeat()`
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,20 @@ testRule({
description: 'explicit scroll-padding test',
message: messages.expected('scroll-padding'),
},
{
code: 'a { grid-template-columns: repeat(3, 1fr); grid-template-rows: auto; grid-template-areas: "left center right"; }',
unfixable: true,
description:
'the repeat() notation has non-trivial semantics and is currently not fixable (columns)',
message: messages.expected('grid-template'),
},
{
code: 'a { grid-template-columns: auto; grid-template-rows: repeat(3, 1fr); grid-template-areas: "left center right"; }',
unfixable: true,
description:
'the repeat() notation has non-trivial semantics and is currently not fixable (rows)',
message: messages.expected('grid-template'),
},
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ const customResolvers = new Map([

if (!(areas && columns && rows)) return;

// repeat() is not allowed inside track listings for grid-template.
// related issue: https://github.com/stylelint/stylelint/issues/7228
// spec ref: https://drafts.csswg.org/css-grid/#explicit-grid-shorthand

if (columns.includes('repeat(') || rows.includes('repeat(')) return;

const splitAreas = [...areas.matchAll(/"[^"]+"/g)].map((x) => x[0]);
const splitRows = rows.split(' ');

Expand Down