Skip to content

Commit b764c23

Browse files
shahana308Shahana Salam
andauthored
Fix named-grid-areas-no-invalid false positives for interpolated grid-template-areas in CSS-in-JS (#8606)
Co-authored-by: Shahana Salam <[email protected]>
1 parent 103c2d2 commit b764c23

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

.changeset/sour-spoons-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": patch
3+
---
4+
5+
Fixed: `named-grid-areas-no-invalid` false positives for interpolated grid-template-areas in CSS-in-JS

lib/rules/named-grid-areas-no-invalid/__tests__/index.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ testRule({
6868
"b c c" 40px / 1fr 1fr 1fr;
6969
}`,
7070
},
71+
{
72+
code: `a { grid-template-areas: ${({ $foo }) => ($foo === 'any string with different number of tokens than return values' ? 'a a a' : 'b b b')}; }`,
73+
description:
74+
'Skip non-standard values to fix false positive in named-grid-areas-no-invalid with styled-components',
75+
},
7176
],
7277

7378
reject: [

lib/rules/named-grid-areas-no-invalid/index.cjs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/named-grid-areas-no-invalid/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import valueParser from 'postcss-value-parser';
33
import { assert } from '../../utils/validateTypes.mjs';
44
import { declarationValueIndex } from '../../utils/nodeFieldIndices.mjs';
55
import findNotContiguousOrRectangular from './utils/findNotContiguousOrRectangular.mjs';
6+
import isStandardSyntaxValue from '../../utils/isStandardSyntaxValue.mjs';
67
import report from '../../utils/report.mjs';
78
import ruleMessages from '../../utils/ruleMessages.mjs';
89
import validateOptions from '../../utils/validateOptions.mjs';
@@ -31,6 +32,8 @@ const rule = (primary) => {
3132
root.walkDecls(/^(?:grid|grid-template|grid-template-areas)$/i, (decl) => {
3233
const { value } = decl;
3334

35+
if (!isStandardSyntaxValue(value)) return;
36+
3437
if (value.toLowerCase().trim() === 'none') return;
3538

3639
/** @type {Array<{ values: string[], index: number, endIndex: number }>} */

0 commit comments

Comments
 (0)