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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 optionsMatches = require('../../utils/optionsMatches');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const _ = require('lodash');
  11. const valueParser = require('postcss-value-parser');
  12. const ruleName = 'number-max-precision';
  13. const messages = ruleMessages(ruleName, {
  14. expected: (number, precision) => `Expected "${number}" to be "${number.toFixed(precision)}"`,
  15. });
  16. function rule(precision, options) {
  17. return (root, result) => {
  18. const validOptions = validateOptions(
  19. result,
  20. ruleName,
  21. {
  22. actual: precision,
  23. possible: [_.isNumber],
  24. },
  25. {
  26. optional: true,
  27. actual: options,
  28. possible: {
  29. ignoreUnits: [_.isString, _.isRegExp],
  30. },
  31. },
  32. );
  33. if (!validOptions) {
  34. return;
  35. }
  36. root.walkAtRules((atRule) => {
  37. if (atRule.name.toLowerCase() === 'import') {
  38. return;
  39. }
  40. check(atRule, atRule.params, atRuleParamIndex);
  41. });
  42. root.walkDecls((decl) => check(decl, decl.value, declarationValueIndex));
  43. function check(node, value, getIndex) {
  44. // Get out quickly if there are no periods
  45. if (!value.includes('.')) {
  46. return;
  47. }
  48. valueParser(value).walk((valueNode) => {
  49. const unit = getUnitFromValueNode(valueNode);
  50. if (optionsMatches(options, 'ignoreUnits', unit)) {
  51. return;
  52. }
  53. // Ignore `url` function
  54. if (valueNode.type === 'function' && valueNode.value.toLowerCase() === 'url') {
  55. return false;
  56. }
  57. // Ignore strings, comments, etc
  58. if (valueNode.type !== 'word') {
  59. return;
  60. }
  61. const match = /\d*\.(\d+)/.exec(valueNode.value);
  62. if (match === null) {
  63. return;
  64. }
  65. if (match[1].length <= precision) {
  66. return;
  67. }
  68. report({
  69. result,
  70. ruleName,
  71. node,
  72. index: getIndex(node) + valueNode.sourceIndex + match.index,
  73. message: messages.expected(Number.parseFloat(match[0]), precision),
  74. });
  75. });
  76. }
  77. };
  78. }
  79. rule.ruleName = ruleName;
  80. rule.messages = messages;
  81. module.exports = rule;