Detect against comments that do not begin with /**

Fixes #11
This commit is contained in:
Tom MacWright 2015-03-11 12:14:35 -04:00
parent fb5afc4428
commit 5c192845c9
4 changed files with 49 additions and 2 deletions

View File

@ -13,11 +13,26 @@ var externalModuleRegexp = process.platform === 'win32' ?
/^(\.|\w:)/ :
/^[\/.]/;
/**
* Detect whether a comment is a JSDoc comment: it should start with
* two asterisks, not any other number of asterisks.
*
* The code parser automatically strips out the first asterisk that's
* required for the comment to be a comment at all, so we count the remaining
* comments.
* @param {String} comment
* @return {boolean} whether it is valid
*/
function isJSDocComment(code) {
var asterisks = code.match(/^(\*+)/);
return asterisks && asterisks[ 1 ].length === 1;
}
/**
* Comment-out a shebang line that may sit at the top of a file,
* making it executable on linux-like systems.
* @param {String} code
* @return code
* @return {String} code
*/
function commentShebang(code) {
return (code[ 0 ] === '#' && code[ 1 ] === '!') ? '//' + code : code;
@ -58,7 +73,9 @@ module.exports = function (index) {
node.leadingComments.filter(function (c) {
return c.type === 'Block';
}).map(function (comment) {
docs.push(doctrine.parse(comment.value, { unwrap: true }));
if (isJSDocComment(comment.value)) {
docs.push(doctrine.parse(comment.value, { unwrap: true }));
}
});
}
this.traverse(path);

View File

@ -0,0 +1,8 @@
/*
* This function returns the number one.
* @return {Number} numberone
*/
module.exports = function () {
// this returns 1
return 1;
};

View File

@ -0,0 +1,8 @@
/***
* This function returns the number one.
* @return {Number} numberone
*/
module.exports = function () {
// this returns 1
return 1;
};

View File

@ -13,6 +13,20 @@ test('documentation', function (t) {
}));
});
test('documentation - single star', function (t) {
documentation(path.join(__dirname, 'fixture/simple-singlestar.js')).pipe(concat(function (data) {
t.equal(data.length, 0, 'simple has no dependencies');
t.end();
}));
});
test('documentation - triple star', function (t) {
documentation(path.join(__dirname, 'fixture/simple-triplestar.js')).pipe(concat(function (data) {
t.equal(data.length, 0, 'simple has no dependencies');
t.end();
}));
});
test('documentation - hashbang', function (t) {
documentation(path.join(__dirname, 'fixture/simple-hashbang.js')).pipe(concat(function (data) {
t.equal(data.length, 1, 'simple has no dependencies');