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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @ts-nocheck
  2. 'use strict';
  3. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  4. const findMediaOperator = require('../findMediaOperator');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const whitespaceChecker = require('../../utils/whitespaceChecker');
  9. const ruleName = 'media-feature-range-operator-space-before';
  10. const messages = ruleMessages(ruleName, {
  11. expectedBefore: () => 'Expected single space before range operator',
  12. rejectedBefore: () => 'Unexpected whitespace before range operator',
  13. });
  14. function rule(expectation, options, context) {
  15. const checker = whitespaceChecker('space', expectation, messages);
  16. return (root, result) => {
  17. const validOptions = validateOptions(result, ruleName, {
  18. actual: expectation,
  19. possible: ['always', 'never'],
  20. });
  21. if (!validOptions) {
  22. return;
  23. }
  24. root.walkAtRules(/^media$/i, (atRule) => {
  25. const fixOperatorIndices = [];
  26. const fix = context.fix ? (index) => fixOperatorIndices.push(index) : null;
  27. findMediaOperator(atRule, (match, params, node) => {
  28. checkBeforeOperator(match, params, node, fix);
  29. });
  30. if (fixOperatorIndices.length) {
  31. let params = atRule.raws.params ? atRule.raws.params.raw : atRule.params;
  32. fixOperatorIndices
  33. .sort((a, b) => b - a)
  34. .forEach((index) => {
  35. const beforeOperator = params.slice(0, index);
  36. const afterOperator = params.slice(index);
  37. if (expectation === 'always') {
  38. params = beforeOperator.replace(/\s*$/, ' ') + afterOperator;
  39. } else if (expectation === 'never') {
  40. params = beforeOperator.replace(/\s*$/, '') + afterOperator;
  41. }
  42. });
  43. if (atRule.raws.params) {
  44. atRule.raws.params.raw = params;
  45. } else {
  46. atRule.params = params;
  47. }
  48. }
  49. });
  50. function checkBeforeOperator(match, params, node, fix) {
  51. // The extra `+ 1` is because the match itself contains
  52. // the character before the operator
  53. checker.before({
  54. source: params,
  55. index: match.startIndex,
  56. err: (m) => {
  57. if (fix) {
  58. fix(match.startIndex);
  59. return;
  60. }
  61. report({
  62. message: m,
  63. node,
  64. index: match.startIndex - 1 + atRuleParamIndex(node),
  65. result,
  66. ruleName,
  67. });
  68. },
  69. });
  70. }
  71. };
  72. }
  73. rule.ruleName = ruleName;
  74. rule.messages = messages;
  75. module.exports = rule;