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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const report = require('../../utils/report');
  5. const ruleMessages = require('../../utils/ruleMessages');
  6. const validateOptions = require('../../utils/validateOptions');
  7. const ruleName = 'selector-max-empty-lines';
  8. const messages = ruleMessages(ruleName, {
  9. expected: (max) => `Expected no more than ${max} empty ${max === 1 ? 'line' : 'lines'}`,
  10. });
  11. function rule(max, options, context) {
  12. const maxAdjacentNewlines = max + 1;
  13. return (root, result) => {
  14. const validOptions = validateOptions(result, ruleName, {
  15. actual: max,
  16. possible: _.isNumber,
  17. });
  18. if (!validOptions) {
  19. return;
  20. }
  21. const violatedCRLFNewLinesRegex = new RegExp(`(?:\r\n){${maxAdjacentNewlines + 1},}`);
  22. const violatedLFNewLinesRegex = new RegExp(`\n{${maxAdjacentNewlines + 1},}`);
  23. const allowedLFNewLinesString = context.fix ? '\n'.repeat(maxAdjacentNewlines) : '';
  24. const allowedCRLFNewLinesString = context.fix ? '\r\n'.repeat(maxAdjacentNewlines) : '';
  25. root.walkRules((ruleNode) => {
  26. const selector = ruleNode.raws.selector ? ruleNode.raws.selector.raw : ruleNode.selector;
  27. if (context.fix) {
  28. const newSelectorString = selector
  29. .replace(new RegExp(violatedLFNewLinesRegex, 'gm'), allowedLFNewLinesString)
  30. .replace(new RegExp(violatedCRLFNewLinesRegex, 'gm'), allowedCRLFNewLinesString);
  31. if (ruleNode.raws.selector) {
  32. ruleNode.raws.selector.raw = newSelectorString;
  33. } else {
  34. ruleNode.selector = newSelectorString;
  35. }
  36. } else if (
  37. violatedLFNewLinesRegex.test(selector) ||
  38. violatedCRLFNewLinesRegex.test(selector)
  39. ) {
  40. report({
  41. message: messages.expected(max),
  42. node: ruleNode,
  43. index: 0,
  44. result,
  45. ruleName,
  46. });
  47. }
  48. });
  49. };
  50. }
  51. rule.ruleName = ruleName;
  52. rule.messages = messages;
  53. module.exports = rule;