12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 'use strict';
- const hasBlock = require('../../utils/hasBlock');
- const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
- 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-space-before';
- const messages = ruleMessages(ruleName, {
- expectedBefore: () => 'Expected single space before ";"',
- rejectedBefore: () => 'Unexpected whitespace before ";"',
- });
- const meta = {
- url: 'https://stylelint.io/user-guide/rules/list/at-rule-semicolon-space-before',
- };
- /** @type {import('stylelint').Rule} */
- const rule = (primary) => {
- const checker = whitespaceChecker('space', primary, messages);
- return (root, result) => {
- const validOptions = validateOptions(result, ruleName, {
- actual: primary,
- possible: ['always', 'never'],
- });
- if (!validOptions) {
- return;
- }
- root.walkAtRules((atRule) => {
- if (hasBlock(atRule)) {
- return;
- }
- if (!isStandardSyntaxAtRule(atRule)) {
- return;
- }
- const nodeString = rawNodeString(atRule);
- checker.before({
- source: nodeString,
- index: nodeString.length,
- err: (m) => {
- report({
- message: m,
- node: atRule,
- index: nodeString.length - 1,
- result,
- ruleName,
- });
- },
- });
- });
- };
- };
- rule.ruleName = ruleName;
- rule.messages = messages;
- rule.meta = meta;
- module.exports = rule;
|