/
lint.js
49 lines (45 loc) · 1.21 KB
/
lint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
var CANONICAL = {
'String': 'string',
'Boolean': 'boolean',
'Undefined': 'undefined',
'Number': 'number',
'array': 'Array',
'date': 'Date',
'object': 'Object'
};
/**
* Passively lints and checks documentation data.
*
* @name lint
* @param {Object} comment parsed comment
* @returns {Array<Object>} array of errors
*/
module.exports = function (comment) {
comment.tags.forEach(function (tag) {
function nameInvariant(name) {
if (CANONICAL[name]) {
comment.errors.push({
message: 'type ' + name + ' found, ' + CANONICAL[name] + ' is standard',
commentLineNumber: tag.lineNumber
});
}
}
function checkCanonical(type) {
if (type.type === 'NameExpression') {
nameInvariant(type.name);
} else if (type.type === 'UnionType') {
type.elements.forEach(checkCanonical);
} else if (type.type === 'OptionalType') {
checkCanonical(type.expression);
} else if (type.type === 'TypeApplication') {
checkCanonical(type.expression);
type.applications.map(checkCanonical);
}
}
if (tag.title === 'param' && tag.type) {
checkCanonical(tag.type);
}
});
return comment;
};