Skip to content

Commit 506b096

Browse files
committed
feat(utils): keycheck
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 4c8bf79 commit 506b096

File tree

8 files changed

+59
-16
lines changed

8 files changed

+59
-16
lines changed

.codecov.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,4 @@ ignore:
8888
- '**/index.ts'
8989

9090
profiling:
91-
critical_files_paths:
92-
- src/handlers/*.ts
93-
- src/utils/get-identifiers.ts
94-
- src/utils/has-module-id.ts
95-
- src/utils/preleave-if-statement.ts
96-
- src/visitors/*.ts
91+
critical_files_paths: []

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ jobs:
333333
- id: codecov
334334
name: Upload coverage report to Codecov
335335
if: steps.test-files-check.outputs.files_exists == 'true'
336-
uses: actions/cache@v4.0.1
336+
uses: codecov/codecov-action@v4.1.0
337337
env:
338338
GITHUB_JOB: ${{ github.job }}
339339
GITHUB_REF: ${{ github.ref }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![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)
44
[![npm](https://img.shields.io/npm/v/@flex-development/esast-util-attach-comments.svg)](https://npmjs.com/package/@flex-development/esast-util-attach-comments)
5-
[![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)
5+
[![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)
66
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
77
[![license](https://img.shields.io/github/license/flex-development/esast-util-attach-comments.svg)](LICENSE.md)
88
[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)

build.config.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { defineBuildConfig, type Config } from '@flex-development/mkbuild'
8-
import pkg from './package.json' assert { type: 'json' }
98
import tsconfig from './tsconfig.build.json' assert { type: 'json' }
109

1110
/**
@@ -16,10 +15,7 @@ import tsconfig from './tsconfig.build.json' assert { type: 'json' }
1615
const config: Config = defineBuildConfig({
1716
charset: 'utf8',
1817
entries: [{ dts: 'only' }, { dts: false, ignore: ['types'] }],
19-
target: [
20-
pkg.engines.node.replace(/^\D+/, 'node'),
21-
tsconfig.compilerOptions.target
22-
],
18+
target: ['node18', tsconfig.compilerOptions.target],
2319
tsconfig: 'tsconfig.build.json'
2420
})
2521

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@
158158
"@types/estree": "1.0.5",
159159
"chai": "5.1.0"
160160
},
161-
"engines": {
162-
"node": ">=18.18.2"
163-
},
164161
"packageManager": "[email protected]",
165162
"sideEffects": false
166163
}

src/utils/__tests__/keycheck.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @file Unit Tests - keycheck
3+
* @module esast-util-attach-comments/utils/tests/unit/keycheck
4+
*/
5+
6+
import testSubject from '../keycheck'
7+
8+
describe('unit:utils/keycheck', () => {
9+
it('should return false if key === "comments"', () => {
10+
expect(testSubject('comments')).to.be.false
11+
})
12+
13+
it('should return false if key === "leadingComments"', () => {
14+
expect(testSubject('leadingComments')).to.be.false
15+
})
16+
17+
it('should return false if key === "trailingComments"', () => {
18+
expect(testSubject('trailingComments')).to.be.false
19+
})
20+
21+
it('should return true if key === undefined', () => {
22+
expect(testSubject()).to.be.true
23+
})
24+
25+
it('should return true if key is not comment field', () => {
26+
expect(testSubject('body')).to.be.true
27+
})
28+
})

src/utils/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file Entry Point - Utilities
3+
* @module esast-util-attach-comments/utils
4+
*/
5+
6+
export { default as keycheck } from './keycheck'

src/utils/keycheck.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file Utilities - keycheck
3+
* @module esast-util-attach-comments/utils/keycheck
4+
*/
5+
6+
/**
7+
* Allow comment node attachments by `key`.
8+
*
9+
* @internal
10+
*
11+
* @this {void}
12+
*
13+
* @param {string?} key - Field at which a node lives in its parent (or where a
14+
* list of nodes live if `parent[key]` is an array)
15+
* @return {boolean} `true` if comments can be attached, `false` otherwise
16+
*/
17+
function keycheck(this: void, key?: string): boolean {
18+
return !key || !/^(?:comments|(?:leading|trailing)Comments)$/.test(key)
19+
}
20+
21+
export default keycheck

0 commit comments

Comments
 (0)