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.

normalizeRuleSettings.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. const _ = require('lodash');
  3. const rules = require('./rules');
  4. // Rule settings can take a number of forms, e.g.
  5. // a. "rule-name": null
  6. // b. "rule-name": [null, ...]
  7. // c. "rule-name": primaryOption
  8. // d. "rule-name": [primaryOption]
  9. // e. "rule-name": [primaryOption, secondaryOption]
  10. // Where primaryOption can be anything: primitive, Object, or Array.
  11. /**
  12. * This function normalizes all the possibilities into the
  13. * standard form: [primaryOption, secondaryOption]
  14. * Except in the cases with null, a & b, in which case
  15. * null is returned
  16. * @template T
  17. * @template {Object} O
  18. * @param {import('stylelint').StylelintConfigRuleSettings<T, O>} rawSettings
  19. * @param {string} ruleName
  20. * @param {boolean} [primaryOptionArray] If primaryOptionArray is not provided, we try to get it from the rules themselves, which will not work for plugins
  21. * @return {[T] | [T, O] | null}
  22. */
  23. module.exports = function (
  24. rawSettings,
  25. ruleName,
  26. // If primaryOptionArray is not provided, we try to get it from the
  27. // rules themselves, which will not work for plugins
  28. primaryOptionArray,
  29. ) {
  30. if (_.isNil(rawSettings)) {
  31. return null;
  32. }
  33. if (!Array.isArray(rawSettings)) {
  34. return [rawSettings];
  35. }
  36. // Everything below is an array ...
  37. if (!_.isEmpty(rawSettings) && _.isNil(rawSettings[0])) {
  38. return null;
  39. }
  40. if (primaryOptionArray === undefined) {
  41. const rule = rules[ruleName];
  42. primaryOptionArray = _.get(rule, 'primaryOptionArray');
  43. }
  44. if (!primaryOptionArray) {
  45. return rawSettings;
  46. }
  47. // Everything below is a rule that CAN have an array for a primary option ...
  48. // (they might also have something else, e.g. rule-properties-order can
  49. // have the string "alphabetical")
  50. if (rawSettings.length === 1 && Array.isArray(rawSettings[0])) {
  51. return rawSettings;
  52. }
  53. if (
  54. rawSettings.length === 2 &&
  55. !_.isPlainObject(rawSettings[0]) &&
  56. _.isPlainObject(rawSettings[1])
  57. ) {
  58. return rawSettings;
  59. }
  60. // `T` must be an array type, but TSC thinks it's probably invalid to
  61. // cast `[T]` to `T` so we cast through `any` first.
  62. return [/** @type {T} */ (/** @type {any} */ (rawSettings))];
  63. };