Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract JSDoc comment recognition into util functions
and add tests for them
- Loading branch information
1 parent
1c0bd96
commit 73ebb8e
Showing
4 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @param {Comment} node | ||
* @returns {boolean} | ||
*/ | ||
const isJSDocComment = (node) => | ||
node.type === 'Block' && | ||
node.value.charAt(0) === '*' && | ||
node.value.charAt(1) !== '*' | ||
|
||
/** | ||
* @param {Comment} node | ||
* @returns {boolean} | ||
*/ | ||
const isBlockComment = (node) => | ||
node.type === 'Block' && | ||
(node.value.charAt(0) !== '*' || node.value.charAt(1) === '*') | ||
|
||
module.exports = { | ||
isJSDocComment, | ||
isBlockComment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const { | ||
isBlockComment, | ||
isJSDocComment | ||
} = require('../../../lib/utils/comments.js') | ||
|
||
// //foo | ||
const lineCommentNode = { | ||
type: 'Line', | ||
value: 'foo' | ||
} | ||
|
||
// /*foo*/ | ||
const blockCommentNodeWithoutAsterisks = { | ||
type: 'Block', | ||
value: 'foo' | ||
} | ||
|
||
// //** foo */ | ||
const blockCommentNodeWithOneAsterisk = { | ||
type: 'Block', | ||
value: '* foo' | ||
} | ||
|
||
// /*** foo */ | ||
const blockCommentNodeWithTwoAsterisks = { | ||
type: 'Block', | ||
value: '** foo' | ||
} | ||
|
||
describe('isJSDocComment()', () => { | ||
it('returns true for JSDoc comments', () => { | ||
assert.equal(isJSDocComment(blockCommentNodeWithOneAsterisk), true) | ||
}) | ||
|
||
it('returns false for block comments', () => { | ||
assert.equal(isJSDocComment(blockCommentNodeWithoutAsterisks), false) | ||
}) | ||
|
||
it('returns false for line comments', () => { | ||
assert.equal(isJSDocComment(lineCommentNode), false) | ||
}) | ||
|
||
it('returns false for block comments with two asterisks', () => { | ||
assert.equal(isJSDocComment(blockCommentNodeWithTwoAsterisks), false) | ||
}) | ||
}) | ||
|
||
describe('isBlockComment()', () => { | ||
it('returns false for JSDoc comments', () => { | ||
assert.equal(isBlockComment(blockCommentNodeWithOneAsterisk), false) | ||
}) | ||
|
||
it('returns true for block comments', () => { | ||
assert.equal(isBlockComment(blockCommentNodeWithoutAsterisks), true) | ||
}) | ||
|
||
it('returns false for line comments', () => { | ||
assert.equal(isBlockComment(lineCommentNode), false) | ||
}) | ||
|
||
it('returns true for block comments with two asterisks', () => { | ||
assert.equal(isBlockComment(blockCommentNodeWithTwoAsterisks), true) | ||
}) | ||
}) |