Skip to content

Commit

Permalink
Use closest selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jul 18, 2019
1 parent 124e835 commit 7732e1c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/rules/selector-no-union-class-name/index.js
Expand Up @@ -35,8 +35,9 @@ export default function(actual) {
root.walkRules(/&/, rule => {
const parentNodes = [];

if (rule.parent && rule.parent.selector) {
parseSelector(rule.parent.selector, result, rule, fullSelector => {
const selector = getSelectorFromRule(rule.parent);
if (selector) {
parseSelector(selector, result, rule, fullSelector => {
fullSelector.walk(node => parentNodes.push(node));
});
}
Expand Down Expand Up @@ -67,3 +68,20 @@ export default function(actual) {
});
};
}

/**
* Searches for the closest rule which
* has a selector and returns the selector
* @returns {string|undefined}
*/
function getSelectorFromRule(rule) {
// All non at-rules have their own selector
if (rule.selector !== undefined) {
return rule.selector;
}
// At-rules like @mixin don't have a selector themself
// but their parents might have one
if (rule.parent) {
return getSelectorFromRule(rule.parent);
}
}

0 comments on commit 7732e1c

Please sign in to comment.