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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const blockString = require('../../utils/blockString');
  5. const hasBlock = require('../../utils/hasBlock');
  6. const optionsMatches = require('../../utils/optionsMatches');
  7. const rawNodeString = require('../../utils/rawNodeString');
  8. const report = require('../../utils/report');
  9. const ruleMessages = require('../../utils/ruleMessages');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const whitespaceChecker = require('../../utils/whitespaceChecker');
  12. const ruleName = 'block-closing-brace-newline-after';
  13. const messages = ruleMessages(ruleName, {
  14. expectedAfter: () => 'Expected newline after "}"',
  15. expectedAfterSingleLine: () => 'Expected newline after "}" of a single-line block',
  16. rejectedAfterSingleLine: () => 'Unexpected whitespace after "}" of a single-line block',
  17. expectedAfterMultiLine: () => 'Expected newline after "}" of a multi-line block',
  18. rejectedAfterMultiLine: () => 'Unexpected whitespace after "}" of a multi-line block',
  19. });
  20. function rule(expectation, options, context) {
  21. const checker = whitespaceChecker('newline', expectation, messages);
  22. return (root, result) => {
  23. const validOptions = validateOptions(
  24. result,
  25. ruleName,
  26. {
  27. actual: expectation,
  28. possible: [
  29. 'always',
  30. 'always-single-line',
  31. 'never-single-line',
  32. 'always-multi-line',
  33. 'never-multi-line',
  34. ],
  35. },
  36. {
  37. actual: options,
  38. possible: {
  39. ignoreAtRules: [_.isString],
  40. },
  41. optional: true,
  42. },
  43. );
  44. if (!validOptions) {
  45. return;
  46. }
  47. // Check both kinds of statements: rules and at-rules
  48. root.walkRules(check);
  49. root.walkAtRules(check);
  50. function check(statement) {
  51. if (!hasBlock(statement)) {
  52. return;
  53. }
  54. if (optionsMatches(options, 'ignoreAtRules', statement.name)) {
  55. return;
  56. }
  57. const nextNode = statement.next();
  58. if (!nextNode) {
  59. return;
  60. }
  61. // Allow an end-of-line comment x spaces after the brace
  62. const nextNodeIsSingleLineComment =
  63. nextNode.type === 'comment' &&
  64. !/[^ ]/.test(nextNode.raws.before || '') &&
  65. !nextNode.toString().includes('\n');
  66. const nodeToCheck = nextNodeIsSingleLineComment ? nextNode.next() : nextNode;
  67. if (!nodeToCheck) {
  68. return;
  69. }
  70. let reportIndex = statement.toString().length;
  71. let source = rawNodeString(nodeToCheck);
  72. // Skip a semicolon at the beginning, if any
  73. if (source && source.startsWith(';')) {
  74. source = source.slice(1);
  75. reportIndex++;
  76. }
  77. // Only check one after, because there might be other
  78. // spaces handled by the indentation rule
  79. checker.afterOneOnly({
  80. source,
  81. index: -1,
  82. lineCheckStr: blockString(statement),
  83. err: (msg) => {
  84. if (context.fix) {
  85. if (expectation.startsWith('always')) {
  86. const index = nodeToCheck.raws.before.search(/\r?\n/);
  87. if (index >= 0) {
  88. nodeToCheck.raws.before = nodeToCheck.raws.before.slice(index);
  89. } else {
  90. nodeToCheck.raws.before = context.newline + nodeToCheck.raws.before;
  91. }
  92. return;
  93. }
  94. if (expectation.startsWith('never')) {
  95. nodeToCheck.raws.before = '';
  96. return;
  97. }
  98. }
  99. report({
  100. message: msg,
  101. node: statement,
  102. index: reportIndex,
  103. result,
  104. ruleName,
  105. });
  106. },
  107. });
  108. }
  109. };
  110. }
  111. rule.ruleName = ruleName;
  112. rule.messages = messages;
  113. module.exports = rule;