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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // @ts-nocheck
  2. 'use strict';
  3. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  4. const declarationValueIndex = require('../../utils/declarationValueIndex');
  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 ruleName = 'number-no-trailing-zeros';
  10. const messages = ruleMessages(ruleName, {
  11. rejected: 'Unexpected trailing zero(s)',
  12. });
  13. function rule(actual, secondary, context) {
  14. return (root, result) => {
  15. const validOptions = validateOptions(result, ruleName, { actual });
  16. if (!validOptions) {
  17. return;
  18. }
  19. root.walkAtRules((atRule) => {
  20. if (atRule.name.toLowerCase() === 'import') {
  21. return;
  22. }
  23. check(atRule, atRule.params, atRuleParamIndex);
  24. });
  25. root.walkDecls((decl) => check(decl, decl.value, declarationValueIndex));
  26. function check(node, value, getIndex) {
  27. const fixPositions = [];
  28. // Get out quickly if there are no periods
  29. if (!value.includes('.')) {
  30. return;
  31. }
  32. valueParser(value).walk((valueNode) => {
  33. // Ignore `url` function
  34. if (valueNode.type === 'function' && valueNode.value.toLowerCase() === 'url') {
  35. return false;
  36. }
  37. // Ignore strings, comments, etc
  38. if (valueNode.type !== 'word') {
  39. return;
  40. }
  41. const match = /\.(\d*?)(0+)(?:\D|$)/.exec(valueNode.value);
  42. // match[1] is any numbers between the decimal and our trailing zero, could be empty
  43. // match[2] is our trailing zero(s)
  44. if (match === null) {
  45. return;
  46. }
  47. // our index is:
  48. // the index of our valueNode +
  49. // the index of our match +
  50. // 1 for our decimal +
  51. // the length of our potential non-zero number match (match[1])
  52. const index = valueNode.sourceIndex + match.index + 1 + match[1].length;
  53. // our startIndex is identical to our index except when we have only
  54. // trailing zeros after our decimal. in that case we don't need the decimal
  55. // either so we move our index back by 1.
  56. const startIndex = match[1].length > 0 ? index : index - 1;
  57. // our end index is our original index + the length of our trailing zeros
  58. const endIndex = index + match[2].length;
  59. if (context.fix) {
  60. fixPositions.unshift({
  61. startIndex,
  62. endIndex,
  63. });
  64. return;
  65. }
  66. report({
  67. message: messages.rejected,
  68. node,
  69. // this is the index of the _first_ trailing zero
  70. index: getIndex(node) + index,
  71. result,
  72. ruleName,
  73. });
  74. });
  75. if (fixPositions.length) {
  76. fixPositions.forEach((fixPosition) => {
  77. const startIndex = fixPosition.startIndex;
  78. const endIndex = fixPosition.endIndex;
  79. if (node.type === 'atrule') {
  80. node.params = removeTrailingZeros(node.params, startIndex, endIndex);
  81. } else {
  82. node.value = removeTrailingZeros(node.value, startIndex, endIndex);
  83. }
  84. });
  85. }
  86. }
  87. };
  88. }
  89. function removeTrailingZeros(input, startIndex, endIndex) {
  90. return input.slice(0, startIndex) + input.slice(endIndex);
  91. }
  92. rule.ruleName = ruleName;
  93. rule.messages = messages;
  94. module.exports = rule;