index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const atRuleNameSpaceChecker = require('../atRuleNameSpaceChecker');
  3. const ruleMessages = require('../../utils/ruleMessages');
  4. const validateOptions = require('../../utils/validateOptions');
  5. const whitespaceChecker = require('../../utils/whitespaceChecker');
  6. const ruleName = 'at-rule-name-space-after';
  7. const messages = ruleMessages(ruleName, {
  8. expectedAfter: (name) => `Expected single space after at-rule name "${name}"`,
  9. });
  10. const meta = {
  11. url: 'https://stylelint.io/user-guide/rules/at-rule-name-space-after',
  12. fixable: true,
  13. };
  14. /** @type {import('stylelint').Rule} */
  15. const rule = (primary, _secondary, context) => {
  16. const checker = whitespaceChecker('space', primary, messages);
  17. return (root, result) => {
  18. const validOptions = validateOptions(result, ruleName, {
  19. actual: primary,
  20. possible: ['always', 'always-single-line'],
  21. });
  22. if (!validOptions) {
  23. return;
  24. }
  25. atRuleNameSpaceChecker({
  26. root,
  27. result,
  28. locationChecker: checker.after,
  29. checkedRuleName: ruleName,
  30. fix: context.fix
  31. ? (atRule) => {
  32. if (typeof atRule.raws.afterName === 'string') {
  33. atRule.raws.afterName = atRule.raws.afterName.replace(/^\s*/, ' ');
  34. }
  35. }
  36. : null,
  37. });
  38. };
  39. };
  40. rule.ruleName = ruleName;
  41. rule.messages = messages;
  42. rule.meta = meta;
  43. module.exports = rule;