index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. const fixer = require('../functionCommaSpaceFix');
  3. const functionCommaSpaceChecker = require('../functionCommaSpaceChecker');
  4. const ruleMessages = require('../../utils/ruleMessages');
  5. const validateOptions = require('../../utils/validateOptions');
  6. const whitespaceChecker = require('../../utils/whitespaceChecker');
  7. const ruleName = 'function-comma-space-after';
  8. const messages = ruleMessages(ruleName, {
  9. expectedAfter: () => 'Expected single space after ","',
  10. rejectedAfter: () => 'Unexpected whitespace after ","',
  11. expectedAfterSingleLine: () => 'Expected single space after "," in a single-line function',
  12. rejectedAfterSingleLine: () => 'Unexpected whitespace after "," in a single-line function',
  13. });
  14. const meta = {
  15. url: 'https://stylelint.io/user-guide/rules/function-comma-space-after',
  16. fixable: true,
  17. };
  18. /** @type {import('stylelint').Rule} */
  19. const rule = (primary, _secondaryOptions, context) => {
  20. const checker = whitespaceChecker('space', primary, messages);
  21. return (root, result) => {
  22. const validOptions = validateOptions(result, ruleName, {
  23. actual: primary,
  24. possible: ['always', 'never', 'always-single-line', 'never-single-line'],
  25. });
  26. if (!validOptions) {
  27. return;
  28. }
  29. functionCommaSpaceChecker({
  30. root,
  31. result,
  32. locationChecker: checker.after,
  33. checkedRuleName: ruleName,
  34. fix: context.fix
  35. ? (div, index, nodes) =>
  36. fixer({
  37. div,
  38. index,
  39. nodes,
  40. expectation: primary,
  41. position: 'after',
  42. symb: ' ',
  43. })
  44. : null,
  45. });
  46. };
  47. };
  48. rule.ruleName = ruleName;
  49. rule.messages = messages;
  50. rule.meta = meta;
  51. module.exports = rule;