File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed
test/lib/rules/validate-jsdoc Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ var validatorsByName = module.exports = {
6
6
checkParamNames : require ( './check-param-names' ) ,
7
7
checkRedundantParams : require ( './check-redundant-params' ) ,
8
8
requireParamTypes : require ( './require-param-types' ) ,
9
+ requireHyphenBeforeDescription : require ( './require-hyphen-before-description' ) ,
9
10
10
11
checkReturnTypes : require ( './check-return-types' ) ,
11
12
requireReturnTypes : require ( './require-return-types' ) ,
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 ( / a c c e p t e d v a l u e / i) ;
12
+ } ) ;
13
+
14
+ it ( 'with undefined should throws' , function ( ) {
15
+ global . expect ( function ( ) {
16
+ checker . configure ( { requireHyphenBeforeDescription : { } } ) ;
17
+ } ) . to . throws ( / a c c e p t e d v a l u e / 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
+ } ) ;
You can’t perform that action at this time.
0 commit comments