index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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-before';
  8. const messages = ruleMessages(ruleName, {
  9. expectedBefore: () => 'Expected single space before ","',
  10. rejectedBefore: () => 'Unexpected whitespace before ","',
  11. expectedBeforeSingleLine: () => 'Expected single space before "," in a single-line function',
  12. rejectedBeforeSingleLine: () => 'Unexpected whitespace before "," in a single-line function',
  13. });
  14. const meta = {
  15. url: 'https://stylelint.io/user-guide/rules/list/function-comma-space-before',
  16. };
  17. /** @type {import('stylelint').Rule} */
  18. const rule = (primary, _secondaryOptions, context) => {
  19. const checker = whitespaceChecker('space', primary, messages);
  20. return (root, result) => {
  21. const validOptions = validateOptions(result, ruleName, {
  22. actual: primary,
  23. possible: ['always', 'never', 'always-single-line', 'never-single-line'],
  24. });
  25. if (!validOptions) {
  26. return;
  27. }
  28. functionCommaSpaceChecker({
  29. root,
  30. result,
  31. locationChecker: checker.before,
  32. checkedRuleName: ruleName,
  33. fix: context.fix
  34. ? (div, index, nodes) =>
  35. fixer({
  36. div,
  37. index,
  38. nodes,
  39. expectation: primary,
  40. position: 'before',
  41. symb: ' ',
  42. })
  43. : null,
  44. });
  45. };
  46. };
  47. rule.ruleName = ruleName;
  48. rule.messages = messages;
  49. rule.meta = meta;
  50. module.exports = rule;