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.

requireYields.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /**
  9. * We can skip checking for a yield value, in case the documentation is inherited
  10. * or the method has a constructor or abstract tag.
  11. *
  12. * In either of these cases the yield value is optional or not defined.
  13. *
  14. * @param {*} utils
  15. * a reference to the utils which are used to probe if a tag is present or not.
  16. * @returns {boolean}
  17. * true in case deep checking can be skipped; otherwise false.
  18. */
  19. const canSkip = utils => {
  20. return utils.hasATag([// inheritdoc implies that all documentation is inherited
  21. // see https://jsdoc.app/tags-inheritdoc.html
  22. //
  23. // Abstract methods are by definition incomplete,
  24. // so it is not an error if it declares a yield value but does not implement it.
  25. 'abstract', 'virtual', // Constructors do not have a yield value
  26. // so we can bail out here, too.
  27. 'class', 'constructor', // Yield (and any `next`) type is specified accompanying the targeted
  28. // @type
  29. 'type', // This seems to imply a class as well
  30. 'interface']) || utils.avoidDocs();
  31. };
  32. const checkTagName = (utils, report, tagName) => {
  33. const preferredTagName = utils.getPreferredTagName({
  34. tagName
  35. });
  36. if (!preferredTagName) {
  37. return [];
  38. }
  39. const tags = utils.getTags(preferredTagName);
  40. if (tags.length > 1) {
  41. report(`Found more than one @${preferredTagName} declaration.`);
  42. } // In case the code yields something, we expect a yields value in JSDoc.
  43. const [tag] = tags;
  44. const missingTag = typeof tag === 'undefined' || tag === null;
  45. return [preferredTagName, missingTag];
  46. };
  47. var _default = (0, _iterateJsdoc.default)(({
  48. report,
  49. utils,
  50. context
  51. }) => {
  52. const {
  53. next = false,
  54. nextWithGeneratorTag = false,
  55. forceRequireNext = false,
  56. forceRequireYields = false,
  57. withGeneratorTag = true
  58. } = context.options[0] || {}; // A preflight check. We do not need to run a deep check
  59. // in case the @yield comment is optional or undefined.
  60. if (canSkip(utils)) {
  61. return;
  62. }
  63. const iteratingFunction = utils.isIteratingFunction();
  64. const [preferredYieldTagName, missingYieldTag] = checkTagName(utils, report, 'yields');
  65. if (preferredYieldTagName) {
  66. const shouldReportYields = () => {
  67. if (!missingYieldTag) {
  68. return false;
  69. }
  70. if (withGeneratorTag && utils.hasTag('generator') || forceRequireYields && iteratingFunction && utils.isGenerator()) {
  71. return true;
  72. }
  73. return iteratingFunction && utils.isGenerator() && utils.hasYieldValue();
  74. };
  75. if (shouldReportYields()) {
  76. report(`Missing JSDoc @${preferredYieldTagName} declaration.`);
  77. }
  78. }
  79. if (next || nextWithGeneratorTag || forceRequireNext) {
  80. const [preferredNextTagName, missingNextTag] = checkTagName(utils, report, 'next');
  81. if (!preferredNextTagName) {
  82. return;
  83. }
  84. const shouldReportNext = () => {
  85. if (!missingNextTag) {
  86. return false;
  87. }
  88. if (nextWithGeneratorTag && utils.hasTag('generator')) {
  89. return true;
  90. }
  91. if (!next && !forceRequireNext || !iteratingFunction || !utils.isGenerator()) {
  92. return false;
  93. }
  94. return forceRequireNext || utils.hasYieldReturnValue();
  95. };
  96. if (shouldReportNext()) {
  97. report(`Missing JSDoc @${preferredNextTagName} declaration.`);
  98. }
  99. }
  100. }, {
  101. contextDefaults: true,
  102. meta: {
  103. docs: {
  104. description: 'Requires yields are documented.',
  105. url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-yields'
  106. },
  107. schema: [{
  108. additionalProperties: false,
  109. properties: {
  110. contexts: {
  111. items: {
  112. anyOf: [{
  113. type: 'string'
  114. }, {
  115. additionalProperties: false,
  116. properties: {
  117. comment: {
  118. type: 'string'
  119. },
  120. context: {
  121. type: 'string'
  122. }
  123. },
  124. type: 'object'
  125. }]
  126. },
  127. type: 'array'
  128. },
  129. exemptedBy: {
  130. items: {
  131. type: 'string'
  132. },
  133. type: 'array'
  134. },
  135. forceRequireNext: {
  136. default: false,
  137. type: 'boolean'
  138. },
  139. forceRequireYields: {
  140. default: false,
  141. type: 'boolean'
  142. },
  143. next: {
  144. default: false,
  145. type: 'boolean'
  146. },
  147. nextWithGeneratorTag: {
  148. default: false,
  149. type: 'boolean'
  150. },
  151. withGeneratorTag: {
  152. default: true,
  153. type: 'boolean'
  154. }
  155. },
  156. type: 'object'
  157. }],
  158. type: 'suggestion'
  159. }
  160. });
  161. exports.default = _default;
  162. module.exports = exports.default;
  163. //# sourceMappingURL=requireYields.js.map