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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // @ts-nocheck
  2. 'use strict';
  3. const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass');
  4. const isNonNegativeInteger = require('../../utils/isNonNegativeInteger');
  5. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  6. const parseSelector = require('../../utils/parseSelector');
  7. const report = require('../../utils/report');
  8. const resolvedNestedSelector = require('postcss-resolve-nested-selector');
  9. const ruleMessages = require('../../utils/ruleMessages');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const ruleName = 'selector-max-compound-selectors';
  12. const messages = ruleMessages(ruleName, {
  13. expected: (selector, max) =>
  14. `Expected "${selector}" to have no more than ${max} compound ${
  15. max === 1 ? 'selector' : 'selectors'
  16. }`,
  17. });
  18. function rule(max) {
  19. return (root, result) => {
  20. const validOptions = validateOptions(result, ruleName, {
  21. actual: max,
  22. possible: isNonNegativeInteger,
  23. });
  24. if (!validOptions) {
  25. return;
  26. }
  27. // Finds actual selectors in selectorNode object and checks them
  28. function checkSelector(selectorNode, ruleNode) {
  29. let compoundCount = 1;
  30. selectorNode.each((childNode) => {
  31. // Only traverse inside actual selectors and context functional pseudo-classes
  32. if (childNode.type === 'selector' || isContextFunctionalPseudoClass(childNode)) {
  33. checkSelector(childNode, ruleNode);
  34. }
  35. // Compound selectors are separated by combinators, so increase count when meeting one
  36. if (childNode.type === 'combinator') {
  37. compoundCount++;
  38. }
  39. });
  40. if (selectorNode.type !== 'root' && selectorNode.type !== 'pseudo' && compoundCount > max) {
  41. report({
  42. ruleName,
  43. result,
  44. node: ruleNode,
  45. message: messages.expected(selectorNode, max),
  46. word: selectorNode,
  47. });
  48. }
  49. }
  50. root.walkRules((ruleNode) => {
  51. if (!isStandardSyntaxRule(ruleNode)) {
  52. return;
  53. }
  54. // Using `.selectors` gets us each selector if there is a comma separated set
  55. ruleNode.selectors.forEach((selector) => {
  56. resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
  57. // Process each resolved selector with `checkSelector` via postcss-selector-parser
  58. parseSelector(resolvedSelector, result, ruleNode, (s) => checkSelector(s, ruleNode));
  59. });
  60. });
  61. });
  62. };
  63. }
  64. rule.ruleName = ruleName;
  65. rule.messages = messages;
  66. module.exports = rule;