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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../../utils/declarationValueIndex');
  4. const getDeclarationValue = require('../../utils/getDeclarationValue');
  5. const isSingleLineString = require('../../utils/isSingleLineString');
  6. const isStandardSyntaxFunction = require('../../utils/isStandardSyntaxFunction');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const setDeclarationValue = require('../../utils/setDeclarationValue');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const valueParser = require('postcss-value-parser');
  12. const ruleName = 'function-parentheses-space-inside';
  13. const messages = ruleMessages(ruleName, {
  14. expectedOpening: 'Expected single space after "("',
  15. rejectedOpening: 'Unexpected whitespace after "("',
  16. expectedClosing: 'Expected single space before ")"',
  17. rejectedClosing: 'Unexpected whitespace before ")"',
  18. expectedOpeningSingleLine: 'Expected single space after "(" in a single-line function',
  19. rejectedOpeningSingleLine: 'Unexpected whitespace after "(" in a single-line function',
  20. expectedClosingSingleLine: 'Expected single space before ")" in a single-line function',
  21. rejectedClosingSingleLine: 'Unexpected whitespace before ")" in a single-line function',
  22. });
  23. function rule(expectation, options, context) {
  24. return (root, result) => {
  25. const validOptions = validateOptions(result, ruleName, {
  26. actual: expectation,
  27. possible: ['always', 'never', 'always-single-line', 'never-single-line'],
  28. });
  29. if (!validOptions) {
  30. return;
  31. }
  32. root.walkDecls((decl) => {
  33. if (!decl.value.includes('(')) {
  34. return;
  35. }
  36. let hasFixed = false;
  37. const declValue = getDeclarationValue(decl);
  38. const parsedValue = valueParser(declValue);
  39. parsedValue.walk((valueNode) => {
  40. if (valueNode.type !== 'function') {
  41. return;
  42. }
  43. if (!isStandardSyntaxFunction(valueNode)) {
  44. return;
  45. }
  46. // Ignore function without parameters
  47. if (!valueNode.nodes.length) {
  48. return;
  49. }
  50. const functionString = valueParser.stringify(valueNode);
  51. const isSingleLine = isSingleLineString(functionString);
  52. // Check opening ...
  53. const openingIndex = valueNode.sourceIndex + valueNode.value.length + 1;
  54. if (expectation === 'always' && valueNode.before !== ' ') {
  55. if (context.fix) {
  56. hasFixed = true;
  57. valueNode.before = ' ';
  58. } else {
  59. complain(messages.expectedOpening, openingIndex);
  60. }
  61. }
  62. if (expectation === 'never' && valueNode.before !== '') {
  63. if (context.fix) {
  64. hasFixed = true;
  65. valueNode.before = '';
  66. } else {
  67. complain(messages.rejectedOpening, openingIndex);
  68. }
  69. }
  70. if (isSingleLine && expectation === 'always-single-line' && valueNode.before !== ' ') {
  71. if (context.fix) {
  72. hasFixed = true;
  73. valueNode.before = ' ';
  74. } else {
  75. complain(messages.expectedOpeningSingleLine, openingIndex);
  76. }
  77. }
  78. if (isSingleLine && expectation === 'never-single-line' && valueNode.before !== '') {
  79. if (context.fix) {
  80. hasFixed = true;
  81. valueNode.before = '';
  82. } else {
  83. complain(messages.rejectedOpeningSingleLine, openingIndex);
  84. }
  85. }
  86. // Check closing ...
  87. const closingIndex = valueNode.sourceIndex + functionString.length - 2;
  88. if (expectation === 'always' && valueNode.after !== ' ') {
  89. if (context.fix) {
  90. hasFixed = true;
  91. valueNode.after = ' ';
  92. } else {
  93. complain(messages.expectedClosing, closingIndex);
  94. }
  95. }
  96. if (expectation === 'never' && valueNode.after !== '') {
  97. if (context.fix) {
  98. hasFixed = true;
  99. valueNode.after = '';
  100. } else {
  101. complain(messages.rejectedClosing, closingIndex);
  102. }
  103. }
  104. if (isSingleLine && expectation === 'always-single-line' && valueNode.after !== ' ') {
  105. if (context.fix) {
  106. hasFixed = true;
  107. valueNode.after = ' ';
  108. } else {
  109. complain(messages.expectedClosingSingleLine, closingIndex);
  110. }
  111. }
  112. if (isSingleLine && expectation === 'never-single-line' && valueNode.after !== '') {
  113. if (context.fix) {
  114. hasFixed = true;
  115. valueNode.after = '';
  116. } else {
  117. complain(messages.rejectedClosingSingleLine, closingIndex);
  118. }
  119. }
  120. });
  121. if (hasFixed) {
  122. setDeclarationValue(decl, parsedValue.toString());
  123. }
  124. function complain(message, offset) {
  125. report({
  126. ruleName,
  127. result,
  128. message,
  129. node: decl,
  130. index: declarationValueIndex(decl) + offset,
  131. });
  132. }
  133. });
  134. };
  135. }
  136. rule.ruleName = ruleName;
  137. rule.messages = messages;
  138. module.exports = rule;