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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
  5. const hasEmptyLine = require('../../utils/hasEmptyLine');
  6. const isAfterComment = require('../../utils/isAfterComment');
  7. const isFirstNested = require('../../utils/isFirstNested');
  8. const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
  9. const isSharedLineComment = require('../../utils/isSharedLineComment');
  10. const optionsMatches = require('../../utils/optionsMatches');
  11. const removeEmptyLinesBefore = require('../../utils/removeEmptyLinesBefore');
  12. const report = require('../../utils/report');
  13. const ruleMessages = require('../../utils/ruleMessages');
  14. const validateOptions = require('../../utils/validateOptions');
  15. const ruleName = 'comment-empty-line-before';
  16. const messages = ruleMessages(ruleName, {
  17. expected: 'Expected empty line before comment',
  18. rejected: 'Unexpected empty line before comment',
  19. });
  20. const stylelintCommandPrefix = 'stylelint-';
  21. function rule(expectation, options, context) {
  22. return (root, result) => {
  23. const validOptions = validateOptions(
  24. result,
  25. ruleName,
  26. {
  27. actual: expectation,
  28. possible: ['always', 'never'],
  29. },
  30. {
  31. actual: options,
  32. possible: {
  33. except: ['first-nested'],
  34. ignore: ['stylelint-commands', 'after-comment'],
  35. ignoreComments: [_.isString, _.isRegExp],
  36. },
  37. optional: true,
  38. },
  39. );
  40. if (!validOptions) {
  41. return;
  42. }
  43. root.walkComments((comment) => {
  44. // Ignore the first node
  45. if (isFirstNodeOfRoot(comment)) {
  46. return;
  47. }
  48. // Optionally ignore stylelint commands
  49. if (
  50. comment.text.startsWith(stylelintCommandPrefix) &&
  51. optionsMatches(options, 'ignore', 'stylelint-commands')
  52. ) {
  53. return;
  54. }
  55. // Optionally ignore newlines between comments
  56. if (optionsMatches(options, 'ignore', 'after-comment') && isAfterComment(comment)) {
  57. return;
  58. }
  59. // Ignore comments matching the ignoreComments option.
  60. if (optionsMatches(options, 'ignoreComments', comment.text)) {
  61. return;
  62. }
  63. // Ignore shared-line comments
  64. if (isSharedLineComment(comment)) {
  65. return;
  66. }
  67. // Ignore SCSS comments
  68. if (comment.raws.inline || comment.inline) {
  69. return;
  70. }
  71. const expectEmptyLineBefore = (() => {
  72. if (optionsMatches(options, 'except', 'first-nested') && isFirstNested(comment)) {
  73. return false;
  74. }
  75. return expectation === 'always';
  76. })();
  77. const before = comment.raws.before || '';
  78. const hasEmptyLineBefore = hasEmptyLine(before);
  79. // Return if the expectation is met
  80. if (expectEmptyLineBefore === hasEmptyLineBefore) {
  81. return;
  82. }
  83. // Fix
  84. if (context.fix) {
  85. if (expectEmptyLineBefore) {
  86. addEmptyLineBefore(comment, context.newline);
  87. } else {
  88. removeEmptyLinesBefore(comment, context.newline);
  89. }
  90. return;
  91. }
  92. const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
  93. report({
  94. message,
  95. node: comment,
  96. result,
  97. ruleName,
  98. });
  99. });
  100. };
  101. }
  102. rule.ruleName = ruleName;
  103. rule.messages = messages;
  104. module.exports = rule;