UNPKG

stylelint-sassdoc

Version:

stylelint plugin to check scss files for a valid sassdoc documentation Credits to https://github.com/anneangersbach

32 lines (28 loc) 1.06 kB
const adjacentLineIsSCSSComment = require('./adjacentLineIsSCSSComment'); const regExCheck = require('./regExCheck'); /** * Checks the preceding comment nodes for @return and {type} * @param {Node} node - the current node */ let results = []; module.exports = function checkCommentsForReturn(node, tail = 0) { const previousNode = node.prev(); if (tail === 0) { results = []; } if (adjacentLineIsSCSSComment(node)) { // do not remove spaces in the regex (makes the stylelint formatter fail) if (regExCheck(previousNode, /@return |@returns /)) { const returnComment = {}; returnComment.returnOnLine = previousNode.source.start.line; returnComment.hasType = false; returnComment.node = previousNode; if (regExCheck(previousNode, /(?<type>\{[\w]+\})/)) { returnComment.hasType = true; } results.push(returnComment); } return checkCommentsForReturn(previousNode, tail + 1); } return results; };