index.js 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. const report = require('../../utils/report');
  3. const ruleMessages = require('../../utils/ruleMessages');
  4. const validateOptions = require('../../utils/validateOptions');
  5. const ruleName = 'no-empty-source';
  6. const messages = ruleMessages(ruleName, {
  7. rejected: 'Unexpected empty source',
  8. });
  9. const meta = {
  10. url: 'https://stylelint.io/user-guide/rules/no-empty-source',
  11. };
  12. /** @type {import('stylelint').Rule} */
  13. const rule = (primary, _secondaryOptions, context) => {
  14. return (root, result) => {
  15. const validOptions = validateOptions(result, ruleName, { actual: primary });
  16. if (!validOptions) {
  17. return;
  18. }
  19. const rootString = context.fix ? root.toString() : (root.source && root.source.input.css) || '';
  20. if (rootString.trim()) {
  21. return;
  22. }
  23. report({
  24. message: messages.rejected,
  25. node: root,
  26. result,
  27. ruleName,
  28. });
  29. };
  30. };
  31. rule.ruleName = ruleName;
  32. rule.messages = messages;
  33. rule.meta = meta;
  34. module.exports = rule;