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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @ts-nocheck
  2. 'use strict';
  3. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  4. const keywordSets = require('../../reference/keywordSets');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const styleSearch = require('style-search');
  8. const validateOptions = require('../../utils/validateOptions');
  9. const ruleName = 'selector-pseudo-element-colon-notation';
  10. const messages = ruleMessages(ruleName, {
  11. expected: (q) => `Expected ${q} colon pseudo-element notation`,
  12. });
  13. function rule(expectation, options, context) {
  14. return (root, result) => {
  15. const validOptions = validateOptions(result, ruleName, {
  16. actual: expectation,
  17. possible: ['single', 'double'],
  18. });
  19. if (!validOptions) {
  20. return;
  21. }
  22. root.walkRules((ruleNode) => {
  23. if (!isStandardSyntaxRule(ruleNode)) {
  24. return;
  25. }
  26. const selector = ruleNode.selector;
  27. // get out early if no pseudo elements or classes
  28. if (!selector.includes(':')) {
  29. return;
  30. }
  31. const fixPositions = [];
  32. // match only level 1 and 2 pseudo elements
  33. const pseudoElementsWithColons = [...keywordSets.levelOneAndTwoPseudoElements].map(
  34. (x) => `:${x}`,
  35. );
  36. styleSearch({ source: selector.toLowerCase(), target: pseudoElementsWithColons }, (match) => {
  37. const prevCharIsColon = selector[match.startIndex - 1] === ':';
  38. if (expectation === 'single' && !prevCharIsColon) {
  39. return;
  40. }
  41. if (expectation === 'double' && prevCharIsColon) {
  42. return;
  43. }
  44. if (context.fix) {
  45. fixPositions.unshift({ ruleNode, startIndex: match.startIndex });
  46. return;
  47. }
  48. report({
  49. message: messages.expected(expectation),
  50. node: ruleNode,
  51. index: match.startIndex,
  52. result,
  53. ruleName,
  54. });
  55. });
  56. if (fixPositions.length) {
  57. // If expecting : then we found :: so remove one of the colons
  58. // If expecting :: then we found : so add one extra colon
  59. const expectedSingle = expectation === 'single';
  60. const offset = expectedSingle ? 1 : 0;
  61. const extraColon = expectedSingle ? '' : ':';
  62. fixPositions.forEach((fixPosition) => {
  63. ruleNode.selector =
  64. ruleNode.selector.substring(0, fixPosition.startIndex - offset) +
  65. extraColon +
  66. ruleNode.selector.substring(fixPosition.startIndex);
  67. });
  68. }
  69. });
  70. };
  71. }
  72. rule.ruleName = ruleName;
  73. rule.messages = messages;
  74. module.exports = rule;