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.

multilineBlocks.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. var _default = (0, _iterateJsdoc.default)(({
  9. context,
  10. jsdoc,
  11. utils
  12. }) => {
  13. const {
  14. allowMultipleTags = true,
  15. noFinalLineText = true,
  16. noZeroLineText = true,
  17. noSingleLineBlocks = false,
  18. singleLineTags = ['lends', 'type'],
  19. noMultilineBlocks = false,
  20. minimumLengthForMultiline = Number.POSITIVE_INFINITY,
  21. multilineTags = ['*']
  22. } = context.options[0] || {};
  23. const {
  24. source: [{
  25. tokens
  26. }]
  27. } = jsdoc;
  28. const {
  29. description,
  30. tag
  31. } = tokens;
  32. const sourceLength = jsdoc.source.length;
  33. const isInvalidSingleLine = tagName => {
  34. return noSingleLineBlocks && (!tagName || !singleLineTags.includes(tagName) && !singleLineTags.includes('*'));
  35. };
  36. if (sourceLength === 1) {
  37. if (!isInvalidSingleLine(tag.slice(1))) {
  38. return;
  39. }
  40. const fixer = () => {
  41. utils.makeMultiline();
  42. };
  43. utils.reportJSDoc('Single line blocks are not permitted by your configuration.', null, fixer, true);
  44. return;
  45. }
  46. const lineChecks = () => {
  47. if (noZeroLineText && (tag || description)) {
  48. const fixer = () => {
  49. const line = { ...tokens
  50. };
  51. utils.emptyTokens(tokens);
  52. const {
  53. tokens: {
  54. delimiter,
  55. start
  56. }
  57. } = jsdoc.source[1];
  58. utils.addLine(1, { ...line,
  59. delimiter,
  60. start
  61. });
  62. };
  63. utils.reportJSDoc('Should have no text on the "0th" line (after the `/**`).', null, fixer);
  64. return;
  65. }
  66. const finalLine = jsdoc.source[jsdoc.source.length - 1];
  67. const finalLineTokens = finalLine.tokens;
  68. if (noFinalLineText && finalLineTokens.description.trim()) {
  69. const fixer = () => {
  70. const line = { ...finalLineTokens
  71. };
  72. line.description = line.description.trimEnd();
  73. const {
  74. delimiter
  75. } = line;
  76. ['delimiter', 'postDelimiter', 'tag', 'type', 'lineEnd', 'postType', 'postTag', 'name', 'postName', 'description'].forEach(prop => {
  77. finalLineTokens[prop] = '';
  78. });
  79. utils.addLine(jsdoc.source.length - 1, { ...line,
  80. delimiter,
  81. end: ''
  82. });
  83. };
  84. utils.reportJSDoc('Should have no text on the final line (before the `*/`).', null, fixer);
  85. }
  86. };
  87. if (noMultilineBlocks) {
  88. if (jsdoc.tags.length && (multilineTags.includes('*') || utils.hasATag(multilineTags))) {
  89. lineChecks();
  90. return;
  91. }
  92. if (jsdoc.description.length >= minimumLengthForMultiline) {
  93. lineChecks();
  94. return;
  95. }
  96. if (noSingleLineBlocks && (!jsdoc.tags.length || !utils.filterTags(({
  97. tag: tg
  98. }) => {
  99. return !isInvalidSingleLine(tg);
  100. }).length)) {
  101. utils.reportJSDoc('Multiline jsdoc blocks are prohibited by ' + 'your configuration but fixing would result in a single ' + 'line block which you have prohibited with `noSingleLineBlocks`.');
  102. return;
  103. }
  104. if (jsdoc.tags.length > 1) {
  105. if (!allowMultipleTags) {
  106. utils.reportJSDoc('Multiline jsdoc blocks are prohibited by ' + 'your configuration but the block has multiple tags.');
  107. return;
  108. }
  109. } else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {
  110. if (!allowMultipleTags) {
  111. utils.reportJSDoc('Multiline jsdoc blocks are prohibited by ' + 'your configuration but the block has a description with a tag.');
  112. return;
  113. }
  114. } else {
  115. const fixer = () => {
  116. jsdoc.source = [{
  117. number: 1,
  118. source: '',
  119. tokens: jsdoc.source.reduce((obj, {
  120. tokens: {
  121. description: desc,
  122. tag: tg,
  123. type: typ,
  124. name: nme,
  125. lineEnd,
  126. postType,
  127. postName,
  128. postTag
  129. }
  130. }) => {
  131. if (typ) {
  132. obj.type = typ;
  133. }
  134. if (tg && typ && nme) {
  135. obj.postType = postType;
  136. }
  137. if (nme) {
  138. obj.name += nme;
  139. }
  140. if (nme && desc) {
  141. obj.postName = postName;
  142. }
  143. obj.description += desc;
  144. const nameOrDescription = obj.description || obj.name;
  145. if (nameOrDescription && nameOrDescription.slice(-1) !== ' ') {
  146. obj.description += ' ';
  147. }
  148. obj.lineEnd = lineEnd; // Already filtered for multiple tags
  149. obj.tag += tg;
  150. if (tg) {
  151. obj.postTag = postTag || ' ';
  152. }
  153. return obj;
  154. }, utils.seedTokens({
  155. delimiter: '/**',
  156. end: '*/',
  157. postDelimiter: ' '
  158. }))
  159. }];
  160. };
  161. utils.reportJSDoc('Multiline jsdoc blocks are prohibited by ' + 'your configuration.', null, fixer);
  162. return;
  163. }
  164. }
  165. lineChecks();
  166. }, {
  167. iterateAllJsdocs: true,
  168. meta: {
  169. docs: {
  170. description: 'Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.',
  171. url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-multiline-blocks'
  172. },
  173. fixable: 'code',
  174. schema: [{
  175. additionalProperies: false,
  176. properties: {
  177. allowMultipleTags: {
  178. type: 'boolean'
  179. },
  180. minimumLengthForMultiline: {
  181. type: 'integer'
  182. },
  183. multilineTags: {
  184. anyOf: [{
  185. enum: ['*'],
  186. type: 'string'
  187. }, {
  188. items: {
  189. type: 'string'
  190. },
  191. type: 'array'
  192. }]
  193. },
  194. noFinalLineText: {
  195. type: 'boolean'
  196. },
  197. noMultilineBlocks: {
  198. type: 'boolean'
  199. },
  200. noSingleLineBlocks: {
  201. type: 'boolean'
  202. },
  203. noZeroLineText: {
  204. type: 'boolean'
  205. },
  206. singleLineTags: {
  207. items: {
  208. type: 'string'
  209. },
  210. type: 'array'
  211. }
  212. },
  213. type: 'object'
  214. }],
  215. type: 'suggestion'
  216. }
  217. });
  218. exports.default = _default;
  219. module.exports = exports.default;
  220. //# sourceMappingURL=multilineBlocks.js.map