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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // @ts-nocheck
  2. 'use strict';
  3. const valueParser = require('postcss-value-parser');
  4. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  5. const declarationValueIndex = require('../../utils/declarationValueIndex');
  6. const getAtRuleParams = require('../../utils/getAtRuleParams');
  7. const getDeclarationValue = require('../../utils/getDeclarationValue');
  8. const isCustomProperty = require('../../utils/isCustomProperty');
  9. const isMathFunction = require('../../utils/isMathFunction');
  10. const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
  11. const keywordSets = require('../../reference/keywordSets');
  12. const optionsMatches = require('../../utils/optionsMatches');
  13. const report = require('../../utils/report');
  14. const ruleMessages = require('../../utils/ruleMessages');
  15. const setAtRuleParams = require('../../utils/setAtRuleParams');
  16. const setDeclarationValue = require('../../utils/setDeclarationValue');
  17. const validateOptions = require('../../utils/validateOptions');
  18. const ruleName = 'length-zero-no-unit';
  19. const messages = ruleMessages(ruleName, {
  20. rejected: 'Unexpected unit',
  21. });
  22. function rule(primary, secondary, context) {
  23. return (root, result) => {
  24. const validOptions = validateOptions(
  25. result,
  26. ruleName,
  27. {
  28. actual: primary,
  29. },
  30. {
  31. actual: secondary,
  32. possible: {
  33. ignore: ['custom-properties'],
  34. },
  35. optional: true,
  36. },
  37. );
  38. if (!validOptions) return;
  39. let needsFix;
  40. function check(node, nodeIndex, valueNode) {
  41. const { value, sourceIndex } = valueNode;
  42. if (isMathFunction(valueNode)) return false;
  43. if (!isWord(valueNode)) return;
  44. const numberUnit = valueParser.unit(value);
  45. if (numberUnit === false) return;
  46. const { number, unit } = numberUnit;
  47. if (unit === '') return;
  48. if (!isLength(unit)) return;
  49. if (isFraction(unit)) return;
  50. if (!isZero(number)) return;
  51. if (context.fix) {
  52. valueNode.value = number;
  53. needsFix = true;
  54. return;
  55. }
  56. report({
  57. index: nodeIndex + sourceIndex + number.length,
  58. message: messages.rejected,
  59. node,
  60. result,
  61. ruleName,
  62. });
  63. }
  64. function checkAtRule(node) {
  65. if (!isStandardSyntaxAtRule(node)) return;
  66. needsFix = false;
  67. const index = atRuleParamIndex(node);
  68. const parsedValue = valueParser(getAtRuleParams(node));
  69. parsedValue.walk((valueNode) => {
  70. return check(node, index, valueNode);
  71. });
  72. if (needsFix) {
  73. setAtRuleParams(node, parsedValue.toString());
  74. }
  75. }
  76. function checkDecl(node) {
  77. needsFix = false;
  78. const { prop } = node;
  79. if (isLineHeight(prop)) return;
  80. if (optionsMatches(secondary, 'ignore', 'custom-properties') && isCustomProperty(prop))
  81. return;
  82. const index = declarationValueIndex(node);
  83. const parsedValue = valueParser(getDeclarationValue(node));
  84. parsedValue.walk((valueNode, valueNodeIndex, valueNodes) => {
  85. if (isLineHeightValue(node, valueNodes, valueNodeIndex)) return;
  86. return check(node, index, valueNode);
  87. });
  88. if (needsFix) {
  89. setDeclarationValue(node, parsedValue.toString());
  90. }
  91. }
  92. root.walkAtRules(checkAtRule);
  93. root.walkDecls(checkDecl);
  94. };
  95. }
  96. function isLineHeightValue({ prop }, nodes, index) {
  97. return (
  98. prop.toLowerCase() === 'font' &&
  99. index > 0 &&
  100. nodes[index - 1].type === 'div' &&
  101. nodes[index - 1].value === '/'
  102. );
  103. }
  104. function isLineHeight(prop) {
  105. return prop.toLowerCase() === 'line-height';
  106. }
  107. function isWord({ type }) {
  108. return type === 'word';
  109. }
  110. function isLength(unit) {
  111. return keywordSets.lengthUnits.has(unit.toLowerCase());
  112. }
  113. function isFraction(unit) {
  114. return unit.toLowerCase() === 'fr';
  115. }
  116. function isZero(number) {
  117. return Number.parseFloat(number) === 0;
  118. }
  119. rule.ruleName = ruleName;
  120. rule.messages = messages;
  121. module.exports = rule;