Skip to content

Commit

Permalink
Fix declaration-property-value-no-unknown false positives for `env(…
Browse files Browse the repository at this point in the history
…)` (#6646)

* Fix `declaration-property-value-no-unknown` false positives for `env()`

* Create serious-moose-applaud.md

* feedback

* feedback

Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>

---------

Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
  • Loading branch information
romainmenke and jeddy3 committed Feb 10, 2023
1 parent a38641c commit d24ee3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-moose-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-property-value-no-unknown` false positives for `env()`
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ testRule({
{
code: 'a { top: var(--foo); }',
},
{
code: 'a { top: env(titlebar-area-height); }',
},
{
code: 'a { foo: 1px; }',
},
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/declaration-property-value-no-unknown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const rule = (primary, secondaryOptions) => {
try {
cssTreeValueNode = parse(value, { context: 'value' });

if (containsUnsupportedMathFunction(cssTreeValueNode)) return;
if (containsUnsupportedFunction(cssTreeValueNode)) return;
} catch (e) {
result.warn(`Cannot parse property value "${value}"`, {
node: decl,
Expand Down Expand Up @@ -130,15 +130,16 @@ const rule = (primary, secondaryOptions) => {
* some math functions like `clamp()` via `fork()`. In the future, it may be unnecessary.
*
* @see https://github.com/stylelint/stylelint/pull/6511#issuecomment-1412921062
* @see https://github.com/stylelint/stylelint/issues/6635#issuecomment-1425787649
*
* @param {import('css-tree').CssNode} cssTreeNode
* @returns {boolean}
*/
function containsUnsupportedMathFunction(cssTreeNode) {
function containsUnsupportedFunction(cssTreeNode) {
return Boolean(
find(
cssTreeNode,
(node) => node.type === 'Function' && ['clamp', 'min', 'max'].includes(node.name),
(node) => node.type === 'Function' && ['clamp', 'min', 'max', 'env'].includes(node.name),
),
);
}
Expand Down

0 comments on commit d24ee3b

Please sign in to comment.