diff --git a/index.js b/index.js index a3a8f6f..38a534a 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test/fixture/simple-singlestar.js b/test/fixture/simple-singlestar.js new file mode 100644 index 0000000..dc8a030 --- /dev/null +++ b/test/fixture/simple-singlestar.js @@ -0,0 +1,8 @@ +/* + * This function returns the number one. + * @return {Number} numberone + */ +module.exports = function () { + // this returns 1 + return 1; +}; diff --git a/test/fixture/simple-triplestar.js b/test/fixture/simple-triplestar.js new file mode 100644 index 0000000..bf22216 --- /dev/null +++ b/test/fixture/simple-triplestar.js @@ -0,0 +1,8 @@ +/*** + * This function returns the number one. + * @return {Number} numberone + */ +module.exports = function () { + // this returns 1 + return 1; +}; diff --git a/test/test.js b/test/test.js index 41db6e1..6258843 100644 --- a/test/test.js +++ b/test/test.js @@ -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');