Skip to content

Commit bf19a6c

Browse files
dtracersAlexej Yaroshevich
authored andcommitted
New Rule: requireParamDescription
Fixes #107 Closes gh-111
1 parent 85fba47 commit bf19a6c

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed

lib/rules/validate-jsdoc/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var validatorsByName = module.exports = {
66
checkParamNames: require('./check-param-names'),
77
checkRedundantParams: require('./check-redundant-params'),
88
requireParamTypes: require('./require-param-types'),
9+
requireParamDescription: require('./require-param-description'),
910
requireHyphenBeforeDescription: require('./require-hyphen-before-description'),
1011

1112
checkReturnTypes: require('./check-return-types'),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = validateParamTagDescription;
2+
module.exports.tags = ['param', 'arg', 'argument'];
3+
module.exports.scopes = ['function'];
4+
module.exports.options = {
5+
requireParamDescription: {allowedValues: [true]}
6+
};
7+
8+
/**
9+
* Validator for @param
10+
*
11+
* @param {(FunctionDeclaration|FunctionExpression)} node
12+
* @param {DocTag} tag
13+
* @param {Function} err
14+
*/
15+
function validateParamTagDescription(node, tag, err) {
16+
// checking existance
17+
if (tag.description) {
18+
return;
19+
}
20+
21+
var offset = (tag.name && tag.name.value && tag.name.value.length) || 0;
22+
var loc = (tag.name ? tag.name.loc : null) || tag.loc;
23+
24+
return err('Missing param description', {
25+
line: loc.line,
26+
column: loc.column + offset
27+
});
28+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
describe('lib/rules/validate-jsdoc/require-param-description', function () {
2+
var checker = global.checker({
3+
plugins: ['./lib/index']
4+
});
5+
6+
describe('not configured', function() {
7+
8+
it('should report with undefined', function() {
9+
global.expect(function() {
10+
checker.configure({requireParamDescription: undefined});
11+
}).to.throws(/accepted value/i);
12+
});
13+
14+
it('should report with an object', function() {
15+
global.expect(function() {
16+
checker.configure({requireParamDescription: {}});
17+
}).to.throws(/accepted value/i);
18+
});
19+
20+
});
21+
22+
describe('with true', function() {
23+
checker.rules({requireParamDescription: true});
24+
25+
checker.cases([
26+
/* jshint ignore:start */
27+
{
28+
it: 'should not report',
29+
code: function() {
30+
function yay(yey) {
31+
}
32+
}
33+
}, {
34+
it: 'should report missing jsdoc-param description for function',
35+
errors: 1,
36+
code: function () {
37+
var x = 1;
38+
/**
39+
* @param xxx
40+
*/
41+
function funcName(xxx) {
42+
// dummy
43+
}
44+
}
45+
}, {
46+
it: 'should report missing jsdoc-param description for method',
47+
errors: 1,
48+
code: function () {
49+
Cls.prototype = {
50+
/**
51+
* @param yyy
52+
*/
53+
run: function(xxx) {
54+
// dummy
55+
}
56+
};
57+
}
58+
}, {
59+
it: 'should not report invalid jsdoc for method',
60+
code: function () {
61+
var x = 1;
62+
/**
63+
* @param {String} xxx description
64+
*/
65+
function funcName(xxx) {
66+
// dummy
67+
}
68+
}
69+
}, {
70+
it: 'should not report invalid jsdoc for function',
71+
code: function () {
72+
Cls.prototype = {
73+
/**
74+
* @param {String} xxx description
75+
*/
76+
run: function(xxx) {
77+
// dummy
78+
}
79+
};
80+
}
81+
}, {
82+
it: 'should not report invalid jsdoc with object type for method',
83+
code: function () {
84+
var x = 1;
85+
/**
86+
* @param {{foo: string}} xxx description
87+
*/
88+
function funcName(xxx) {
89+
// dummy
90+
}
91+
}
92+
}, {
93+
it: 'should not report invalid jsdoc with object type for function',
94+
code: function () {
95+
Cls.prototype = {
96+
/**
97+
* @param {{foo: string}} xxx description
98+
*/
99+
run: function(xxx) {
100+
// dummy
101+
}
102+
};
103+
}
104+
}, {
105+
it: 'should not report invalid jsdoc with no param type for method',
106+
code: function () {
107+
var x = 1;
108+
/**
109+
* @param xxx description
110+
*/
111+
function funcName(xxx) {
112+
// dummy
113+
}
114+
}
115+
}, {
116+
it: 'should not report invalid jsdoc with no param type for function',
117+
code: function () {
118+
Cls.prototype = {
119+
/**
120+
* @param xxx description
121+
*/
122+
run: function(xxx) {
123+
// dummy
124+
}
125+
};
126+
}
127+
}, {
128+
it: 'should report with right location',
129+
code: function () {
130+
Cls.prototype = {
131+
/**
132+
* @param xxx
133+
*/
134+
run: function(xxx) {
135+
// dummy
136+
}
137+
};
138+
},
139+
errors: {column: 17, line: 3}
140+
}
141+
/* jshint ignore:end */
142+
]);
143+
144+
});
145+
146+
});

0 commit comments

Comments
 (0)