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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const hasBlock = require('../../utils/hasBlock');
  5. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  6. const optionsMatches = require('../../utils/optionsMatches');
  7. const parser = require('postcss-selector-parser');
  8. const report = require('../../utils/report');
  9. const ruleMessages = require('../../utils/ruleMessages');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const ruleName = 'max-nesting-depth';
  12. const messages = ruleMessages(ruleName, {
  13. expected: (depth) => `Expected nesting depth to be no more than ${depth}`,
  14. });
  15. function rule(max, options) {
  16. const isIgnoreAtRule = (node) =>
  17. node.type === 'atrule' && optionsMatches(options, 'ignoreAtRules', node.name);
  18. return (root, result) => {
  19. validateOptions(
  20. result,
  21. ruleName,
  22. {
  23. actual: max,
  24. possible: [_.isNumber],
  25. },
  26. {
  27. optional: true,
  28. actual: options,
  29. possible: {
  30. ignore: ['blockless-at-rules', 'pseudo-classes'],
  31. ignoreAtRules: [_.isString, _.isRegExp],
  32. },
  33. },
  34. );
  35. root.walkRules(checkStatement);
  36. root.walkAtRules(checkStatement);
  37. function checkStatement(statement) {
  38. if (isIgnoreAtRule(statement)) {
  39. return;
  40. }
  41. if (!hasBlock(statement)) {
  42. return;
  43. }
  44. if (statement.selector && !isStandardSyntaxRule(statement)) {
  45. return;
  46. }
  47. const depth = nestingDepth(statement);
  48. if (depth > max) {
  49. report({
  50. ruleName,
  51. result,
  52. node: statement,
  53. message: messages.expected(max),
  54. });
  55. }
  56. }
  57. };
  58. function nestingDepth(node, level = 0) {
  59. const parent = node.parent;
  60. if (isIgnoreAtRule(parent)) {
  61. return 0;
  62. }
  63. // The nesting depth level's computation has finished
  64. // when this function, recursively called, receives
  65. // a node that is not nested -- a direct child of the
  66. // root node
  67. if (parent.type === 'root' || (parent.type === 'atrule' && parent.parent.type === 'root')) {
  68. return level;
  69. }
  70. function containsPseudoClassesOnly(selector) {
  71. const normalized = parser().processSync(selector, { lossless: false });
  72. const selectors = normalized.split(',');
  73. return selectors.every((sel) => sel.startsWith('&:') && sel[2] !== ':');
  74. }
  75. if (
  76. (optionsMatches(options, 'ignore', 'blockless-at-rules') &&
  77. node.type === 'atrule' &&
  78. node.every((child) => child.type !== 'decl')) ||
  79. (optionsMatches(options, 'ignore', 'pseudo-classes') &&
  80. node.type === 'rule' &&
  81. containsPseudoClassesOnly(node.selector))
  82. ) {
  83. return nestingDepth(parent, level);
  84. }
  85. // Unless any of the conditions above apply, we want to
  86. // add 1 to the nesting depth level and then check the parent,
  87. // continuing to add and move up the hierarchy
  88. // until we hit the root node
  89. return nestingDepth(parent, level + 1);
  90. }
  91. }
  92. rule.ruleName = ruleName;
  93. rule.messages = messages;
  94. module.exports = rule;