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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../../utils/declarationValueIndex');
  4. const functionArgumentsSearch = require('../../utils/functionArgumentsSearch');
  5. const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
  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 vendor = require('../../utils/vendor');
  11. const ruleName = 'function-linear-gradient-no-nonstandard-direction';
  12. const messages = ruleMessages(ruleName, {
  13. rejected: 'Unexpected nonstandard direction',
  14. });
  15. function isStandardDirection(source, withToPrefix) {
  16. const regexp = withToPrefix
  17. ? /^to (top|left|bottom|right)(?: (top|left|bottom|right))?$/
  18. : /^(top|left|bottom|right)(?: (top|left|bottom|right))?$/;
  19. const matches = source.match(regexp);
  20. if (!matches) {
  21. return false;
  22. }
  23. if (matches.length === 2) {
  24. return true;
  25. }
  26. // Cannot repeat side-or-corner, e.g. "to top top"
  27. if (matches.length === 3 && matches[1] !== matches[2]) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. function rule(actual) {
  33. return (root, result) => {
  34. const validOptions = validateOptions(result, ruleName, { actual });
  35. if (!validOptions) {
  36. return;
  37. }
  38. root.walkDecls((decl) => {
  39. valueParser(decl.value).walk((valueNode) => {
  40. if (valueNode.type !== 'function') {
  41. return;
  42. }
  43. functionArgumentsSearch(
  44. valueParser.stringify(valueNode).toLowerCase(),
  45. 'linear-gradient',
  46. (expression, expressionIndex) => {
  47. const firstArg = expression.split(',')[0].trim();
  48. // If the first arg is not standard, return early
  49. if (!isStandardSyntaxValue(firstArg)) {
  50. return;
  51. }
  52. // If the first character is a number, we can assume the user intends an angle
  53. if (/[\d.]/.test(firstArg[0])) {
  54. if (/^[\d.]+(?:deg|grad|rad|turn)$/.test(firstArg)) {
  55. return;
  56. }
  57. complain();
  58. return;
  59. }
  60. // The first argument may not be a direction: it may be an angle,
  61. // or a color stop (in which case user gets default direction, "to bottom")
  62. // cf. https://drafts.csswg.org/css-images-3/#linear-gradient-syntax
  63. if (!/left|right|top|bottom/.test(firstArg)) {
  64. return;
  65. }
  66. const withToPrefix = !vendor.prefix(valueNode.value);
  67. if (!isStandardDirection(firstArg, withToPrefix)) {
  68. complain();
  69. }
  70. function complain() {
  71. report({
  72. message: messages.rejected,
  73. node: decl,
  74. index: declarationValueIndex(decl) + valueNode.sourceIndex + expressionIndex,
  75. result,
  76. ruleName,
  77. });
  78. }
  79. },
  80. );
  81. });
  82. });
  83. };
  84. }
  85. rule.ruleName = ruleName;
  86. rule.messages = messages;
  87. module.exports = rule;