Skip to content

Commit

Permalink
Ignore variables in mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelalozano16 committed Apr 4, 2024
1 parent 73ab3da commit 05dd67e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/rules/no-unused-private-members/__tests__/index.js
Expand Up @@ -177,6 +177,15 @@ testRule({
margin: $-a-b;
}`,
description: "Is used as a mixin default parameter"
},
{
code: `
@mixin foo {
$_a-b: 1px;
}
@include foo
`,
description: "Is used as a mixin default parameter"
}
],

Expand Down
18 changes: 15 additions & 3 deletions src/rules/no-unused-private-members/index.js
Expand Up @@ -29,6 +29,17 @@ function matchUnderscores(inputString) {
return inputString.replaceAll("_", "-");
}

function isWithinMixin(node) {
let parent = node.parent;
while (parent) {
if (parent.type === "atrule" && parent.name === "mixin") {
return true;
}
parent = parent.parent;
}
return false;
}

function rule(primaryOption) {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, {
Expand Down Expand Up @@ -72,7 +83,8 @@ function rule(primaryOption) {
// Private variables
const isPrivateVariable =
node.type === "decl" &&
(node.prop.startsWith("$-") || node.prop.startsWith("$_"));
(node.prop.startsWith("$-") || node.prop.startsWith("$_")) &&
!isWithinMixin(node);
if (isPrivateVariable) {
privateMembers.variables.set(matchUnderscores(node.prop), node);
}
Expand Down Expand Up @@ -139,10 +151,10 @@ function rule(primaryOption) {
});

for (const types in privateMembers) {
for (const [key, value] of privateMembers[types].entries()) {
for (const [key, node] of privateMembers[types].entries()) {
utils.report({
message: messages.expected(key),
node: value,
node,
result,
ruleName
});
Expand Down

0 comments on commit 05dd67e

Please sign in to comment.