Skip to content

Commit b7dd13e

Browse files
committed
new rule: requireHyphenBeforeDescription
1 parent bf7b174 commit b7dd13e

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-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+
requireHyphenBeforeDescription: require('./require-hyphen-before-description'),
910

1011
checkReturnTypes: require('./check-return-types'),
1112
requireReturnTypes: require('./require-return-types'),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = requireHyphenBeforeDescription;
2+
module.exports.tags = ['param', 'arg', 'argument'];
3+
module.exports.scopes = ['function'];
4+
module.exports.options = {
5+
requireHyphenBeforeDescription: {allowedValues: [true]}
6+
};
7+
8+
/**
9+
* checking returns types
10+
* @param {(FunctionDeclaration|FunctionExpression)} node
11+
* @param {DocTag} tag
12+
* @param {Function} err
13+
*/
14+
function requireHyphenBeforeDescription(node, tag, err) {
15+
if (!tag.description) {
16+
return;
17+
}
18+
19+
if (tag.description.substring(0, 2) !== '- ') {
20+
err('Missing hyphen before description', tag.loc);
21+
}
22+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
describe('lib/rules/validate-jsdoc/require-hyphen-before-description', function () {
2+
var checker = global.checker({
3+
additionalRules: ['lib/rules/validate-jsdoc.js']
4+
});
5+
6+
describe('configured', function() {
7+
8+
it('with undefined should throws', function() {
9+
global.expect(function() {
10+
checker.configure({requireHyphenBeforeDescription: undefined});
11+
}).to.throws(/accepted value/i);
12+
});
13+
14+
it('with undefined should throws', function() {
15+
global.expect(function() {
16+
checker.configure({requireHyphenBeforeDescription: {}});
17+
}).to.throws(/accepted value/i);
18+
});
19+
20+
});
21+
22+
describe('with true', function() {
23+
checker.rules({requireHyphenBeforeDescription: true});
24+
25+
checker.cases([
26+
/* jshint ignore:start */
27+
{
28+
it: 'should not throw',
29+
code: function() {
30+
function yay(yey) {
31+
}
32+
33+
/**
34+
* @param {number} yay
35+
*/
36+
function yey(yay) {
37+
}
38+
}
39+
40+
}, {
41+
it: 'should report invalid description (without a hyphen)',
42+
code: function () {
43+
/**
44+
* @param {number} yay description without hyphen
45+
*/
46+
function yey(yay) {
47+
}
48+
},
49+
errors: 1
50+
}, {
51+
it: 'should not report valid description (with hyphen)',
52+
code: function () {
53+
/**
54+
* @param {number} yay - description without hyphen
55+
*/
56+
function yey(yay) {
57+
}
58+
}
59+
60+
}
61+
/* jshint ignore:end */
62+
]);
63+
64+
});
65+
66+
});

0 commit comments

Comments
 (0)