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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @ts-nocheck
  2. 'use strict';
  3. const addEmptyLineAfter = require('../../utils/addEmptyLineAfter');
  4. const blockString = require('../../utils/blockString');
  5. const hasBlock = require('../../utils/hasBlock');
  6. const hasEmptyBlock = require('../../utils/hasEmptyBlock');
  7. const hasEmptyLine = require('../../utils/hasEmptyLine');
  8. const isSingleLineString = require('../../utils/isSingleLineString');
  9. const optionsMatches = require('../../utils/optionsMatches');
  10. const removeEmptyLineAfter = require('../../utils/removeEmptyLinesAfter');
  11. const report = require('../../utils/report');
  12. const ruleMessages = require('../../utils/ruleMessages');
  13. const validateOptions = require('../../utils/validateOptions');
  14. const ruleName = 'block-closing-brace-empty-line-before';
  15. const messages = ruleMessages(ruleName, {
  16. expected: 'Expected empty line before closing brace',
  17. rejected: 'Unexpected empty line before closing brace',
  18. });
  19. function rule(expectation, options, context) {
  20. return (root, result) => {
  21. const validOptions = validateOptions(
  22. result,
  23. ruleName,
  24. {
  25. actual: expectation,
  26. possible: ['always-multi-line', 'never'],
  27. },
  28. {
  29. actual: options,
  30. possible: {
  31. except: ['after-closing-brace'],
  32. },
  33. optional: true,
  34. },
  35. );
  36. if (!validOptions) {
  37. return;
  38. }
  39. // Check both kinds of statements: rules and at-rules
  40. root.walkRules(check);
  41. root.walkAtRules(check);
  42. function check(statement) {
  43. // Return early if blockless or has empty block
  44. if (!hasBlock(statement) || hasEmptyBlock(statement)) {
  45. return;
  46. }
  47. // Get whitespace after ""}", ignoring extra semicolon
  48. const before = (statement.raws.after || '').replace(/;+/, '');
  49. // Calculate index
  50. const statementString = statement.toString();
  51. let index = statementString.length - 1;
  52. if (statementString[index - 1] === '\r') {
  53. index -= 1;
  54. }
  55. // Set expectation
  56. const expectEmptyLineBefore = (() => {
  57. const childNodeTypes = statement.nodes.map((item) => item.type);
  58. // Reverse the primary options if `after-closing-brace` is set
  59. if (
  60. optionsMatches(options, 'except', 'after-closing-brace') &&
  61. statement.type === 'atrule' &&
  62. !childNodeTypes.includes('decl')
  63. ) {
  64. return expectation === 'never';
  65. }
  66. return Boolean(
  67. expectation === 'always-multi-line' && !isSingleLineString(blockString(statement)),
  68. );
  69. })();
  70. // Check for at least one empty line
  71. const hasEmptyLineBefore = hasEmptyLine(before);
  72. // Return if the expectation is met
  73. if (expectEmptyLineBefore === hasEmptyLineBefore) {
  74. return;
  75. }
  76. if (context.fix) {
  77. if (expectEmptyLineBefore) {
  78. addEmptyLineAfter(statement, context.newline);
  79. } else {
  80. removeEmptyLineAfter(statement, context.newline);
  81. }
  82. return;
  83. }
  84. const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
  85. report({
  86. message,
  87. result,
  88. ruleName,
  89. node: statement,
  90. index,
  91. });
  92. }
  93. };
  94. }
  95. rule.ruleName = ruleName;
  96. rule.messages = messages;
  97. module.exports = rule;