Skip to content

Commit c93d4d9

Browse files
author
Alexej Yaroshevich
committed
checkAnnotations: rework
- true now means existance of tag - added 'some' value to force some value in tag - patched tests for changed tag values - changed @access value to 'some' Fixes #74
1 parent c8caa2e commit c93d4d9

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

lib/rules/validate-jsdoc/check-annotations.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ validateAnnotations.configure = function(options) {
7070
* @param {JSCS.Errors} errors
7171
*/
7272
function validateAnnotations(file, errors) {
73-
var checkFulfill = true; //this._options.checkAnnotations.checkFulfill;
7473
var comments = file.getComments();
7574
comments.forEach(function(commentNode) {
7675
if (commentNode.type !== 'Block' || commentNode.value[0] !== '*') {
@@ -86,17 +85,30 @@ function validateAnnotations(file, errors) {
8685
node.iterate(function(tag) {
8786
if (!(tag.id in tags)) {
8887
errors.add('unavailable tag ' + tag.id, tag.loc);
89-
}
90-
if (!checkFulfill) {
9188
return;
9289
}
9390

9491
// checking tag fullfill
9592
var isFilled = tag.name || tag.type || tag.description;
96-
if (tags[tag.id] === false && isFilled) {
97-
errors.add('unexpected data in tag ' + tag.id, tag.loc);
98-
} else if (tags[tag.id] === true && !isFilled) {
99-
errors.add('incomplete data in tag ' + tag.id, tag.loc);
93+
switch (tags[tag.id]) {
94+
case false:
95+
if (isFilled) {
96+
errors.add('unexpected data in tag ' + tag.id, tag.loc);
97+
}
98+
break;
99+
100+
case true:
101+
// any data
102+
break;
103+
104+
case 'some':
105+
if (!isFilled) {
106+
errors.add('incomplete data in tag ' + tag.id, tag.loc);
107+
}
108+
break;
109+
110+
default:
111+
// unknown
100112
}
101113
});
102114
});

lib/tags/jsdoc3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"abstract": false,
3-
"access": true,
3+
"access": "some",
44
"alias": true,
55
"arg": true,
66
"argument": true,

test/lib/jsdoc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,14 @@ describe('jsdoc', function() {
131131
' * @param {Type} some long\n' +
132132
' * description of param\n' +
133133
' * @abstract\n' +
134+
' * @example\n' +
135+
' * // use this anywhere\n' +
136+
' * makeFun(value, some);\n' +
134137
' */', {start: {line: 5, column: 2}});
135138
});
136139

137140
it('should parses comment and create all tags and types', function() {
138-
expect(c1.tags.length).to.eq(3);
141+
expect(c1.tags.length).to.eq(4);
139142

140143
var tag1 = c1.tags[0];
141144
expect(tag1.id).to.eq('tag1');
@@ -154,6 +157,12 @@ describe('jsdoc', function() {
154157
var abs = c1.tags[2];
155158
expect(abs.id).to.eq('abstract');
156159
expect(abs.loc).to.eql(new Location(11, 5));
160+
161+
var example = c1.tags[3];
162+
expect(example.id).to.eq('example');
163+
expect(example.type).to.eq(undefined);
164+
expect(example.name).to.eq(undefined);
165+
expect(example.description).to.eq('// use this anywhere\nmakeFun(value, some);');
157166
});
158167

159168
});

test/lib/rules/validate-jsdoc/check-annotations.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ describe('lib/rules/validate-jsdoc/check-annotations', function() {
3939
code: function() {
4040
/** @access */
4141
}
42+
},
43+
{
44+
it: 'should not throw example tag',
45+
errors: [],
46+
code: function() {
47+
/**
48+
* @example
49+
* // some sample comment
50+
* aFunctionSampleCall({a:1, b:2, c:3, e:null}, {a:4, d:5}, {b:6, c:7});
51+
*/
52+
}
4253
}
4354
/* jshint ignore:end */
4455
]);
@@ -73,7 +84,7 @@ describe('lib/rules/validate-jsdoc/check-annotations', function() {
7384
'preset': 'jsdoc3',
7485
'extra': {
7586
'empty': false,
76-
'fulfilled': true
87+
'fulfilled': 'some'
7788
}
7889
}});
7990

@@ -115,7 +126,7 @@ describe('lib/rules/validate-jsdoc/check-annotations', function() {
115126
checker.cases([
116127
/* jshint ignore:start */
117128
{
118-
it: 'should throw',
129+
it: 'arg, argument tags should throw',
119130
errors: 2,
120131
code: function() {
121132
/**

0 commit comments

Comments
 (0)