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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // @ts-nocheck
  2. 'use strict';
  3. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  4. const declarationValueIndex = require('../../utils/declarationValueIndex');
  5. const getUnitFromValueNode = require('../../utils/getUnitFromValueNode');
  6. const report = require('../../utils/report');
  7. const ruleMessages = require('../../utils/ruleMessages');
  8. const validateOptions = require('../../utils/validateOptions');
  9. const valueParser = require('postcss-value-parser');
  10. const ruleName = 'unit-case';
  11. const messages = ruleMessages(ruleName, {
  12. expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
  13. });
  14. function rule(expectation, options, context) {
  15. return (root, result) => {
  16. const validOptions = validateOptions(result, ruleName, {
  17. actual: expectation,
  18. possible: ['lower', 'upper'],
  19. });
  20. if (!validOptions) {
  21. return;
  22. }
  23. function check(node, checkedValue, getIndex) {
  24. const violations = [];
  25. function processValue(valueNode) {
  26. const unit = getUnitFromValueNode(valueNode);
  27. if (!unit) {
  28. return false;
  29. }
  30. const expectedUnit = expectation === 'lower' ? unit.toLowerCase() : unit.toUpperCase();
  31. if (unit === expectedUnit) {
  32. return false;
  33. }
  34. violations.push({
  35. index: getIndex(node) + valueNode.sourceIndex,
  36. message: messages.expected(unit, expectedUnit),
  37. });
  38. return true;
  39. }
  40. const parsedValue = valueParser(checkedValue).walk((valueNode) => {
  41. // Ignore wrong units within `url` function
  42. let needFix = false;
  43. const value = valueNode.value;
  44. if (valueNode.type === 'function' && value.toLowerCase() === 'url') {
  45. return false;
  46. }
  47. if (value.includes('*')) {
  48. value.split('*').some((val) => {
  49. return processValue({
  50. ...valueNode,
  51. sourceIndex: value.indexOf(val) + val.length + 1,
  52. value: val,
  53. });
  54. });
  55. }
  56. needFix = processValue(valueNode);
  57. if (needFix && context.fix) {
  58. valueNode.value = expectation === 'lower' ? value.toLowerCase() : value.toUpperCase();
  59. }
  60. });
  61. if (violations.length) {
  62. if (context.fix) {
  63. if (node.name === 'media') {
  64. node.params = parsedValue.toString();
  65. } else {
  66. node.value = parsedValue.toString();
  67. }
  68. } else {
  69. violations.forEach((err) => {
  70. report({
  71. index: err.index,
  72. message: err.message,
  73. node,
  74. result,
  75. ruleName,
  76. });
  77. });
  78. }
  79. }
  80. }
  81. root.walkAtRules((atRule) => {
  82. if (!/^media$/i.test(atRule.name) && !atRule.variable) {
  83. return;
  84. }
  85. check(atRule, atRule.params, atRuleParamIndex);
  86. });
  87. root.walkDecls((decl) => check(decl, decl.value, declarationValueIndex));
  88. };
  89. }
  90. rule.ruleName = ruleName;
  91. rule.messages = messages;
  92. module.exports = rule;