Skip to content

Commit ef50d17

Browse files
committed
Merge pull request #77 from jscs-dev/hotfix/check-annotations-rework
Check annotations rework and bunch of minor fixes
2 parents ee16a2c + 73a1b5a commit ef50d17

File tree

9 files changed

+74
-30
lines changed

9 files changed

+74
-30
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,23 @@ There are 3 presets for `Closure Compiler`, `JSDoc3` and `JSDuck5`.
7373

7474
By default it allows any tag of mixed set. You can pass `Object` to select preset with `preset` field and add custom tags with `extra` field.
7575

76-
Type: `Boolean` or `String` or `{"preset": String, "extra": Object}` (`extra` field should contains tags in keys and boolean in values. false means no value possible)
76+
Type: `Boolean` or `String` or `{"preset": String, "extra": Object}` (see [tag values](#user-content-tag-values))
7777

7878
Values: `true`, `"closurecompiler"`, `"jsdoc3"`, `"jsduck5"`, `Object`
7979

8080
Context: `file`
8181

8282
Tags: `*`
8383

84+
#### Tag values
85+
86+
`extra` field should contains tags in keys and there are options for values:
87+
- `false` means tag available with no value
88+
- `true` means tag available with any value
89+
- `"some"` means tag available and requires some value
90+
91+
See also [tag presets](https://github.com/jscs-dev/jscs-jsdoc/tree/hotfix/check-annotations-rework/lib/tags).
92+
8493
#### Example
8594

8695
```js

lib/jsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ function _iterateDocTypes(node, cb) {
420420
* Converts AST jsDoc node to simple object
421421
* @param {Object} node
422422
* @returns {!Array.<SimplifiedType>}
423-
* @link https://github.com/Kuniwak/jsdoctypeparser
423+
* @see https://github.com/Kuniwak/jsdoctypeparser
424424
*/
425425
function _simplifyType(node) {
426426
var res = [];

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/closurecompiler.json

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,56 @@
33
"author": true,
44
"argument": true,
55
"borrows": true,
6-
"class": true,
6+
"class": false,
77
"const": false,
88
"constant": false,
99
"constructor": false,
1010
"constructs": false,
1111
"default": true,
12-
"define": true,
12+
"define": "some",
1313
"deprecated": true,
1414
"description": true,
1515
"dict": false,
16-
"enum": true,
16+
"enum": "some",
1717
"event": true,
1818
"example": true,
1919
"export": false,
20-
"extends": true,
20+
"extends": "some",
2121
"field": false,
2222
"fileOverview": true,
2323
"final": false,
2424
"function": false,
2525
"ignore": false,
26-
"implements": true,
26+
"implements": "some",
2727
"inheritDoc": false,
2828
"inner": false,
2929
"interface": false,
30-
"lends": true,
31-
"license": true,
32-
"link": true,
30+
"lends": "some",
31+
"license": "some",
3332
"memberOf": true,
3433
"name": true,
3534
"namespace": true,
3635
"nosideeffects": false,
3736
"override": false,
3837
"package": false,
39-
"param": true,
40-
"preserve": true,
38+
"param": "some",
39+
"preserve": "some",
4140
"private": false,
4241
"property": true,
42+
"protected": false,
4343
"public": false,
4444
"requires": true,
45-
"returns": true,
45+
"returns": "some",
46+
"return": "some",
4647
"see": true,
4748
"since": true,
4849
"static": false,
4950
"struct": false,
5051
"template": true,
51-
"this": true,
52-
"throws": true,
53-
"type": true,
54-
"typedef": true,
55-
"version": true
52+
"this": "some",
53+
"throws": "some",
54+
"typedef": "some",
55+
"type": "some",
56+
"unrestricted": false,
57+
"version": "some"
5658
}

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,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"node": ">= 0.10.0"
2424
},
2525
"dependencies": {
26-
"comment-parser": "^0.2.3",
26+
"comment-parser": "zxqfox/comment-parser#jscs-jsdoc",
2727
"jsdoctypeparser": "^1.1.3"
2828
},
2929
"devDependencies": {

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
/**

test/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test/*test*.js test/lib/
22
--recursive
33
--require test/init.js
4+
--timeout 6000
45
-R dot
56
-u bdd

0 commit comments

Comments
 (0)