stylelint-sassdoc
Version:
stylelint plugin to check scss files for a valid sassdoc documentation Credits to https://github.com/anneangersbach
37 lines (33 loc) • 1.28 kB
JavaScript
const adjacentLineIsSCSSComment = require('./adjacentLineIsSCSSComment');
const regExCheck = require('./regExCheck');
/**
* Checks the preceding comment nodes for @arg, @argument, @param and {type}
* @param {Node} node - the current node
*/
let results = [];
module.exports = function checkCommentsForParam(node, tail = 0) {
const previousNode = node.prev();
if (tail === 0) {
results = [];
}
if (adjacentLineIsSCSSComment(node)) {
if (regExCheck(previousNode, /@arg .+|@argument .+|@param .+|@parameter .+/)) {
const returnComment = {};
returnComment.returnOnLine = previousNode.source.start.line;
returnComment.hasType = false;
returnComment.hasName = false;
returnComment.node = previousNode;
// checking for '{type}' to ensure parameter type
if (regExCheck(previousNode, /(?<type>\{.+\})/)) {
returnComment.hasType = true;
}
// checking if a $name is present
if (regExCheck(previousNode, / \$.{1}/)) {
returnComment.hasName = true;
}
results.push(returnComment);
}
return checkCommentsForParam(previousNode, tail + 1);
}
return results;
};