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.

index.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  5. const declarationValueIndex = require('../../utils/declarationValueIndex');
  6. const getUnitFromValueNode = require('../../utils/getUnitFromValueNode');
  7. const mediaParser = require('postcss-media-query-parser').default;
  8. const optionsMatches = require('../../utils/optionsMatches');
  9. const report = require('../../utils/report');
  10. const ruleMessages = require('../../utils/ruleMessages');
  11. const validateObjectWithArrayProps = require('../../utils/validateObjectWithArrayProps');
  12. const validateOptions = require('../../utils/validateOptions');
  13. const valueParser = require('postcss-value-parser');
  14. const ruleName = 'unit-blacklist';
  15. const messages = ruleMessages(ruleName, {
  16. rejected: (unit) => `Unexpected unit "${unit}"`,
  17. });
  18. // a function to retrieve only the media feature name
  19. // could be externalized in an utils function if needed in other code
  20. const getMediaFeatureName = (mediaFeatureNode) => {
  21. const value = mediaFeatureNode.value.toLowerCase();
  22. return /((-?\w*)*)/i.exec(value)[1];
  23. };
  24. function rule(listInput, options) {
  25. const list = [].concat(listInput);
  26. return (root, result) => {
  27. const validOptions = validateOptions(
  28. result,
  29. ruleName,
  30. {
  31. actual: list,
  32. possible: [_.isString],
  33. },
  34. {
  35. optional: true,
  36. actual: options,
  37. possible: {
  38. ignoreProperties: validateObjectWithArrayProps([_.isString, _.isRegExp]),
  39. ignoreMediaFeatureNames: validateObjectWithArrayProps([_.isString, _.isRegExp]),
  40. },
  41. },
  42. );
  43. if (!validOptions) {
  44. return;
  45. }
  46. result.warn(`'${ruleName}' has been deprecated. Instead use 'unit-disallowed-list'.`, {
  47. stylelintType: 'deprecation',
  48. stylelintReference: `https://github.com/stylelint/stylelint/blob/13.7.0/lib/rules/${ruleName}/README.md`,
  49. });
  50. function check(node, nodeIndex, valueNode, input, option) {
  51. const unit = getUnitFromValueNode(valueNode);
  52. // There is not unit or it is not configured as a violation
  53. if (!unit || (unit && !list.includes(unit.toLowerCase()))) {
  54. return;
  55. }
  56. // The unit has an ignore option for the specific input
  57. if (optionsMatches(option, unit.toLowerCase(), input)) {
  58. return;
  59. }
  60. report({
  61. index: nodeIndex + valueNode.sourceIndex,
  62. message: messages.rejected(unit),
  63. node,
  64. result,
  65. ruleName,
  66. });
  67. }
  68. function checkMedia(node, value, getIndex) {
  69. mediaParser(node.params).walk(/^media-feature$/i, (mediaFeatureNode) => {
  70. const mediaName = getMediaFeatureName(mediaFeatureNode);
  71. const parentValue = mediaFeatureNode.parent.value;
  72. valueParser(value).walk((valueNode) => {
  73. // Ignore all non-word valueNode and
  74. // the values not included in the parentValue string
  75. if (valueNode.type !== 'word' || !parentValue.includes(valueNode.value)) {
  76. return;
  77. }
  78. check(
  79. node,
  80. getIndex(node),
  81. valueNode,
  82. mediaName,
  83. options ? options.ignoreMediaFeatureNames : {},
  84. );
  85. });
  86. });
  87. }
  88. function checkDecl(node, value, getIndex) {
  89. // make sure multiplication operations (*) are divided - not handled
  90. // by postcss-value-parser
  91. value = value.replace(/\*/g, ',');
  92. valueParser(value).walk((valueNode) => {
  93. // Ignore wrong units within `url` function
  94. if (valueNode.type === 'function' && valueNode.value.toLowerCase() === 'url') {
  95. return false;
  96. }
  97. check(node, getIndex(node), valueNode, node.prop, options ? options.ignoreProperties : {});
  98. });
  99. }
  100. root.walkAtRules(/^media$/i, (atRule) => checkMedia(atRule, atRule.params, atRuleParamIndex));
  101. root.walkDecls((decl) => checkDecl(decl, decl.value, declarationValueIndex));
  102. };
  103. }
  104. rule.primaryOptionArray = true;
  105. rule.ruleName = ruleName;
  106. rule.messages = messages;
  107. rule.meta = { deprecated: true };
  108. module.exports = rule;