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.

requireJsdoc.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _jsdoccomment = require("@es-joy/jsdoccomment");
  7. var _lodash = _interopRequireDefault(require("lodash"));
  8. var _exportParser = _interopRequireDefault(require("../exportParser"));
  9. var _iterateJsdoc = require("../iterateJsdoc");
  10. var _jsdocUtils = _interopRequireDefault(require("../jsdocUtils"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. const OPTIONS_SCHEMA = {
  13. additionalProperties: false,
  14. properties: {
  15. checkConstructors: {
  16. default: true,
  17. type: 'boolean'
  18. },
  19. checkGetters: {
  20. anyOf: [{
  21. type: 'boolean'
  22. }, {
  23. enum: ['no-setter'],
  24. type: 'string'
  25. }],
  26. default: true
  27. },
  28. checkSetters: {
  29. anyOf: [{
  30. type: 'boolean'
  31. }, {
  32. enum: ['no-getter'],
  33. type: 'string'
  34. }],
  35. default: true
  36. },
  37. contexts: {
  38. items: {
  39. anyOf: [{
  40. type: 'string'
  41. }, {
  42. additionalProperties: false,
  43. properties: {
  44. context: {
  45. type: 'string'
  46. },
  47. inlineCommentBlock: {
  48. type: 'boolean'
  49. }
  50. },
  51. type: 'object'
  52. }]
  53. },
  54. type: 'array'
  55. },
  56. enableFixer: {
  57. default: true,
  58. type: 'boolean'
  59. },
  60. exemptEmptyConstructors: {
  61. default: false,
  62. type: 'boolean'
  63. },
  64. exemptEmptyFunctions: {
  65. default: false,
  66. type: 'boolean'
  67. },
  68. fixerMessage: {
  69. default: '',
  70. type: 'string'
  71. },
  72. publicOnly: {
  73. oneOf: [{
  74. default: false,
  75. type: 'boolean'
  76. }, {
  77. additionalProperties: false,
  78. default: {},
  79. properties: {
  80. ancestorsOnly: {
  81. type: 'boolean'
  82. },
  83. cjs: {
  84. type: 'boolean'
  85. },
  86. esm: {
  87. type: 'boolean'
  88. },
  89. window: {
  90. type: 'boolean'
  91. }
  92. },
  93. type: 'object'
  94. }]
  95. },
  96. require: {
  97. additionalProperties: false,
  98. default: {},
  99. properties: {
  100. ArrowFunctionExpression: {
  101. default: false,
  102. type: 'boolean'
  103. },
  104. ClassDeclaration: {
  105. default: false,
  106. type: 'boolean'
  107. },
  108. ClassExpression: {
  109. default: false,
  110. type: 'boolean'
  111. },
  112. FunctionDeclaration: {
  113. default: true,
  114. type: 'boolean'
  115. },
  116. FunctionExpression: {
  117. default: false,
  118. type: 'boolean'
  119. },
  120. MethodDefinition: {
  121. default: false,
  122. type: 'boolean'
  123. }
  124. },
  125. type: 'object'
  126. }
  127. },
  128. type: 'object'
  129. };
  130. const getOption = (context, baseObject, option, key) => {
  131. if (!_lodash.default.has(context, `options[0][${option}][${key}]`)) {
  132. return baseObject.properties[key].default;
  133. }
  134. return context.options[0][option][key];
  135. };
  136. const getOptions = context => {
  137. const {
  138. publicOnly,
  139. contexts = [],
  140. exemptEmptyConstructors = true,
  141. exemptEmptyFunctions = false,
  142. enableFixer = true,
  143. fixerMessage = ''
  144. } = context.options[0] || {};
  145. return {
  146. contexts,
  147. enableFixer,
  148. exemptEmptyConstructors,
  149. exemptEmptyFunctions,
  150. fixerMessage,
  151. publicOnly: (baseObj => {
  152. if (!publicOnly) {
  153. return false;
  154. }
  155. const properties = {};
  156. Object.keys(baseObj.properties).forEach(prop => {
  157. const opt = getOption(context, baseObj, 'publicOnly', prop);
  158. properties[prop] = opt;
  159. });
  160. return properties;
  161. })(OPTIONS_SCHEMA.properties.publicOnly.oneOf[1]),
  162. require: (baseObj => {
  163. const properties = {};
  164. Object.keys(baseObj.properties).forEach(prop => {
  165. const opt = getOption(context, baseObj, 'require', prop);
  166. properties[prop] = opt;
  167. });
  168. return properties;
  169. })(OPTIONS_SCHEMA.properties.require)
  170. };
  171. };
  172. var _default = {
  173. create(context) {
  174. const sourceCode = context.getSourceCode();
  175. const settings = (0, _iterateJsdoc.getSettings)(context);
  176. if (!settings) {
  177. return {};
  178. }
  179. const {
  180. require: requireOption,
  181. contexts,
  182. publicOnly,
  183. exemptEmptyFunctions,
  184. exemptEmptyConstructors,
  185. enableFixer,
  186. fixerMessage
  187. } = getOptions(context);
  188. const checkJsDoc = (info, handler, node) => {
  189. const jsDocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
  190. if (jsDocNode) {
  191. return;
  192. } // For those who have options configured against ANY constructors (or
  193. // setters or getters) being reported
  194. if (_jsdocUtils.default.exemptSpeciaMethods({
  195. tags: []
  196. }, node, context, [OPTIONS_SCHEMA])) {
  197. return;
  198. }
  199. if ( // Avoid reporting param-less, return-less functions (when
  200. // `exemptEmptyFunctions` option is set)
  201. exemptEmptyFunctions && info.isFunctionContext || // Avoid reporting param-less, return-less constructor methods (when
  202. // `exemptEmptyConstructors` option is set)
  203. exemptEmptyConstructors && _jsdocUtils.default.isConstructor(node)) {
  204. const functionParameterNames = _jsdocUtils.default.getFunctionParameterNames(node);
  205. if (!functionParameterNames.length && !_jsdocUtils.default.hasReturnValue(node)) {
  206. return;
  207. }
  208. }
  209. const fix = fixer => {
  210. // Default to one line break if the `minLines`/`maxLines` settings allow
  211. const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
  212. let baseNode = (0, _jsdoccomment.getReducedASTNode)(node, sourceCode);
  213. const decorator = (0, _jsdoccomment.getDecorator)(baseNode);
  214. if (decorator) {
  215. baseNode = decorator;
  216. }
  217. const indent = _jsdocUtils.default.getIndent({
  218. text: sourceCode.getText(baseNode, baseNode.loc.start.column)
  219. });
  220. const {
  221. inlineCommentBlock
  222. } = contexts.find(({
  223. context: ctxt
  224. }) => {
  225. return ctxt === node.type;
  226. }) || {};
  227. const insertion = (inlineCommentBlock ? `/** ${fixerMessage}` : `/**\n${indent}*${fixerMessage}\n${indent}`) + `*/${'\n'.repeat(lines)}${indent.slice(0, -1)}`;
  228. return fixer.insertTextBefore(baseNode, insertion);
  229. };
  230. const report = () => {
  231. const loc = {
  232. end: node.loc.start + 1,
  233. start: node.loc.start
  234. };
  235. context.report({
  236. fix: enableFixer ? fix : null,
  237. loc,
  238. messageId: 'missingJsDoc',
  239. node
  240. });
  241. };
  242. if (publicOnly) {
  243. var _publicOnly$ancestors, _publicOnly$esm, _publicOnly$cjs, _publicOnly$window;
  244. const opt = {
  245. ancestorsOnly: Boolean((_publicOnly$ancestors = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.ancestorsOnly) !== null && _publicOnly$ancestors !== void 0 ? _publicOnly$ancestors : false),
  246. esm: Boolean((_publicOnly$esm = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.esm) !== null && _publicOnly$esm !== void 0 ? _publicOnly$esm : true),
  247. initModuleExports: Boolean((_publicOnly$cjs = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.cjs) !== null && _publicOnly$cjs !== void 0 ? _publicOnly$cjs : true),
  248. initWindow: Boolean((_publicOnly$window = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.window) !== null && _publicOnly$window !== void 0 ? _publicOnly$window : false)
  249. };
  250. const exported = _exportParser.default.isUncommentedExport(node, sourceCode, opt, settings);
  251. if (exported) {
  252. report();
  253. }
  254. } else {
  255. report();
  256. }
  257. };
  258. const hasOption = prop => {
  259. return requireOption[prop] || contexts.some(ctxt => {
  260. return typeof ctxt === 'object' ? ctxt.context === prop : ctxt === prop;
  261. });
  262. };
  263. return { ..._jsdocUtils.default.getContextObject(_jsdocUtils.default.enforcedContexts(context, []), checkJsDoc),
  264. ArrowFunctionExpression(node) {
  265. if (!hasOption('ArrowFunctionExpression')) {
  266. return;
  267. }
  268. if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value) {
  269. checkJsDoc({
  270. isFunctionContext: true
  271. }, null, node);
  272. }
  273. },
  274. ClassDeclaration(node) {
  275. if (!hasOption('ClassDeclaration')) {
  276. return;
  277. }
  278. checkJsDoc({
  279. isFunctionContext: false
  280. }, null, node);
  281. },
  282. ClassExpression(node) {
  283. if (!hasOption('ClassExpression')) {
  284. return;
  285. }
  286. checkJsDoc({
  287. isFunctionContext: false
  288. }, null, node);
  289. },
  290. FunctionDeclaration(node) {
  291. if (!hasOption('FunctionDeclaration')) {
  292. return;
  293. }
  294. checkJsDoc({
  295. isFunctionContext: true
  296. }, null, node);
  297. },
  298. FunctionExpression(node) {
  299. if (hasOption('MethodDefinition') && node.parent.type === 'MethodDefinition') {
  300. checkJsDoc({
  301. isFunctionContext: true
  302. }, null, node);
  303. return;
  304. }
  305. if (!hasOption('FunctionExpression')) {
  306. return;
  307. }
  308. if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value) {
  309. checkJsDoc({
  310. isFunctionContext: true
  311. }, null, node);
  312. }
  313. }
  314. };
  315. },
  316. meta: {
  317. docs: {
  318. category: 'Stylistic Issues',
  319. description: 'Require JSDoc comments',
  320. recommended: 'true',
  321. url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-jsdoc'
  322. },
  323. fixable: 'code',
  324. messages: {
  325. missingJsDoc: 'Missing JSDoc comment.'
  326. },
  327. schema: [OPTIONS_SCHEMA],
  328. type: 'suggestion'
  329. }
  330. };
  331. exports.default = _default;
  332. module.exports = exports.default;
  333. //# sourceMappingURL=requireJsdoc.js.map