Ohm-Management - Projektarbeit B-ME
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.

require-jsdoc.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @fileoverview Rule to check for jsdoc presence.
  3. * @author Gyandeep Singh
  4. */
  5. "use strict";
  6. module.exports = {
  7. meta: {
  8. type: "suggestion",
  9. docs: {
  10. description: "require JSDoc comments",
  11. category: "Stylistic Issues",
  12. recommended: false,
  13. url: "https://eslint.org/docs/rules/require-jsdoc"
  14. },
  15. schema: [
  16. {
  17. type: "object",
  18. properties: {
  19. require: {
  20. type: "object",
  21. properties: {
  22. ClassDeclaration: {
  23. type: "boolean"
  24. },
  25. MethodDefinition: {
  26. type: "boolean"
  27. },
  28. FunctionDeclaration: {
  29. type: "boolean"
  30. },
  31. ArrowFunctionExpression: {
  32. type: "boolean"
  33. },
  34. FunctionExpression: {
  35. type: "boolean"
  36. }
  37. },
  38. additionalProperties: false
  39. }
  40. },
  41. additionalProperties: false
  42. }
  43. ]
  44. },
  45. create(context) {
  46. const source = context.getSourceCode();
  47. const DEFAULT_OPTIONS = {
  48. FunctionDeclaration: true,
  49. MethodDefinition: false,
  50. ClassDeclaration: false,
  51. ArrowFunctionExpression: false,
  52. FunctionExpression: false
  53. };
  54. const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});
  55. /**
  56. * Report the error message
  57. * @param {ASTNode} node node to report
  58. * @returns {void}
  59. */
  60. function report(node) {
  61. context.report({ node, message: "Missing JSDoc comment." });
  62. }
  63. /**
  64. * Check if the jsdoc comment is present or not.
  65. * @param {ASTNode} node node to examine
  66. * @returns {void}
  67. */
  68. function checkJsDoc(node) {
  69. const jsdocComment = source.getJSDocComment(node);
  70. if (!jsdocComment) {
  71. report(node);
  72. }
  73. }
  74. return {
  75. FunctionDeclaration(node) {
  76. if (options.FunctionDeclaration) {
  77. checkJsDoc(node);
  78. }
  79. },
  80. FunctionExpression(node) {
  81. if (
  82. (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
  83. (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
  84. ) {
  85. checkJsDoc(node);
  86. }
  87. },
  88. ClassDeclaration(node) {
  89. if (options.ClassDeclaration) {
  90. checkJsDoc(node);
  91. }
  92. },
  93. ArrowFunctionExpression(node) {
  94. if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {
  95. checkJsDoc(node);
  96. }
  97. }
  98. };
  99. }
  100. };