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 at-rule-property-required-list performance #6865

Merged
Changes from 2 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
45 changes: 34 additions & 11 deletions lib/rules/at-rule-property-required-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,62 @@ const rule = (primary) => {
return;
}

/** @type {Map<string, Set<string>|undefined>} */
const propLists = new Map();

for (const key in primary) {
if (!Object.hasOwnProperty.call(primary, key)) continue;

const propList = flattenArray(primary[key]);
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

if (!propList) continue;

propLists.set(key, new Set(propList));
}
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

/** @type {Set<string>} */
const currentPropList = new Set();

root.walkAtRules((atRule) => {
if (!isStandardSyntaxAtRule(atRule)) {
return;
}

const { name, nodes } = atRule;
const atRuleName = name.toLowerCase();
const propList = flattenArray(primary[atRuleName]);
const propList = propLists.get(atRuleName);

if (!propList) {
return;
}

for (const property of propList) {
const propertyName = property.toLowerCase();
currentPropList.clear();

const hasProperty = nodes.find(
(node) => node.type === 'decl' && node.prop.toLowerCase() === propertyName,
);
nodes.forEach((node) => {
if (!node || node.type !== 'decl') return;

const propName = node.prop.toLowerCase();

if (!propList.has(propName)) return;

currentPropList.add(propName);
});
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

if (currentPropList.size === propList.size) {
romainmenke marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (hasProperty) {
continue;
}
for (const requiredProp of propList) {
if (currentPropList.has(requiredProp)) continue;

report({
message: messages.expected,
messageArgs: [atRuleName, propertyName],
messageArgs: [atRuleName, requiredProp],
node: atRule,
word: `@${atRule.name}`,
result,
ruleName,
});
continue;
}
});
};
Expand Down