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.

functionCommaSpaceChecker.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../utils/declarationValueIndex');
  4. const getDeclarationValue = require('../utils/getDeclarationValue');
  5. const isStandardSyntaxFunction = require('../utils/isStandardSyntaxFunction');
  6. const report = require('../utils/report');
  7. const setDeclarationValue = require('../utils/setDeclarationValue');
  8. const valueParser = require('postcss-value-parser');
  9. module.exports = function (opts) {
  10. opts.root.walkDecls((decl) => {
  11. const declValue = getDeclarationValue(decl);
  12. let hasFixed;
  13. const parsedValue = valueParser(declValue);
  14. parsedValue.walk((valueNode) => {
  15. if (valueNode.type !== 'function') {
  16. return;
  17. }
  18. if (!isStandardSyntaxFunction(valueNode)) {
  19. return;
  20. }
  21. // Ignore `url()` arguments, which may contain data URIs or other funky stuff
  22. if (valueNode.value.toLowerCase() === 'url') {
  23. return;
  24. }
  25. const argumentStrings = valueNode.nodes.map((node) => valueParser.stringify(node));
  26. const functionArguments = (() => {
  27. // Remove function name and parens
  28. let result = valueNode.before + argumentStrings.join('') + valueNode.after;
  29. // 1. Remove comments including preceding whitespace (when only succeeded by whitespace)
  30. // 2. Remove all other comments, but leave adjacent whitespace intact
  31. result = result.replace(/( *\/(\*.*\*\/(?!\S)|\/.*)|(\/(\*.*\*\/|\/.*)))/, '');
  32. return result;
  33. })();
  34. /**
  35. * Gets the index of the comma for checking.
  36. * @param {Node} commaNode The comma node
  37. * @param {number} nodeIndex The index of the comma node
  38. * @returns {number} The index of the comma for checking
  39. */
  40. function getCommaCheckIndex(commaNode, nodeIndex) {
  41. let commaBefore =
  42. valueNode.before + argumentStrings.slice(0, nodeIndex).join('') + commaNode.before;
  43. // 1. Remove comments including preceding whitespace (when only succeeded by whitespace)
  44. // 2. Remove all other comments, but leave adjacent whitespace intact
  45. commaBefore = commaBefore.replace(/( *\/(\*.*\*\/(?!\S)|\/.*)|(\/(\*.*\*\/|\/.*)))/, '');
  46. return commaBefore.length;
  47. }
  48. const commaDataList = [];
  49. valueNode.nodes.forEach((node, nodeIndex) => {
  50. if (node.type !== 'div' || node.value !== ',') {
  51. return;
  52. }
  53. const checkIndex = getCommaCheckIndex(node, nodeIndex);
  54. commaDataList.push({
  55. commaNode: node,
  56. checkIndex,
  57. nodeIndex,
  58. });
  59. });
  60. for (const { commaNode, checkIndex, nodeIndex } of commaDataList) {
  61. opts.locationChecker({
  62. source: functionArguments,
  63. index: checkIndex,
  64. err: (message) => {
  65. const index =
  66. declarationValueIndex(decl) + commaNode.sourceIndex + commaNode.before.length;
  67. if (opts.fix && opts.fix(commaNode, nodeIndex, valueNode.nodes)) {
  68. hasFixed = true;
  69. return;
  70. }
  71. report({
  72. index,
  73. message,
  74. node: decl,
  75. result: opts.result,
  76. ruleName: opts.checkedRuleName,
  77. });
  78. },
  79. });
  80. }
  81. });
  82. if (hasFixed) {
  83. setDeclarationValue(decl, parsedValue.toString());
  84. }
  85. });
  86. };