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-property-value-no-unknown false positives for env() #6646

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/serious-moose-applaud.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-property-value-no-unknown` false positives for `env()`
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
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