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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // @ts-nocheck
  2. 'use strict';
  3. const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
  4. const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const valueParser = require('postcss-value-parser');
  9. const vendor = require('../../utils/vendor');
  10. const ruleName = 'shorthand-property-no-redundant-values';
  11. const messages = ruleMessages(ruleName, {
  12. rejected: (unexpected, expected) =>
  13. `Unexpected longhand value '${unexpected}' instead of '${expected}'`,
  14. });
  15. const propertiesWithShorthandNotation = new Set([
  16. 'margin',
  17. 'padding',
  18. 'border-color',
  19. 'border-radius',
  20. 'border-style',
  21. 'border-width',
  22. 'grid-gap',
  23. ]);
  24. const ignoredCharacters = ['+', '*', '/', '(', ')', '$', '@', '--', 'var('];
  25. function hasIgnoredCharacters(value) {
  26. return ignoredCharacters.some((char) => value.includes(char));
  27. }
  28. function isShorthandProperty(property) {
  29. return propertiesWithShorthandNotation.has(property);
  30. }
  31. function canCondense(top, right, bottom, left) {
  32. const lowerTop = top.toLowerCase();
  33. const lowerRight = right.toLowerCase();
  34. const lowerBottom = bottom && bottom.toLowerCase();
  35. const lowerLeft = left && left.toLowerCase();
  36. if (canCondenseToOneValue(lowerTop, lowerRight, lowerBottom, lowerLeft)) {
  37. return [top];
  38. }
  39. if (canCondenseToTwoValues(lowerTop, lowerRight, lowerBottom, lowerLeft)) {
  40. return [top, right];
  41. }
  42. if (canCondenseToThreeValues(lowerTop, lowerRight, lowerBottom, lowerLeft)) {
  43. return [top, right, bottom];
  44. }
  45. return [top, right, bottom, left];
  46. }
  47. function canCondenseToOneValue(top, right, bottom, left) {
  48. if (top !== right) {
  49. return false;
  50. }
  51. return (top === bottom && (bottom === left || !left)) || (!bottom && !left);
  52. }
  53. function canCondenseToTwoValues(top, right, bottom, left) {
  54. return (top === bottom && right === left) || (top === bottom && !left && top !== right);
  55. }
  56. function canCondenseToThreeValues(top, right, bottom, left) {
  57. return right === left;
  58. }
  59. function rule(actual, secondary, context) {
  60. return (root, result) => {
  61. const validOptions = validateOptions(result, ruleName, { actual });
  62. if (!validOptions) {
  63. return;
  64. }
  65. root.walkDecls((decl) => {
  66. if (!isStandardSyntaxDeclaration(decl) || !isStandardSyntaxProperty(decl.prop)) {
  67. return;
  68. }
  69. const prop = decl.prop;
  70. const value = decl.value;
  71. const normalizedProp = vendor.unprefixed(prop.toLowerCase());
  72. if (hasIgnoredCharacters(value) || !isShorthandProperty(normalizedProp)) {
  73. return;
  74. }
  75. const valuesToShorthand = [];
  76. valueParser(value).walk((valueNode) => {
  77. if (valueNode.type !== 'word') {
  78. return;
  79. }
  80. valuesToShorthand.push(valueParser.stringify(valueNode));
  81. });
  82. if (valuesToShorthand.length <= 1 || valuesToShorthand.length > 4) {
  83. return;
  84. }
  85. const shortestForm = canCondense(...valuesToShorthand);
  86. const shortestFormString = shortestForm.filter(Boolean).join(' ');
  87. const valuesFormString = valuesToShorthand.join(' ');
  88. if (shortestFormString.toLowerCase() === valuesFormString.toLowerCase()) {
  89. return;
  90. }
  91. if (context.fix) {
  92. decl.value = decl.value.replace(value, shortestFormString);
  93. } else {
  94. report({
  95. message: messages.rejected(value, shortestFormString),
  96. node: decl,
  97. result,
  98. ruleName,
  99. });
  100. }
  101. });
  102. };
  103. }
  104. rule.ruleName = ruleName;
  105. rule.messages = messages;
  106. module.exports = rule;