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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const getDeclarationValue = require('../../utils/getDeclarationValue');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const setDeclarationValue = require('../../utils/setDeclarationValue');
  8. const validateOptions = require('../../utils/validateOptions');
  9. const valueParser = require('postcss-value-parser');
  10. const ruleName = 'function-max-empty-lines';
  11. const messages = ruleMessages(ruleName, {
  12. expected: (max) => `Expected no more than ${max} empty ${max === 1 ? 'line' : 'lines'}`,
  13. });
  14. function placeIndexOnValueStart(decl) {
  15. return decl.prop.length + decl.raws.between.length - 1;
  16. }
  17. function rule(max, options, context) {
  18. const maxAdjacentNewlines = max + 1;
  19. return (root, result) => {
  20. const validOptions = validateOptions(result, ruleName, {
  21. actual: max,
  22. possible: _.isNumber,
  23. });
  24. if (!validOptions) {
  25. return;
  26. }
  27. const violatedCRLFNewLinesRegex = new RegExp(`(?:\r\n){${maxAdjacentNewlines + 1},}`);
  28. const violatedLFNewLinesRegex = new RegExp(`\n{${maxAdjacentNewlines + 1},}`);
  29. const allowedLFNewLinesString = context.fix ? '\n'.repeat(maxAdjacentNewlines) : '';
  30. const allowedCRLFNewLinesString = context.fix ? '\r\n'.repeat(maxAdjacentNewlines) : '';
  31. root.walkDecls((decl) => {
  32. if (!decl.value.includes('(')) {
  33. return;
  34. }
  35. const stringValue = getDeclarationValue(decl);
  36. const splittedValue = [];
  37. let sourceIndexStart = 0;
  38. valueParser(stringValue).walk((node) => {
  39. if (
  40. node.type !== 'function' /* ignore non functions */ ||
  41. node.value.length === 0 /* ignore sass lists */
  42. ) {
  43. return;
  44. }
  45. const stringifiedNode = valueParser.stringify(node);
  46. if (
  47. !violatedLFNewLinesRegex.test(stringifiedNode) &&
  48. !violatedCRLFNewLinesRegex.test(stringifiedNode)
  49. ) {
  50. return;
  51. }
  52. if (context.fix) {
  53. const newNodeString = stringifiedNode
  54. .replace(new RegExp(violatedLFNewLinesRegex, 'gm'), allowedLFNewLinesString)
  55. .replace(new RegExp(violatedCRLFNewLinesRegex, 'gm'), allowedCRLFNewLinesString);
  56. splittedValue.push([
  57. stringValue.slice(sourceIndexStart, node.sourceIndex),
  58. newNodeString,
  59. ]);
  60. sourceIndexStart = node.sourceIndex + stringifiedNode.length;
  61. } else {
  62. report({
  63. message: messages.expected(max),
  64. node: decl,
  65. index: placeIndexOnValueStart(decl) + node.sourceIndex,
  66. result,
  67. ruleName,
  68. });
  69. }
  70. });
  71. if (context.fix && splittedValue.length > 0) {
  72. const updatedValue =
  73. splittedValue.reduce((acc, curr) => acc + curr[0] + curr[1], '') +
  74. stringValue.slice(sourceIndexStart);
  75. setDeclarationValue(decl, updatedValue);
  76. }
  77. });
  78. };
  79. }
  80. rule.ruleName = ruleName;
  81. rule.messages = messages;
  82. module.exports = rule;