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

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