stylelint-sassdoc
Version:
stylelint plugin to check scss files for a valid sassdoc documentation Credits to https://github.com/anneangersbach
29 lines (26 loc) • 1.12 kB
JavaScript
const checkEmptyLine = require('./checkEmptyLine');
const regExCheck = require('./regExCheck');
const nodeToString = require('./nodeToString');
/**
* Checks if the adjacent node is a valid Sassdoc comment
* starting with //, exluding any CSS comments starting with /*
* @param {Node} node - the current node
* @param {boolean} checkPrevious - is previous node | is next node
* @return {boolean}
*/
module.exports = function adjacentLineIsSCSSComment(node, checkPrevious = true) {
const adjacentNode = checkPrevious ? node.prev() : node.next();
if (!adjacentNode) {
return false;
}
const adjacentString = nodeToString(adjacentNode);
let isSassdoc = false;
const isComment = (adjacentNode.type === 'comment');
const isNoEmptyLine = checkEmptyLine(node, adjacentNode);
if (isNoEmptyLine) {
// starts with '///' followed by 0 or more characters.
// Windows fails this, if it is only checking for '///' at the beginning of the string
isSassdoc = regExCheck(adjacentString, /^\/\/\/.*/);
}
return (isComment && isNoEmptyLine && isSassdoc);
};