Skip to content

Commit

Permalink
feat(utils): keycheck
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 4, 2024
1 parent 4c8bf79 commit 672b668
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
7 changes: 1 addition & 6 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,4 @@ ignore:
- '**/index.ts'

profiling:
critical_files_paths:
- src/handlers/*.ts
- src/utils/get-identifiers.ts
- src/utils/has-module-id.ts
- src/utils/preleave-if-statement.ts
- src/visitors/*.ts
critical_files_paths: []
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![github release](https://img.shields.io/github/v/release/flex-development/esast-util-attach-comments.svg?include_prereleases&sort=semver)](https://github.com/flex-development/esast-util-attach-comments/releases/latest)
[![npm](https://img.shields.io/npm/v/@flex-development/esast-util-attach-comments.svg)](https://npmjs.com/package/@flex-development/esast-util-attach-comments)
[![codecov](https://codecov.io/gh/flex-development/esast-util-attach-comments/graph/badge.svg?token=)](https://codecov.io/gh/flex-development/esast-util-attach-comments)
[![codecov](https://codecov.io/gh/flex-development/esast-util-attach-comments/graph/badge.svg?token=gATnvcdplV)](https://codecov.io/gh/flex-development/esast-util-attach-comments)
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
[![license](https://img.shields.io/github/license/flex-development/esast-util-attach-comments.svg)](LICENSE.md)
[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)
Expand Down
28 changes: 28 additions & 0 deletions src/utils/__tests__/keycheck.spec.ts
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
})
})
6 changes: 6 additions & 0 deletions src/utils/index.ts
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'
21 changes: 21 additions & 0 deletions src/utils/keycheck.ts
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

0 comments on commit 672b668

Please sign in to comment.