index.cjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const configurationComment = require('../../utils/configurationComment.cjs');
  5. const report = require('../../utils/report.cjs');
  6. const ruleMessages = require('../../utils/ruleMessages.cjs');
  7. const validateOptions = require('../../utils/validateOptions.cjs');
  8. const ruleName = 'no-empty-source';
  9. const messages = ruleMessages(ruleName, {
  10. rejected: 'Unexpected empty source',
  11. });
  12. const meta = {
  13. url: 'https://stylelint.io/user-guide/rules/no-empty-source',
  14. };
  15. /** @type {import('stylelint').CoreRules[ruleName]} */
  16. const rule = (primary, _secondaryOptions, context) => {
  17. return (root, result) => {
  18. const validOptions = validateOptions(result, ruleName, { actual: primary });
  19. if (!validOptions) {
  20. return;
  21. }
  22. // after a fix has been applied root.toString() may differ from root.source.input.css
  23. // i.e. root.source.input.css remains unchanged after a fix
  24. const rootString = context.fix ? root.toString() : (root.source && root.source.input.css) || '';
  25. let hasNotableChild =
  26. Boolean(rootString.trim()) &&
  27. root.nodes.some((child) => {
  28. if (configurationComment.isConfigurationComment(child, context.configurationComment)) return false;
  29. return true;
  30. });
  31. if (!hasNotableChild) {
  32. // Assume a case when a non-standard syntax is used, such as JSX. See #8547.
  33. if (root.nodes.length === 0 && Boolean(root.raws.after?.trim())) {
  34. hasNotableChild = true;
  35. }
  36. }
  37. if (hasNotableChild) {
  38. return;
  39. }
  40. report({
  41. message: messages.rejected,
  42. messageArgs: [],
  43. node: root,
  44. result,
  45. ruleName,
  46. });
  47. };
  48. };
  49. rule.ruleName = ruleName;
  50. rule.messages = messages;
  51. rule.meta = meta;
  52. module.exports = rule;