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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // @ts-nocheck
  2. 'use strict';
  3. const beforeBlockString = require('../../utils/beforeBlockString');
  4. const blockString = require('../../utils/blockString');
  5. const hasBlock = require('../../utils/hasBlock');
  6. const hasEmptyBlock = require('../../utils/hasEmptyBlock');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const whitespaceChecker = require('../../utils/whitespaceChecker');
  11. const ruleName = 'block-opening-brace-newline-before';
  12. const messages = ruleMessages(ruleName, {
  13. expectedBefore: () => 'Expected newline before "{"',
  14. expectedBeforeSingleLine: () => 'Expected newline before "{" of a single-line block',
  15. rejectedBeforeSingleLine: () => 'Unexpected whitespace before "{" of a single-line block',
  16. expectedBeforeMultiLine: () => 'Expected newline before "{" of a multi-line block',
  17. rejectedBeforeMultiLine: () => 'Unexpected whitespace before "{" of a multi-line block',
  18. });
  19. function rule(expectation, options, context) {
  20. const checker = whitespaceChecker('newline', expectation, messages);
  21. return (root, result) => {
  22. const validOptions = validateOptions(result, ruleName, {
  23. actual: expectation,
  24. possible: [
  25. 'always',
  26. 'always-single-line',
  27. 'never-single-line',
  28. 'always-multi-line',
  29. 'never-multi-line',
  30. ],
  31. });
  32. if (!validOptions) {
  33. return;
  34. }
  35. // Check both kinds of statement: rules and at-rules
  36. root.walkRules(check);
  37. root.walkAtRules(check);
  38. function check(statement) {
  39. // Return early if blockless or has an empty block
  40. if (!hasBlock(statement) || hasEmptyBlock(statement)) {
  41. return;
  42. }
  43. const source = beforeBlockString(statement);
  44. const beforeBraceNoRaw = beforeBlockString(statement, {
  45. noRawBefore: true,
  46. });
  47. let index = beforeBraceNoRaw.length - 1;
  48. if (beforeBraceNoRaw[index - 1] === '\r') {
  49. index -= 1;
  50. }
  51. checker.beforeAllowingIndentation({
  52. lineCheckStr: blockString(statement),
  53. source,
  54. index: source.length,
  55. err: (m) => {
  56. if (context.fix) {
  57. if (expectation.startsWith('always')) {
  58. const spaceIndex = statement.raws.between.search(/\s+$/);
  59. if (spaceIndex >= 0) {
  60. statement.raws.between =
  61. statement.raws.between.slice(0, spaceIndex) +
  62. context.newline +
  63. statement.raws.between.slice(spaceIndex);
  64. } else {
  65. statement.raws.between += context.newline;
  66. }
  67. return;
  68. }
  69. if (expectation.startsWith('never')) {
  70. statement.raws.between = statement.raws.between.replace(/\s*$/, '');
  71. return;
  72. }
  73. }
  74. report({
  75. message: m,
  76. node: statement,
  77. index,
  78. result,
  79. ruleName,
  80. });
  81. },
  82. });
  83. }
  84. };
  85. }
  86. rule.ruleName = ruleName;
  87. rule.messages = messages;
  88. module.exports = rule;