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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const isKeyframeSelector = require('../../utils/isKeyframeSelector');
  5. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  6. const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
  7. const parseSelector = require('../../utils/parseSelector');
  8. const report = require('../../utils/report');
  9. const resolveNestedSelector = require('postcss-resolve-nested-selector');
  10. const ruleMessages = require('../../utils/ruleMessages');
  11. const validateOptions = require('../../utils/validateOptions');
  12. const ruleName = 'selector-class-pattern';
  13. const messages = ruleMessages(ruleName, {
  14. expected: (selectorValue, pattern) =>
  15. `Expected class selector ".${selectorValue}" to match pattern "${pattern}"`,
  16. });
  17. function rule(pattern, options) {
  18. return (root, result) => {
  19. const validOptions = validateOptions(
  20. result,
  21. ruleName,
  22. {
  23. actual: pattern,
  24. possible: [_.isRegExp, _.isString],
  25. },
  26. {
  27. actual: options,
  28. possible: {
  29. resolveNestedSelectors: _.isBoolean,
  30. },
  31. optional: true,
  32. },
  33. );
  34. if (!validOptions) {
  35. return;
  36. }
  37. const shouldResolveNestedSelectors = _.get(options, 'resolveNestedSelectors');
  38. const normalizedPattern = _.isString(pattern) ? new RegExp(pattern) : pattern;
  39. root.walkRules((ruleNode) => {
  40. const selector = ruleNode.selector;
  41. const selectors = ruleNode.selectors;
  42. if (!isStandardSyntaxRule(ruleNode)) {
  43. return;
  44. }
  45. if (selectors.some((s) => isKeyframeSelector(s))) {
  46. return;
  47. }
  48. // Only bother resolving selectors that have an interpolating &
  49. if (shouldResolveNestedSelectors && hasInterpolatingAmpersand(selector)) {
  50. resolveNestedSelector(selector, ruleNode).forEach((nestedSelector) => {
  51. if (!isStandardSyntaxSelector(nestedSelector)) {
  52. return;
  53. }
  54. parseSelector(nestedSelector, result, ruleNode, (s) => checkSelector(s, ruleNode));
  55. });
  56. } else {
  57. parseSelector(selector, result, ruleNode, (s) => checkSelector(s, ruleNode));
  58. }
  59. });
  60. function checkSelector(fullSelector, ruleNode) {
  61. fullSelector.walkClasses((classNode) => {
  62. const value = classNode.value;
  63. const sourceIndex = classNode.sourceIndex;
  64. if (normalizedPattern.test(value)) {
  65. return;
  66. }
  67. report({
  68. result,
  69. ruleName,
  70. message: messages.expected(value, pattern),
  71. node: ruleNode,
  72. index: sourceIndex,
  73. });
  74. });
  75. }
  76. };
  77. }
  78. // An "interpolating ampersand" means an "&" used to interpolate
  79. // within another simple selector, rather than an "&" that
  80. // stands on its own as a simple selector
  81. function hasInterpolatingAmpersand(selector) {
  82. for (let i = 0, l = selector.length; i < l; i++) {
  83. if (selector[i] !== '&') {
  84. continue;
  85. }
  86. if (selector[i - 1] !== undefined && !isCombinator(selector[i - 1])) {
  87. return true;
  88. }
  89. if (selector[i + 1] !== undefined && !isCombinator(selector[i + 1])) {
  90. return true;
  91. }
  92. }
  93. return false;
  94. }
  95. function isCombinator(x) {
  96. return /[\s+>~]/.test(x);
  97. }
  98. rule.ruleName = ruleName;
  99. rule.messages = messages;
  100. module.exports = rule;