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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const isKeyframeSelector = require('../../utils/isKeyframeSelector');
  5. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  6. const isStandardSyntaxTypeSelector = require('../../utils/isStandardSyntaxTypeSelector');
  7. const optionsMatches = require('../../utils/optionsMatches');
  8. const parseSelector = require('../../utils/parseSelector');
  9. const report = require('../../utils/report');
  10. const ruleMessages = require('../../utils/ruleMessages');
  11. const validateOptions = require('../../utils/validateOptions');
  12. const ruleName = 'selector-type-case';
  13. const messages = ruleMessages(ruleName, {
  14. expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
  15. });
  16. function rule(expectation, options, context) {
  17. return (root, result) => {
  18. const validOptions = validateOptions(
  19. result,
  20. ruleName,
  21. {
  22. actual: expectation,
  23. possible: ['lower', 'upper'],
  24. },
  25. {
  26. actual: options,
  27. possible: {
  28. ignoreTypes: [_.isString],
  29. },
  30. optional: true,
  31. },
  32. );
  33. if (!validOptions) {
  34. return;
  35. }
  36. root.walkRules((ruleNode) => {
  37. let hasComments = _.get(ruleNode, 'raws.selector.raw');
  38. const selector = hasComments ? hasComments : ruleNode.selector;
  39. const selectors = ruleNode.selectors;
  40. if (!isStandardSyntaxRule(ruleNode)) {
  41. return;
  42. }
  43. if (selectors.some((s) => isKeyframeSelector(s))) {
  44. return;
  45. }
  46. parseSelector(selector, result, ruleNode, (selectorAST) => {
  47. selectorAST.walkTags((tag) => {
  48. if (!isStandardSyntaxTypeSelector(tag)) {
  49. return;
  50. }
  51. if (optionsMatches(options, 'ignoreTypes', tag.value)) {
  52. return;
  53. }
  54. const sourceIndex = tag.sourceIndex;
  55. const value = tag.value;
  56. const expectedValue = expectation === 'lower' ? value.toLowerCase() : value.toUpperCase();
  57. if (value === expectedValue) {
  58. return;
  59. }
  60. if (context.fix) {
  61. if (hasComments) {
  62. hasComments =
  63. hasComments.slice(0, sourceIndex) +
  64. expectedValue +
  65. hasComments.slice(sourceIndex + value.length);
  66. _.set(ruleNode, 'raws.selector.raw', hasComments);
  67. } else {
  68. ruleNode.selector =
  69. ruleNode.selector.slice(0, sourceIndex) +
  70. expectedValue +
  71. ruleNode.selector.slice(sourceIndex + value.length);
  72. }
  73. return;
  74. }
  75. report({
  76. message: messages.expected(value, expectedValue),
  77. node: ruleNode,
  78. index: sourceIndex,
  79. ruleName,
  80. result,
  81. });
  82. });
  83. });
  84. });
  85. };
  86. }
  87. rule.ruleName = ruleName;
  88. rule.messages = messages;
  89. module.exports = rule;