Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

checkAgainstRule.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const normalizeRuleSettings = require('../normalizeRuleSettings');
  3. const Result = require('postcss/lib/result');
  4. const rules = require('../rules');
  5. /**
  6. * Useful for third-party code (e.g. plugins) to run a PostCSS Root
  7. * against a specific rule and do something with the warnings
  8. * @template T
  9. * @template {Object} O
  10. * @param {{
  11. ruleName: string,
  12. ruleSettings: import('stylelint').StylelintConfigRuleSettings<T, O>,
  13. root: import('postcss').Root,
  14. }} options
  15. * @param {Function} callback
  16. * @returns {void}
  17. */
  18. module.exports = function (options, callback) {
  19. if (!options)
  20. throw new Error(
  21. "checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties",
  22. );
  23. if (!callback) throw new Error('checkAgainstRule requires a callback');
  24. if (!options.ruleName) throw new Error("checkAgainstRule requires a 'ruleName' option");
  25. if (!Object.keys(rules).includes(options.ruleName))
  26. throw new Error(`Rule '${options.ruleName}' does not exist`);
  27. if (!options.ruleSettings) throw new Error("checkAgainstRule requires a 'ruleSettings' option");
  28. if (!options.root) throw new Error("checkAgainstRule requires a 'root' option");
  29. const settings = normalizeRuleSettings(options.ruleSettings, options.ruleName);
  30. if (!settings) {
  31. return;
  32. }
  33. // @ts-expect-error - this error should not occur with PostCSS 8
  34. const tmpPostcssResult = new Result();
  35. rules[options.ruleName](
  36. settings[0],
  37. /** @type {O} */ (settings[1]),
  38. {},
  39. )(options.root, tmpPostcssResult);
  40. tmpPostcssResult.warnings().forEach(callback);
  41. };