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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // @ts-nocheck
  2. 'use strict';
  3. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  4. const declarationValueIndex = require('../../utils/declarationValueIndex');
  5. const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
  6. const parseSelector = require('../../utils/parseSelector');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const valueParser = require('postcss-value-parser');
  11. const ruleName = 'string-no-newline';
  12. const reNewLine = /(\r?\n)/;
  13. const messages = ruleMessages(ruleName, {
  14. rejected: 'Unexpected newline in string',
  15. });
  16. function rule(actual) {
  17. return (root, result) => {
  18. const validOptions = validateOptions(result, ruleName, { actual });
  19. if (!validOptions) {
  20. return;
  21. }
  22. root.walk((node) => {
  23. switch (node.type) {
  24. case 'atrule':
  25. checkDeclOrAtRule(node, node.params, atRuleParamIndex);
  26. break;
  27. case 'decl':
  28. checkDeclOrAtRule(node, node.value, declarationValueIndex);
  29. break;
  30. case 'rule':
  31. checkRule(node);
  32. break;
  33. }
  34. });
  35. function checkRule(ruleNode) {
  36. // Get out quickly if there are no new line
  37. if (!reNewLine.test(ruleNode.selector)) {
  38. return;
  39. }
  40. if (!isStandardSyntaxSelector(ruleNode.selector)) {
  41. return;
  42. }
  43. parseSelector(ruleNode.selector, result, ruleNode, (selectorTree) => {
  44. selectorTree.walkAttributes((attributeNode) => {
  45. if (!reNewLine.test(attributeNode.value)) {
  46. return;
  47. }
  48. const openIndex = [
  49. // length of our attribute
  50. attributeNode.attribute,
  51. // length of our operator , ie '='
  52. attributeNode.operator,
  53. // length of the contents before newline
  54. RegExp.leftContext,
  55. ].reduce(
  56. (index, str) => index + str.length,
  57. // index of the start of our attribute node in our source
  58. attributeNode.sourceIndex,
  59. );
  60. report({
  61. message: messages.rejected,
  62. node: ruleNode,
  63. index: openIndex,
  64. result,
  65. ruleName,
  66. });
  67. });
  68. });
  69. }
  70. function checkDeclOrAtRule(node, value, getIndex) {
  71. // Get out quickly if there are no new line
  72. if (!reNewLine.test(value)) {
  73. return;
  74. }
  75. valueParser(value).walk((valueNode) => {
  76. if (valueNode.type !== 'string' || !reNewLine.test(valueNode.value)) {
  77. return;
  78. }
  79. const openIndex = [
  80. // length of the quote
  81. valueNode.quote,
  82. // length of the contents before newline
  83. RegExp.leftContext,
  84. ].reduce((index, str) => index + str.length, valueNode.sourceIndex);
  85. report({
  86. message: messages.rejected,
  87. node,
  88. index: getIndex(node) + openIndex,
  89. result,
  90. ruleName,
  91. });
  92. });
  93. }
  94. };
  95. }
  96. rule.ruleName = ruleName;
  97. rule.messages = messages;
  98. module.exports = rule;