Sha256: f429e4868978f7de0aa3d70584208766a6c7dea43ede75146eb4e504db806bb6

Contents?: true

Size: 1.99 KB

Versions: 23

Compression:

Stored size: 1.99 KB

Contents

'use strict';

const blockString = require('../../utils/blockString');
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 = 'declaration-block-semicolon-space-after';

const messages = ruleMessages(ruleName, {
	expectedAfter: () => 'Expected single space after ";"',
	rejectedAfter: () => 'Unexpected whitespace after ";"',
	expectedAfterSingleLine: () =>
		'Expected single space after ";" in a single-line declaration block',
	rejectedAfterSingleLine: () =>
		'Unexpected whitespace after ";" in a single-line declaration block',
});

function rule(expectation, options, context) {
	const checker = whitespaceChecker('space', expectation, messages);

	return function (root, result) {
		const validOptions = validateOptions(result, ruleName, {
			actual: expectation,
			possible: ['always', 'never', 'always-single-line', 'never-single-line'],
		});

		if (!validOptions) {
			return;
		}

		root.walkDecls((decl) => {
			// Ignore last declaration if there's no trailing semicolon
			const parentRule = decl.parent;

			if (!parentRule.raws.semicolon && parentRule.last === decl) {
				return;
			}

			const nextDecl = decl.next();

			if (!nextDecl) {
				return;
			}

			checker.after({
				source: rawNodeString(nextDecl),
				index: -1,
				lineCheckStr: blockString(parentRule),
				err: (m) => {
					if (context.fix) {
						if (expectation.startsWith('always')) {
							nextDecl.raws.before = ' ';

							return;
						}

						if (expectation.startsWith('never')) {
							nextDecl.raws.before = '';

							return;
						}
					}

					report({
						message: m,
						node: decl,
						index: decl.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/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.6 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.5 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.4 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.3 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.2 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.1 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3.5 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-5.0.0 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3.4 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3.3 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3.2 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3.1 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.3 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.2.3 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.2.2 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.2.1 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.2 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.1.9 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js
trusty-cms-4.1.8 node_modules/stylelint/lib/rules/declaration-block-semicolon-space-after/index.js