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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../../utils/declarationValueIndex');
  4. const getDeclarationValue = require('../../utils/getDeclarationValue');
  5. const ruleMessages = require('../../utils/ruleMessages');
  6. const setDeclarationValue = require('../../utils/setDeclarationValue');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const valueListCommaWhitespaceChecker = require('../valueListCommaWhitespaceChecker');
  9. const whitespaceChecker = require('../../utils/whitespaceChecker');
  10. const ruleName = 'value-list-comma-space-before';
  11. const messages = ruleMessages(ruleName, {
  12. expectedBefore: () => 'Expected single space before ","',
  13. rejectedBefore: () => 'Unexpected whitespace before ","',
  14. expectedBeforeSingleLine: () => 'Unexpected whitespace before "," in a single-line list',
  15. rejectedBeforeSingleLine: () => 'Unexpected whitespace before "," in a single-line list',
  16. });
  17. function rule(expectation, options, context) {
  18. const checker = whitespaceChecker('space', expectation, messages);
  19. return (root, result) => {
  20. const validOptions = validateOptions(result, ruleName, {
  21. actual: expectation,
  22. possible: ['always', 'never', 'always-single-line', 'never-single-line'],
  23. });
  24. if (!validOptions) {
  25. return;
  26. }
  27. let fixData;
  28. valueListCommaWhitespaceChecker({
  29. root,
  30. result,
  31. locationChecker: checker.before,
  32. checkedRuleName: ruleName,
  33. fix: context.fix
  34. ? (declNode, index) => {
  35. const valueIndex = declarationValueIndex(declNode);
  36. if (index <= valueIndex) {
  37. return false;
  38. }
  39. fixData = fixData || new Map();
  40. const commaIndices = fixData.get(declNode) || [];
  41. commaIndices.push(index);
  42. fixData.set(declNode, commaIndices);
  43. return true;
  44. }
  45. : null,
  46. });
  47. if (fixData) {
  48. fixData.forEach((commaIndices, decl) => {
  49. commaIndices
  50. .sort((a, b) => b - a)
  51. .forEach((index) => {
  52. const value = getDeclarationValue(decl);
  53. const valueIndex = index - declarationValueIndex(decl);
  54. let beforeValue = value.slice(0, valueIndex);
  55. const afterValue = value.slice(valueIndex);
  56. if (expectation.startsWith('always')) {
  57. beforeValue = beforeValue.replace(/\s*$/, ' ');
  58. } else if (expectation.startsWith('never')) {
  59. beforeValue = beforeValue.replace(/\s*$/, '');
  60. }
  61. setDeclarationValue(decl, beforeValue + afterValue);
  62. });
  63. });
  64. }
  65. };
  66. }
  67. rule.ruleName = ruleName;
  68. rule.messages = messages;
  69. module.exports = rule;