index.js 1.6 KB

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