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-duplicate-properties syntax error #6792

Merged
merged 10 commits into from
Apr 18, 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/modern-hornets-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-duplicate-properties` syntax error
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ testRule({
{ code: 'p { width: min(10px, 11px); width: max(10px, 11px); }' },
{ code: 'p { width: calc((10px + 2px)); width: calc((10rem + 2rem)); }' },
{ code: 'p { width: calc((10px + 2px) + 10px); width: calc((10rem + 2rem) + 10px); }' },
{ code: 'p { width: $a; width: calc(1 + $a); }', description: 'using SCSS variables' },
{ code: 'p { width: _$a; width: _$a2; }', description: 'using invalid value' },
],

reject: [
Expand Down
17 changes: 15 additions & 2 deletions lib/rules/declaration-block-no-duplicate-properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { parse, List } = require('css-tree');
const eachDeclarationBlock = require('../../utils/eachDeclarationBlock');
const isCustomProperty = require('../../utils/isCustomProperty');
const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
Expand Down Expand Up @@ -76,8 +77,20 @@ const isEqualValueSyntaxes = (value1, value2) => {
return true;
}

const value1Node = parse(value1, { context: 'value' });
const value2Node = parse(value2, { context: 'value' });
if (!(isStandardSyntaxValue(value1) && isStandardSyntaxValue(value2))) {
return false;
}
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

let value1Node;
let value2Node;

try {
yoyo837 marked this conversation as resolved.
Show resolved Hide resolved
value1Node = parse(value1, { context: 'value' });
value2Node = parse(value2, { context: 'value' });
} catch (error) {
return false;
}

const node1Children = hasChildren(value1Node) ? value1Node.children.toArray() : [];
const node2Children = hasChildren(value2Node) ? value2Node.children.toArray() : [];

Expand Down