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

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-after';
  10. const messages = ruleMessages(ruleName, {
  11. expectedAfter: () => 'Expected single space after range operator',
  12. rejectedAfter: () => 'Unexpected whitespace after 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. checkAfterOperator(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 + 1);
  36. const afterOperator = params.slice(index + 1);
  37. if (expectation === 'always') {
  38. params = beforeOperator + afterOperator.replace(/^\s*/, ' ');
  39. } else if (expectation === 'never') {
  40. params = beforeOperator + afterOperator.replace(/^\s*/, '');
  41. }
  42. });
  43. if (atRule.raws.params) {
  44. atRule.raws.params.raw = params;
  45. } else {
  46. atRule.params = params;
  47. }
  48. }
  49. });
  50. function checkAfterOperator(match, params, node, fix) {
  51. const endIndex = match.startIndex + match.target.length - 1;
  52. checker.after({
  53. source: params,
  54. index: endIndex,
  55. err: (m) => {
  56. if (fix) {
  57. fix(endIndex);
  58. return;
  59. }
  60. report({
  61. message: m,
  62. node,
  63. index: endIndex + atRuleParamIndex(node) + 1,
  64. result,
  65. ruleName,
  66. });
  67. },
  68. });
  69. }
  70. };
  71. }
  72. rule.ruleName = ruleName;
  73. rule.messages = messages;
  74. module.exports = rule;