Sha256: 1508fa3c8bbbffca2b6cd361bcfa3df8fd2fd36d85bd2934e5c5c7aee091994c

Contents?: true

Size: 1.71 KB

Versions: 23

Compression:

Stored size: 1.71 KB

Contents

'use strict';

const hasBlock = require('../../utils/hasBlock');
const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const nextNonCommentNode = require('../../utils/nextNonCommentNode');
const rawNodeString = require('../../utils/rawNodeString');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const whitespaceChecker = require('../../utils/whitespaceChecker');

const ruleName = 'at-rule-semicolon-newline-after';

const messages = ruleMessages(ruleName, {
	expectedAfter: () => 'Expected newline after ";"',
});

function rule(actual, secondary, context) {
	const checker = whitespaceChecker('newline', actual, messages);

	return (root, result) => {
		const validOptions = validateOptions(result, ruleName, {
			actual,
			possible: ['always'],
		});

		if (!validOptions) {
			return;
		}

		root.walkAtRules((atRule) => {
			const nextNode = atRule.next();

			if (!nextNode) {
				return;
			}

			if (hasBlock(atRule)) {
				return;
			}

			if (!isStandardSyntaxAtRule(atRule)) {
				return;
			}

			// Allow an end-of-line comment
			const nodeToCheck = nextNonCommentNode(nextNode);

			if (!nodeToCheck) {
				return;
			}

			checker.afterOneOnly({
				source: rawNodeString(nodeToCheck),
				index: -1,
				err: (msg) => {
					if (context.fix) {
						nodeToCheck.raws.before = context.newline + nodeToCheck.raws.before;
					} else {
						report({
							message: msg,
							node: atRule,
							index: atRule.toString().length + 1,
							result,
							ruleName,
						});
					}
				},
			});
		});
	};
}

rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.6 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.5 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.4 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.3 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.2 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.1 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3.5 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-5.0.0 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3.4 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3.3 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3.2 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3.1 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.3 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.2.3 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.2.2 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.2.1 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.2 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.1.9 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js
trusty-cms-4.1.8 node_modules/stylelint/lib/rules/at-rule-semicolon-newline-after/index.js