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.

checkLineAlignment.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _commentParser = require("comment-parser");
  7. var _alignTransform = _interopRequireDefault(require("../alignTransform"));
  8. var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. const {
  11. flow: commentFlow
  12. } = _commentParser.transforms;
  13. const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
  14. /*
  15. start +
  16. delimiter +
  17. postDelimiter +
  18. tag +
  19. postTag +
  20. type +
  21. postType +
  22. name +
  23. postName +
  24. description +
  25. end +
  26. lineEnd
  27. */
  28. let spacerProps;
  29. let contentProps;
  30. const mightHaveNamepath = utils.tagMightHaveNamepath(tag.tag);
  31. if (mightHaveNamepath) {
  32. spacerProps = ['postDelimiter', 'postTag', 'postType', 'postName'];
  33. contentProps = ['tag', 'type', 'name', 'description'];
  34. } else {
  35. spacerProps = ['postDelimiter', 'postTag', 'postType'];
  36. contentProps = ['tag', 'type', 'description'];
  37. }
  38. const {
  39. tokens
  40. } = tag.source[0];
  41. const followedBySpace = (idx, callbck) => {
  42. const nextIndex = idx + 1;
  43. return spacerProps.slice(nextIndex).some((spacerProp, innerIdx) => {
  44. const contentProp = contentProps[nextIndex + innerIdx];
  45. const spacePropVal = tokens[spacerProp];
  46. const ret = spacePropVal;
  47. if (callbck) {
  48. callbck(!ret, contentProp);
  49. }
  50. return ret && (callbck || !contentProp);
  51. });
  52. }; // If checking alignment on multiple lines, need to check other `source`
  53. // items
  54. // Go through `post*` spacing properties and exit to indicate problem if
  55. // extra spacing detected
  56. const ok = !spacerProps.some((spacerProp, idx) => {
  57. const contentProp = contentProps[idx];
  58. const contentPropVal = tokens[contentProp];
  59. const spacerPropVal = tokens[spacerProp];
  60. const spacing = (customSpacings === null || customSpacings === void 0 ? void 0 : customSpacings[spacerProp]) || 1; // There will be extra alignment if...
  61. // 1. The spaces don't match the space it should have (1 or custom spacing) OR
  62. return spacerPropVal.length !== spacing && spacerPropVal.length !== 0 || // 2. There is a (single) space, no immediate content, and yet another
  63. // space is found subsequently (not separated by intervening content)
  64. spacerPropVal && !contentPropVal && followedBySpace(idx);
  65. });
  66. if (ok) {
  67. return;
  68. }
  69. const fix = () => {
  70. spacerProps.forEach((spacerProp, idx) => {
  71. const contentProp = contentProps[idx];
  72. const contentPropVal = tokens[contentProp];
  73. if (contentPropVal) {
  74. const spacing = (customSpacings === null || customSpacings === void 0 ? void 0 : customSpacings[spacerProp]) || 1;
  75. tokens[spacerProp] = ''.padStart(spacing, ' ');
  76. followedBySpace(idx, (hasSpace, contentPrp) => {
  77. if (hasSpace) {
  78. tokens[contentPrp] = '';
  79. }
  80. });
  81. } else {
  82. tokens[spacerProp] = '';
  83. }
  84. });
  85. utils.setTag(tag, tokens);
  86. };
  87. utils.reportJSDoc('Expected JSDoc block lines to not be aligned.', tag, fix, true);
  88. };
  89. const checkAlignment = ({
  90. customSpacings,
  91. indent,
  92. jsdoc,
  93. jsdocNode,
  94. preserveMainDescriptionPostDelimiter,
  95. report,
  96. tags,
  97. utils
  98. }) => {
  99. const transform = commentFlow((0, _alignTransform.default)({
  100. customSpacings,
  101. indent,
  102. preserveMainDescriptionPostDelimiter,
  103. tags
  104. }));
  105. const transformedJsdoc = transform(jsdoc);
  106. const comment = '/*' + jsdocNode.value + '*/';
  107. const formatted = utils.stringify(transformedJsdoc).trimStart();
  108. if (comment !== formatted) {
  109. report('Expected JSDoc block lines to be aligned.', fixer => {
  110. return fixer.replaceText(jsdocNode, formatted);
  111. });
  112. }
  113. };
  114. var _default = (0, _iterateJsdoc.default)(({
  115. indent,
  116. jsdoc,
  117. jsdocNode,
  118. report,
  119. context,
  120. utils
  121. }) => {
  122. const {
  123. tags: applicableTags = ['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return'],
  124. preserveMainDescriptionPostDelimiter,
  125. customSpacings
  126. } = context.options[1] || {};
  127. if (context.options[0] === 'always') {
  128. // Skip if it contains only a single line.
  129. if (!jsdocNode.value.includes('\n')) {
  130. return;
  131. }
  132. checkAlignment({
  133. customSpacings,
  134. indent,
  135. jsdoc,
  136. jsdocNode,
  137. preserveMainDescriptionPostDelimiter,
  138. report,
  139. tags: applicableTags,
  140. utils
  141. });
  142. return;
  143. }
  144. const foundTags = utils.getPresentTags(applicableTags);
  145. foundTags.forEach(tag => {
  146. checkNotAlignedPerTag(utils, tag, customSpacings);
  147. });
  148. }, {
  149. iterateAllJsdocs: true,
  150. meta: {
  151. docs: {
  152. description: 'Reports invalid alignment of JSDoc block lines.',
  153. url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment'
  154. },
  155. fixable: 'whitespace',
  156. schema: [{
  157. enum: ['always', 'never'],
  158. type: 'string'
  159. }, {
  160. additionalProperties: false,
  161. properties: {
  162. customSpacings: {
  163. additionalProperties: false,
  164. properties: {
  165. postDelimiter: {
  166. type: 'integer'
  167. },
  168. postName: {
  169. type: 'integer'
  170. },
  171. postTag: {
  172. type: 'integer'
  173. },
  174. postType: {
  175. type: 'integer'
  176. }
  177. }
  178. },
  179. preserveMainDescriptionPostDelimiter: {
  180. default: false,
  181. type: 'boolean'
  182. },
  183. tags: {
  184. items: {
  185. type: 'string'
  186. },
  187. type: 'array'
  188. }
  189. },
  190. type: 'object'
  191. }],
  192. type: 'layout'
  193. }
  194. });
  195. exports.default = _default;
  196. module.exports = exports.default;
  197. //# sourceMappingURL=checkLineAlignment.js.map