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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ruleName = 'value-list-max-empty-lines';
  10. const messages = ruleMessages(ruleName, {
  11. expected: (max) => `Expected no more than ${max} empty ${max === 1 ? 'line' : 'lines'}`,
  12. });
  13. function rule(max, options, context) {
  14. const maxAdjacentNewlines = max + 1;
  15. return (root, result) => {
  16. const validOptions = validateOptions(result, ruleName, {
  17. actual: max,
  18. possible: _.isNumber,
  19. });
  20. if (!validOptions) {
  21. return;
  22. }
  23. const violatedCRLFNewLinesRegex = new RegExp(`(?:\r\n){${maxAdjacentNewlines + 1},}`);
  24. const violatedLFNewLinesRegex = new RegExp(`\n{${maxAdjacentNewlines + 1},}`);
  25. const allowedLFNewLinesString = context.fix ? '\n'.repeat(maxAdjacentNewlines) : '';
  26. const allowedCRLFNewLinesString = context.fix ? '\r\n'.repeat(maxAdjacentNewlines) : '';
  27. root.walkDecls((decl) => {
  28. const value = getDeclarationValue(decl);
  29. if (context.fix) {
  30. const newValueString = value
  31. .replace(new RegExp(violatedLFNewLinesRegex, 'gm'), allowedLFNewLinesString)
  32. .replace(new RegExp(violatedCRLFNewLinesRegex, 'gm'), allowedCRLFNewLinesString);
  33. setDeclarationValue(decl, newValueString);
  34. } else if (violatedLFNewLinesRegex.test(value) || violatedCRLFNewLinesRegex.test(value)) {
  35. report({
  36. message: messages.expected(max),
  37. node: decl,
  38. index: 0,
  39. result,
  40. ruleName,
  41. });
  42. }
  43. });
  44. };
  45. }
  46. rule.ruleName = ruleName;
  47. rule.messages = messages;
  48. module.exports = rule;