From 506b096299405b20b0d18c27c1a926623805bccd Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Mon, 4 Mar 2024 17:16:23 -0500 Subject: [PATCH] feat(utils): `keycheck` Signed-off-by: Lexus Drumgold --- .codecov.yml | 7 +------ .github/workflows/ci.yml | 2 +- README.md | 2 +- build.config.ts | 6 +----- package.json | 3 --- src/utils/__tests__/keycheck.spec.ts | 28 ++++++++++++++++++++++++++++ src/utils/index.ts | 6 ++++++ src/utils/keycheck.ts | 21 +++++++++++++++++++++ 8 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 src/utils/__tests__/keycheck.spec.ts create mode 100644 src/utils/index.ts create mode 100644 src/utils/keycheck.ts diff --git a/.codecov.yml b/.codecov.yml index a4c5ef4..67eafee 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -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: [] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 160c8c3..e0f534f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -333,7 +333,7 @@ jobs: - id: codecov name: Upload coverage report to Codecov if: steps.test-files-check.outputs.files_exists == 'true' - uses: actions/cache@v4.0.1 + uses: codecov/codecov-action@v4.1.0 env: GITHUB_JOB: ${{ github.job }} GITHUB_REF: ${{ github.ref }} diff --git a/README.md b/README.md index 318e0bb..5f84844 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/build.config.ts b/build.config.ts index ba2cf17..ccdeea0 100644 --- a/build.config.ts +++ b/build.config.ts @@ -5,7 +5,6 @@ */ import { defineBuildConfig, type Config } from '@flex-development/mkbuild' -import pkg from './package.json' assert { type: 'json' } import tsconfig from './tsconfig.build.json' assert { type: 'json' } /** @@ -16,10 +15,7 @@ import tsconfig from './tsconfig.build.json' assert { type: 'json' } const config: Config = defineBuildConfig({ charset: 'utf8', entries: [{ dts: 'only' }, { dts: false, ignore: ['types'] }], - target: [ - pkg.engines.node.replace(/^\D+/, 'node'), - tsconfig.compilerOptions.target - ], + target: ['node18', tsconfig.compilerOptions.target], tsconfig: 'tsconfig.build.json' }) diff --git a/package.json b/package.json index e0eca1b..ea7090e 100644 --- a/package.json +++ b/package.json @@ -158,9 +158,6 @@ "@types/estree": "1.0.5", "chai": "5.1.0" }, - "engines": { - "node": ">=18.18.2" - }, "packageManager": "yarn@4.1.0", "sideEffects": false } diff --git a/src/utils/__tests__/keycheck.spec.ts b/src/utils/__tests__/keycheck.spec.ts new file mode 100644 index 0000000..6ba0d65 --- /dev/null +++ b/src/utils/__tests__/keycheck.spec.ts @@ -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 + }) +}) diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..9789ef1 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,6 @@ +/** + * @file Entry Point - Utilities + * @module esast-util-attach-comments/utils + */ + +export { default as keycheck } from './keycheck' diff --git a/src/utils/keycheck.ts b/src/utils/keycheck.ts new file mode 100644 index 0000000..4d0e707 --- /dev/null +++ b/src/utils/keycheck.ts @@ -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