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