.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / isSharedLineComment.js
1 /* @flow */
2 "use strict";
3
4 const _ = require("lodash");
5 const getNextNonSharedLineCommentNode = require("./getNextNonSharedLineCommentNode");
6 const getPreviousNonSharedLineCommentNode = require("./getPreviousNonSharedLineCommentNode");
7
8 function nodesShareLines(a, b) {
9   return _.get(a, "source.end.line") === _.get(b, "source.start.line");
10 }
11
12 module.exports = function isSharedLineComment(
13   node /*: postcss$node*/
14 ) /*: boolean*/ {
15   if (node.type !== "comment") {
16     return false;
17   }
18
19   const previousNonSharedLineCommentNode = getPreviousNonSharedLineCommentNode(
20     node
21   );
22   if (nodesShareLines(previousNonSharedLineCommentNode, node)) {
23     return true;
24   }
25
26   const nextNonSharedLineCommentNode = getNextNonSharedLineCommentNode(node);
27   if (nodesShareLines(node, nextNonSharedLineCommentNode)) {
28     return true;
29   }
30
31   const parentNode = node.parent;
32   if (
33     parentNode !== undefined &&
34     parentNode.type !== "root" &&
35     parentNode.source.start.line === node.source.start.line
36   ) {
37     return true;
38   }
39
40   return false;
41 };