Skip to content

Commit

Permalink
Fix at-extend-no-missing-placeholder end positions (stylelint-scss#899
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ybiquitous committed Dec 11, 2023
1 parent 620dbd2 commit 62139e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/rules/at-extend-no-missing-placeholder/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ testRule({
}
`,
line: 3,
column: 17,
endLine: 3,
endColumn: 21,
message: messages.rejected,
description: "when extending with an element"
},
Expand Down
27 changes: 16 additions & 11 deletions src/rules/at-extend-no-missing-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const meta = {
url: ruleUrl(ruleName)
};

const INTERPOLATION_PATTERN = /^#{.+}/;

function rule(actual) {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, { actual });
Expand All @@ -24,17 +26,20 @@ function rule(actual) {
}

root.walkAtRules("extend", atrule => {
const isPlaceholder = atrule.params.trim()[0] === "%";
const isInterpolation = /^#{.+}/.test(atrule.params.trim());

if (!isPlaceholder && !isInterpolation) {
utils.report({
ruleName,
result,
node: atrule,
message: messages.rejected
});
}
const param = atrule.params.trim();

// Placeholder
if (param.startsWith("%")) return;

if (INTERPOLATION_PATTERN.test(param)) return;

utils.report({
ruleName,
result,
node: atrule,
message: messages.rejected,
word: param
});
});
};
}
Expand Down

0 comments on commit 62139e4

Please sign in to comment.