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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @ts-nocheck
  2. 'use strict';
  3. const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
  4. const blockString = require('../../utils/blockString');
  5. const hasEmptyLine = require('../../utils/hasEmptyLine');
  6. const isAfterComment = require('../../utils/isAfterComment');
  7. const isAfterStandardPropertyDeclaration = require('../../utils/isAfterStandardPropertyDeclaration');
  8. const isCustomProperty = require('../../utils/isCustomProperty');
  9. const isFirstNested = require('../../utils/isFirstNested');
  10. const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
  11. const isSingleLineString = require('../../utils/isSingleLineString');
  12. const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
  13. const optionsMatches = require('../../utils/optionsMatches');
  14. const removeEmptyLinesBefore = require('../../utils/removeEmptyLinesBefore');
  15. const report = require('../../utils/report');
  16. const ruleMessages = require('../../utils/ruleMessages');
  17. const validateOptions = require('../../utils/validateOptions');
  18. const ruleName = 'declaration-empty-line-before';
  19. const messages = ruleMessages(ruleName, {
  20. expected: 'Expected empty line before declaration',
  21. rejected: 'Unexpected empty line before declaration',
  22. });
  23. function rule(expectation, options, context) {
  24. return (root, result) => {
  25. const validOptions = validateOptions(
  26. result,
  27. ruleName,
  28. {
  29. actual: expectation,
  30. possible: ['always', 'never'],
  31. },
  32. {
  33. actual: options,
  34. possible: {
  35. except: ['first-nested', 'after-comment', 'after-declaration'],
  36. ignore: [
  37. 'after-comment',
  38. 'after-declaration',
  39. 'first-nested',
  40. 'inside-single-line-block',
  41. ],
  42. },
  43. optional: true,
  44. },
  45. );
  46. if (!validOptions) {
  47. return;
  48. }
  49. root.walkDecls((decl) => {
  50. const prop = decl.prop;
  51. const parent = decl.parent;
  52. // Ignore the first node
  53. if (isFirstNodeOfRoot(decl)) {
  54. return;
  55. }
  56. if (!isStandardSyntaxDeclaration(decl)) {
  57. return;
  58. }
  59. if (isCustomProperty(prop)) {
  60. return;
  61. }
  62. // Optionally ignore the node if a comment precedes it
  63. if (optionsMatches(options, 'ignore', 'after-comment') && isAfterComment(decl)) {
  64. return;
  65. }
  66. // Optionally ignore the node if a declaration precedes it
  67. if (
  68. optionsMatches(options, 'ignore', 'after-declaration') &&
  69. isAfterStandardPropertyDeclaration(decl)
  70. ) {
  71. return;
  72. }
  73. // Optionally ignore the node if it is the first nested
  74. if (optionsMatches(options, 'ignore', 'first-nested') && isFirstNested(decl)) {
  75. return;
  76. }
  77. // Optionally ignore nodes inside single-line blocks
  78. if (
  79. optionsMatches(options, 'ignore', 'inside-single-line-block') &&
  80. isSingleLineString(blockString(parent))
  81. ) {
  82. return;
  83. }
  84. let expectEmptyLineBefore = expectation === 'always';
  85. // Optionally reverse the expectation if any exceptions apply
  86. if (
  87. (optionsMatches(options, 'except', 'first-nested') && isFirstNested(decl)) ||
  88. (optionsMatches(options, 'except', 'after-comment') && isAfterComment(decl)) ||
  89. (optionsMatches(options, 'except', 'after-declaration') &&
  90. isAfterStandardPropertyDeclaration(decl))
  91. ) {
  92. expectEmptyLineBefore = !expectEmptyLineBefore;
  93. }
  94. // Check for at least one empty line
  95. const hasEmptyLineBefore = hasEmptyLine(decl.raws.before);
  96. // Return if the expectation is met
  97. if (expectEmptyLineBefore === hasEmptyLineBefore) {
  98. return;
  99. }
  100. // Fix
  101. if (context.fix) {
  102. if (expectEmptyLineBefore) {
  103. addEmptyLineBefore(decl, context.newline);
  104. } else {
  105. removeEmptyLinesBefore(decl, context.newline);
  106. }
  107. return;
  108. }
  109. const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
  110. report({ message, node: decl, result, ruleName });
  111. });
  112. };
  113. }
  114. rule.ruleName = ruleName;
  115. rule.messages = messages;
  116. module.exports = rule;