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.

matchDescription.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // If supporting Node >= 10, we could loosen the default to this for the
  9. // initial letter: \\p{Upper}
  10. const matchDescriptionDefault = '^[A-Z`\\d_][\\s\\S]*[.?!`]$';
  11. const stringOrDefault = (value, userDefault) => {
  12. return typeof value === 'string' ? value : userDefault || matchDescriptionDefault;
  13. };
  14. var _default = (0, _iterateJsdoc.default)(({
  15. jsdoc,
  16. report,
  17. context,
  18. utils
  19. }) => {
  20. const {
  21. mainDescription,
  22. matchDescription,
  23. message,
  24. tags
  25. } = context.options[0] || {};
  26. const validateDescription = (description, tag) => {
  27. let mainDescriptionMatch = mainDescription;
  28. let errorMessage = message;
  29. if (typeof mainDescription === 'object') {
  30. mainDescriptionMatch = mainDescription.match;
  31. errorMessage = mainDescription.message;
  32. }
  33. if (!tag && mainDescriptionMatch === false) {
  34. return;
  35. }
  36. let tagValue = mainDescriptionMatch;
  37. if (tag) {
  38. const tagName = tag.tag;
  39. if (typeof tags[tagName] === 'object') {
  40. tagValue = tags[tagName].match;
  41. errorMessage = tags[tagName].message;
  42. } else {
  43. tagValue = tags[tagName];
  44. }
  45. }
  46. const regex = utils.getRegexFromString(stringOrDefault(tagValue, matchDescription));
  47. if (!regex.test(description)) {
  48. report(errorMessage || 'JSDoc description does not satisfy the regex pattern.', null, tag || {
  49. // Add one as description would typically be into block
  50. line: jsdoc.source[0].number + 1
  51. });
  52. }
  53. };
  54. if (jsdoc.description) {
  55. const {
  56. description
  57. } = utils.getDescription();
  58. validateDescription(description.replace(/\s+$/, ''));
  59. }
  60. if (!tags || !Object.keys(tags).length) {
  61. return;
  62. }
  63. const hasOptionTag = tagName => {
  64. return Boolean(tags[tagName]);
  65. };
  66. utils.forEachPreferredTag('description', (matchingJsdocTag, targetTagName) => {
  67. const description = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();
  68. if (hasOptionTag(targetTagName)) {
  69. validateDescription(description, matchingJsdocTag);
  70. }
  71. }, true);
  72. const whitelistedTags = utils.filterTags(({
  73. tag: tagName
  74. }) => {
  75. return hasOptionTag(tagName);
  76. });
  77. const {
  78. tagsWithNames,
  79. tagsWithoutNames
  80. } = utils.getTagsByType(whitelistedTags);
  81. tagsWithNames.some(tag => {
  82. const description = utils.getTagDescription(tag).replace(/^[- ]*/u, '').trim();
  83. return validateDescription(description, tag);
  84. });
  85. tagsWithoutNames.some(tag => {
  86. const description = (tag.name + ' ' + utils.getTagDescription(tag)).trim();
  87. return validateDescription(description, tag);
  88. });
  89. }, {
  90. contextDefaults: true,
  91. meta: {
  92. docs: {
  93. description: 'Enforces a regular expression pattern on descriptions.',
  94. url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-match-description'
  95. },
  96. schema: [{
  97. additionalProperties: false,
  98. properties: {
  99. contexts: {
  100. items: {
  101. anyOf: [{
  102. type: 'string'
  103. }, {
  104. additionalProperties: false,
  105. properties: {
  106. comment: {
  107. type: 'string'
  108. },
  109. context: {
  110. type: 'string'
  111. }
  112. },
  113. type: 'object'
  114. }]
  115. },
  116. type: 'array'
  117. },
  118. mainDescription: {
  119. oneOf: [{
  120. format: 'regex',
  121. type: 'string'
  122. }, {
  123. type: 'boolean'
  124. }, {
  125. additionalProperties: false,
  126. properties: {
  127. match: {
  128. oneOf: [{
  129. format: 'regex',
  130. type: 'string'
  131. }, {
  132. type: 'boolean'
  133. }]
  134. },
  135. message: {
  136. type: 'string'
  137. }
  138. },
  139. type: 'object'
  140. }]
  141. },
  142. matchDescription: {
  143. format: 'regex',
  144. type: 'string'
  145. },
  146. message: {
  147. type: 'string'
  148. },
  149. tags: {
  150. patternProperties: {
  151. '.*': {
  152. oneOf: [{
  153. format: 'regex',
  154. type: 'string'
  155. }, {
  156. enum: [true],
  157. type: 'boolean'
  158. }, {
  159. additionalProperties: false,
  160. properties: {
  161. match: {
  162. oneOf: [{
  163. format: 'regex',
  164. type: 'string'
  165. }, {
  166. enum: [true],
  167. type: 'boolean'
  168. }]
  169. },
  170. message: {
  171. type: 'string'
  172. }
  173. },
  174. type: 'object'
  175. }]
  176. }
  177. },
  178. type: 'object'
  179. }
  180. },
  181. type: 'object'
  182. }],
  183. type: 'suggestion'
  184. }
  185. });
  186. exports.default = _default;
  187. module.exports = exports.default;
  188. //# sourceMappingURL=matchDescription.js.map