-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
4c8bf79
commit 672b668
Showing
5 changed files
with
57 additions
and
7 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,28 @@ | ||
/** | ||
* @file Unit Tests - keycheck | ||
* @module esast-util-attach-comments/utils/tests/unit/keycheck | ||
*/ | ||
|
||
import testSubject from '../keycheck' | ||
|
||
describe('unit:utils/keycheck', () => { | ||
it('should return false if key === "comments"', () => { | ||
expect(testSubject('comments')).to.be.false | ||
}) | ||
|
||
it('should return false if key === "leadingComments"', () => { | ||
expect(testSubject('leadingComments')).to.be.false | ||
}) | ||
|
||
it('should return false if key === "trailingComments"', () => { | ||
expect(testSubject('trailingComments')).to.be.false | ||
}) | ||
|
||
it('should return true if key === undefined', () => { | ||
expect(testSubject()).to.be.true | ||
}) | ||
|
||
it('should return true if key is not comment field', () => { | ||
expect(testSubject('body')).to.be.true | ||
}) | ||
}) |
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,6 @@ | ||
/** | ||
* @file Entry Point - Utilities | ||
* @module esast-util-attach-comments/utils | ||
*/ | ||
|
||
export { default as keycheck } from './keycheck' |
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 @@ | ||
/** | ||
* @file Utilities - keycheck | ||
* @module esast-util-attach-comments/utils/keycheck | ||
*/ | ||
|
||
/** | ||
* Allow comment node attachments by `key`. | ||
* | ||
* @internal | ||
* | ||
* @this {void} | ||
* | ||
* @param {string?} key - Field at which a node lives in its parent (or where a | ||
* list of nodes live if `parent[key]` is an array) | ||
* @return {boolean} `true` if comments can be attached, `false` otherwise | ||
*/ | ||
function keycheck(this: void, key?: string): boolean { | ||
return !key || !/^(?:comments|(?:leading|trailing)Comments)$/.test(key) | ||
} | ||
|
||
export default keycheck |