1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | var assign = require("object-assign");
|
9 |
|
10 | module.exports = function(context) {
|
11 | var source = context.getSourceCode();
|
12 | var DEFAULT_OPTIONS = {
|
13 | "FunctionDeclaration": true,
|
14 | "MethodDefinition": false,
|
15 | "ClassDeclaration": false
|
16 | };
|
17 | var options = assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});
|
18 |
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | function report(node) {
|
25 | context.report(node, "Missing JSDoc comment.");
|
26 | }
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 | function checkClassMethodJsDoc(node) {
|
34 | if (node.parent.type === "MethodDefinition") {
|
35 | var jsdocComment = source.getJSDocComment(node);
|
36 |
|
37 | if (!jsdocComment) {
|
38 | report(node);
|
39 | }
|
40 | }
|
41 | }
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | function checkJsDoc(node) {
|
49 | var jsdocComment = source.getJSDocComment(node);
|
50 |
|
51 | if (!jsdocComment) {
|
52 | report(node);
|
53 | }
|
54 | }
|
55 |
|
56 | return {
|
57 | "FunctionDeclaration": function(node) {
|
58 | if (options.FunctionDeclaration) {
|
59 | checkJsDoc(node);
|
60 | }
|
61 | },
|
62 | "FunctionExpression": function(node) {
|
63 | if (options.MethodDefinition) {
|
64 | checkClassMethodJsDoc(node);
|
65 | }
|
66 | },
|
67 | "ClassDeclaration": function(node) {
|
68 | if (options.ClassDeclaration) {
|
69 | checkJsDoc(node);
|
70 | }
|
71 | }
|
72 | };
|
73 | };
|
74 |
|
75 | module.exports.schema = [
|
76 | {
|
77 | "type": "object",
|
78 | "properties": {
|
79 | "require": {
|
80 | "type": "object",
|
81 | "properties": {
|
82 | "ClassDeclaration": {
|
83 | "type": "boolean"
|
84 | },
|
85 | "MethodDefinition": {
|
86 | "type": "boolean"
|
87 | },
|
88 | "FunctionDeclaration": {
|
89 | "type": "boolean"
|
90 | }
|
91 | },
|
92 | "additionalProperties": false
|
93 | }
|
94 | },
|
95 | "additionalProperties": false
|
96 | }
|
97 | ];
|