When trying to return the amount of children containing :host found in an object, the function always returns undefined
.
const plugin = stylelint.createPlugin(ruleName, isEnabled => {
let childrenFound = 0;
childrenFound = lookForChildren(rule.nodes, childrenFound);
console.log(childrenFound); // Wrong Value: Always undefined
}
let lookForChildren = function(nodes, childFound) {
if(childFound > 1) {
console.log(childFound);
return childFound;
}
nodes.forEach(node => {
if (node.selector != undefined) {
const selector = node.selector.replace(":host-context", "");
if (selector.includes(":host")) {
childFound++;
return lookForChildren(node.nodes, childFound);
} else {
return lookForChildren(node.nodes, childFound);
}
}
});
// This returns the wrong value so i deleted it
return childFound;
};
But it should return the childFound variable which is only return when it is greater than 1.
This function checks if a scss document contains a selector with more than one :host
selector because the browser compiles it differently than expected.
When childFound
is greater than one:
Expected: return childFound // Childfound is 2 or higher
Actual: childrenFound
is always undefined.