Sha256: 634bd3875e4182b3f49cf80a21d60bf0511398c61452c0e795f3ffbbedaf5052

Contents?: true

Size: 1.27 KB

Versions: 24

Compression:

Stored size: 1.27 KB

Contents

'use strict';

const _ = require('lodash');
const getNextNonSharedLineCommentNode = require('./getNextNonSharedLineCommentNode');
const getPreviousNonSharedLineCommentNode = require('./getPreviousNonSharedLineCommentNode');

/** @typedef {import('postcss').Node} PostcssNode */

/**
 *
 * @param {PostcssNode | void} a
 * @param {PostcssNode | void} b
 */
function nodesShareLines(a, b) {
	return _.get(a, 'source.end.line') === _.get(b, 'source.start.line');
}

/**
 * @param {PostcssNode} node
 * @returns {boolean}
 */
module.exports = function isSharedLineComment(node) {
	if (node.type !== 'comment') {
		return false;
	}

	const previousNonSharedLineCommentNode = getPreviousNonSharedLineCommentNode(node);

	if (nodesShareLines(previousNonSharedLineCommentNode, node)) {
		return true;
	}

	const nextNonSharedLineCommentNode = getNextNonSharedLineCommentNode(node);

	if (nextNonSharedLineCommentNode && nodesShareLines(node, nextNonSharedLineCommentNode)) {
		return true;
	}

	const parentNode = node.parent;

	// It's a first child and located on the same line as block start
	if (
		parentNode !== undefined &&
		parentNode.type !== 'root' &&
		parentNode.index(node) === 0 &&
		node.raws.before !== undefined &&
		!node.raws.before.includes('\n')
	) {
		return true;
	}

	return false;
};

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.7 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.6 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.5 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.4 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.3 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.2 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.1 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3.5 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-5.0.0 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3.4 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3.3 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3.2 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3.1 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.3 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.2.3 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.2.2 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.2.1 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.2 node_modules/stylelint/lib/utils/isSharedLineComment.js
trusty-cms-4.1.9 node_modules/stylelint/lib/utils/isSharedLineComment.js