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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const findAtRuleContext = require('../../utils/findAtRuleContext');
  5. const isCustomPropertySet = require('../../utils/isCustomPropertySet');
  6. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  7. const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
  8. const keywordSets = require('../../reference/keywordSets');
  9. const nodeContextLookup = require('../../utils/nodeContextLookup');
  10. const optionsMatches = require('../../utils/optionsMatches');
  11. const parseSelector = require('../../utils/parseSelector');
  12. const report = require('../../utils/report');
  13. const resolvedNestedSelector = require('postcss-resolve-nested-selector');
  14. const ruleMessages = require('../../utils/ruleMessages');
  15. const specificity = require('specificity');
  16. const validateOptions = require('../../utils/validateOptions');
  17. const ruleName = 'no-descending-specificity';
  18. const messages = ruleMessages(ruleName, {
  19. rejected: (b, a) => `Expected selector "${b}" to come before selector "${a}"`,
  20. });
  21. function rule(on, options) {
  22. return (root, result) => {
  23. const validOptions = validateOptions(
  24. result,
  25. ruleName,
  26. {
  27. actual: on,
  28. },
  29. {
  30. optional: true,
  31. actual: options,
  32. possible: {
  33. ignore: ['selectors-within-list'],
  34. },
  35. },
  36. );
  37. if (!validOptions) {
  38. return;
  39. }
  40. const selectorContextLookup = nodeContextLookup();
  41. root.walkRules((ruleNode) => {
  42. // Ignore custom property set `--foo: {};`
  43. if (isCustomPropertySet(ruleNode)) {
  44. return;
  45. }
  46. // Ignore nested property `foo: {};`
  47. if (!isStandardSyntaxRule(ruleNode)) {
  48. return;
  49. }
  50. // Ignores selectors within list of selectors
  51. if (
  52. optionsMatches(options, 'ignore', 'selectors-within-list') &&
  53. ruleNode.selectors.length > 1
  54. ) {
  55. return;
  56. }
  57. const comparisonContext = selectorContextLookup.getContext(
  58. ruleNode,
  59. findAtRuleContext(ruleNode),
  60. );
  61. ruleNode.selectors.forEach((selector) => {
  62. const trimSelector = selector.trim();
  63. // Ignore `.selector, { }`
  64. if (trimSelector === '') {
  65. return;
  66. }
  67. // The edge-case of duplicate selectors will act acceptably
  68. const index = ruleNode.selector.indexOf(trimSelector);
  69. // Resolve any nested selectors before checking
  70. resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
  71. parseSelector(resolvedSelector, result, ruleNode, (s) => {
  72. if (!isStandardSyntaxSelector(resolvedSelector)) {
  73. return;
  74. }
  75. checkSelector(s, ruleNode, index, comparisonContext);
  76. });
  77. });
  78. });
  79. });
  80. function checkSelector(selectorNode, ruleNode, sourceIndex, comparisonContext) {
  81. const selector = selectorNode.toString();
  82. const referenceSelectorNode = lastCompoundSelectorWithoutPseudoClasses(selectorNode);
  83. const selectorSpecificity = specificity.calculate(selector)[0].specificityArray;
  84. const entry = { selector, specificity: selectorSpecificity };
  85. if (!comparisonContext.has(referenceSelectorNode)) {
  86. comparisonContext.set(referenceSelectorNode, [entry]);
  87. return;
  88. }
  89. const priorComparableSelectors = comparisonContext.get(referenceSelectorNode);
  90. priorComparableSelectors.forEach((priorEntry) => {
  91. if (specificity.compare(selectorSpecificity, priorEntry.specificity) === -1) {
  92. report({
  93. ruleName,
  94. result,
  95. node: ruleNode,
  96. message: messages.rejected(selector, priorEntry.selector),
  97. index: sourceIndex,
  98. });
  99. }
  100. });
  101. priorComparableSelectors.push(entry);
  102. }
  103. };
  104. }
  105. function lastCompoundSelectorWithoutPseudoClasses(selectorNode) {
  106. const nodesAfterLastCombinator = _.last(
  107. selectorNode.nodes[0].split((node) => {
  108. return node.type === 'combinator';
  109. }),
  110. );
  111. const nodesWithoutPseudoClasses = nodesAfterLastCombinator
  112. .filter((node) => {
  113. return node.type !== 'pseudo' || keywordSets.pseudoElements.has(node.value.replace(/:/g, ''));
  114. })
  115. .join('');
  116. return nodesWithoutPseudoClasses.toString();
  117. }
  118. rule.ruleName = ruleName;
  119. rule.messages = messages;
  120. module.exports = rule;