1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const getNextNonSharedLineCommentNode = require('./getNextNonSharedLineCommentNode');
|
5 | const getPreviousNonSharedLineCommentNode = require('./getPreviousNonSharedLineCommentNode');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function nodesShareLines(a, b) {
|
15 | return _.get(a, 'source.end.line') === _.get(b, 'source.start.line');
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | module.exports = function isSharedLineComment(node) {
|
23 | if (node.type !== 'comment') {
|
24 | return false;
|
25 | }
|
26 |
|
27 | const previousNonSharedLineCommentNode = getPreviousNonSharedLineCommentNode(node);
|
28 |
|
29 | if (nodesShareLines(previousNonSharedLineCommentNode, node)) {
|
30 | return true;
|
31 | }
|
32 |
|
33 | const nextNonSharedLineCommentNode = getNextNonSharedLineCommentNode(node);
|
34 |
|
35 | if (nextNonSharedLineCommentNode && nodesShareLines(node, nextNonSharedLineCommentNode)) {
|
36 | return true;
|
37 | }
|
38 |
|
39 | const parentNode = node.parent;
|
40 |
|
41 |
|
42 | if (
|
43 | parentNode !== undefined &&
|
44 | parentNode.type !== 'root' &&
|
45 | parentNode.index(node) === 0 &&
|
46 | node.raws.before !== undefined &&
|
47 | !node.raws.before.includes('\n')
|
48 | ) {
|
49 | return true;
|
50 | }
|
51 |
|
52 | return false;
|
53 | };
|