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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @ts-nocheck
  2. 'use strict';
  3. const blockString = require('../../utils/blockString');
  4. const hasBlock = require('../../utils/hasBlock');
  5. const hasEmptyBlock = require('../../utils/hasEmptyBlock');
  6. const isSingleLineString = require('../../utils/isSingleLineString');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const ruleName = 'block-closing-brace-newline-before';
  11. const messages = ruleMessages(ruleName, {
  12. expectedBefore: 'Expected newline before "}"',
  13. expectedBeforeMultiLine: 'Expected newline before "}" of a multi-line block',
  14. rejectedBeforeMultiLine: 'Unexpected whitespace before "}" of a multi-line block',
  15. });
  16. function rule(expectation, options, context) {
  17. return (root, result) => {
  18. const validOptions = validateOptions(result, ruleName, {
  19. actual: expectation,
  20. possible: ['always', 'always-multi-line', 'never-multi-line'],
  21. });
  22. if (!validOptions) {
  23. return;
  24. }
  25. // Check both kinds of statements: rules and at-rules
  26. root.walkRules(check);
  27. root.walkAtRules(check);
  28. function check(statement) {
  29. // Return early if blockless or has empty block
  30. if (!hasBlock(statement) || hasEmptyBlock(statement)) {
  31. return;
  32. }
  33. // Ignore extra semicolon
  34. const after = (statement.raws.after || '').replace(/;+/, '');
  35. if (after === undefined) {
  36. return;
  37. }
  38. const blockIsMultiLine = !isSingleLineString(blockString(statement));
  39. const statementString = statement.toString();
  40. let index = statementString.length - 2;
  41. if (statementString[index - 1] === '\r') {
  42. index -= 1;
  43. }
  44. // We're really just checking whether a
  45. // newline *starts* the block's final space -- between
  46. // the last declaration and the closing brace. We can
  47. // ignore any other whitespace between them, because that
  48. // will be checked by the indentation rule.
  49. if (!after.startsWith('\n') && !after.startsWith('\r\n')) {
  50. if (expectation === 'always') {
  51. complain(messages.expectedBefore);
  52. } else if (blockIsMultiLine && expectation === 'always-multi-line') {
  53. complain(messages.expectedBeforeMultiLine);
  54. }
  55. }
  56. if (after !== '' && blockIsMultiLine && expectation === 'never-multi-line') {
  57. complain(messages.rejectedBeforeMultiLine);
  58. }
  59. function complain(message) {
  60. if (context.fix) {
  61. if (expectation.startsWith('always')) {
  62. const firstWhitespaceIndex = statement.raws.after.search(/\s/);
  63. const newlineBefore =
  64. firstWhitespaceIndex >= 0
  65. ? statement.raws.after.slice(0, firstWhitespaceIndex)
  66. : statement.raws.after;
  67. const newlineAfter =
  68. firstWhitespaceIndex >= 0 ? statement.raws.after.slice(firstWhitespaceIndex) : '';
  69. const newlineIndex = newlineAfter.search(/\r?\n/);
  70. if (newlineIndex >= 0) {
  71. statement.raws.after = newlineBefore + newlineAfter.slice(newlineIndex);
  72. } else {
  73. statement.raws.after = newlineBefore + context.newline + newlineAfter;
  74. }
  75. return;
  76. }
  77. if (expectation === 'never-multi-line') {
  78. statement.raws.after = statement.raws.after.replace(/\s/g, '');
  79. return;
  80. }
  81. }
  82. report({
  83. message,
  84. result,
  85. ruleName,
  86. node: statement,
  87. index,
  88. });
  89. }
  90. }
  91. };
  92. }
  93. rule.ruleName = ruleName;
  94. rule.messages = messages;
  95. module.exports = rule;