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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  5. const isCustomMediaQuery = require('../../utils/isCustomMediaQuery');
  6. const isRangeContextMediaFeature = require('../../utils/isRangeContextMediaFeature');
  7. const isStandardSyntaxMediaFeatureName = require('../../utils/isStandardSyntaxMediaFeatureName');
  8. const mediaParser = require('postcss-media-query-parser').default;
  9. const rangeContextNodeParser = require('../rangeContextNodeParser');
  10. const report = require('../../utils/report');
  11. const ruleMessages = require('../../utils/ruleMessages');
  12. const validateOptions = require('../../utils/validateOptions');
  13. const ruleName = 'media-feature-name-case';
  14. const messages = ruleMessages(ruleName, {
  15. expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
  16. });
  17. function rule(expectation, options, context) {
  18. return (root, result) => {
  19. const validOptions = validateOptions(result, ruleName, {
  20. actual: expectation,
  21. possible: ['lower', 'upper'],
  22. });
  23. if (!validOptions) {
  24. return;
  25. }
  26. root.walkAtRules(/^media$/i, (atRule) => {
  27. let hasComments = _.get(atRule, 'raws.params.raw');
  28. const mediaRule = hasComments ? hasComments : atRule.params;
  29. mediaParser(mediaRule).walk(/^media-feature$/i, (mediaFeatureNode) => {
  30. const parent = mediaFeatureNode.parent;
  31. const mediaFeatureRangeContext = isRangeContextMediaFeature(parent.value);
  32. let value;
  33. let sourceIndex;
  34. if (mediaFeatureRangeContext) {
  35. const parsedRangeContext = rangeContextNodeParser(mediaFeatureNode);
  36. value = parsedRangeContext.name.value;
  37. sourceIndex = parsedRangeContext.name.sourceIndex;
  38. } else {
  39. value = mediaFeatureNode.value;
  40. sourceIndex = mediaFeatureNode.sourceIndex;
  41. }
  42. if (!isStandardSyntaxMediaFeatureName(value) || isCustomMediaQuery(value)) {
  43. return;
  44. }
  45. const expectedFeatureName =
  46. expectation === 'lower' ? value.toLowerCase() : value.toUpperCase();
  47. if (value === expectedFeatureName) {
  48. return;
  49. }
  50. if (context.fix) {
  51. if (hasComments) {
  52. hasComments =
  53. hasComments.slice(0, sourceIndex) +
  54. expectedFeatureName +
  55. hasComments.slice(sourceIndex + expectedFeatureName.length);
  56. _.set(atRule, 'raws.params.raw', hasComments);
  57. } else {
  58. atRule.params =
  59. atRule.params.slice(0, sourceIndex) +
  60. expectedFeatureName +
  61. atRule.params.slice(sourceIndex + expectedFeatureName.length);
  62. }
  63. return;
  64. }
  65. report({
  66. index: atRuleParamIndex(atRule) + sourceIndex,
  67. message: messages.expected(value, expectedFeatureName),
  68. node: atRule,
  69. ruleName,
  70. result,
  71. });
  72. });
  73. });
  74. };
  75. }
  76. rule.ruleName = ruleName;
  77. rule.messages = messages;
  78. module.exports = rule;