From 30ca6e5801aa9c6ba4c9884f20cca3b00ff142ef Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Thu, 28 Dec 2023 20:24:09 +0200 Subject: [PATCH] style: replace-jsdoc-typedef-with-let-type fp-134 --- commitlint.config.js | 4 +--- eslint.config.js | 7 +++++-- knip.config.js | 4 +--- lint-staged.config.js | 4 +--- package.json | 5 +++-- prettier.config.js | 4 +--- .../types/html-form-control-element.type.js | 9 +++++---- ...form-non-operational-control-element.type.js | 5 +++-- ...tml-form-operational-control-element.type.js | 5 +++-- src/libs/types/types.js | 7 ++----- .../get-form-control-payload.js | 3 +-- .../check-has-value-as-array.helper.js | 3 +-- .../check-is-refer-to-another-element.helper.js | 2 +- ...get-fieldset-control-element-value.helper.js | 7 ++----- .../get-form-control-elements-payload.js | 11 +++++------ .../get-operational-control-elements.helper.js | 17 +++++++++-------- .../check-has-control-element-name.helper.js | 2 +- ...ck-is-allowed-control-element-type.helper.js | 3 +-- .../check-is-allowed-control-element.helper.js | 3 +-- ...alue-as-array-control-element-name.helper.js | 3 +-- 20 files changed, 48 insertions(+), 60 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index 4b4edea..212f0c8 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,10 +1,8 @@ import { RuleConfigSeverity } from '@commitlint/types'; -/** @typedef {import('@commitlint/types').UserConfig} UserConfig */ - const PROJECT_PREFIXES = /** @type {const} */ (['fp', 'release']); -/** @type {UserConfig} */ +/** @type {import('@commitlint/types').UserConfig} */ const configuration = { extends: ['@commitlint/config-conventional'], parserPreset: { diff --git a/eslint.config.js b/eslint.config.js index 618e10e..f81f3a0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -10,8 +10,10 @@ import sonarjs from 'eslint-plugin-sonarjs'; import unicorn from 'eslint-plugin-unicorn'; import globals from 'globals'; -/** @typedef {import('eslint').Linter.FlatConfig} FlatConfig */ -/** @typedef {import('eslint').Linter.ParserModule} ParserModule */ +/** @typedef {import('eslint').Linter.FlatConfig} */ +let FlatConfig; +/** @typedef {import('eslint').Linter.ParserModule} */ +let ParserModule; /** @type {FlatConfig} */ const ignoresConfig = { @@ -65,6 +67,7 @@ const jsdocConfig = { }, rules: { ...jsdoc.configs['recommended-typescript-flavor-error'].rules, + 'jsdoc/no-undefined-types': ['error'], 'jsdoc/require-jsdoc': [ 'error', { diff --git a/knip.config.js b/knip.config.js index 37788f8..4a806ee 100644 --- a/knip.config.js +++ b/knip.config.js @@ -1,6 +1,4 @@ -/** @typedef {import('knip/dist').KnipConfig} KnipConfig */ - -/** @type {KnipConfig} */ +/** @type {import('knip').KnipConfig} */ const config = { entry: ['src/index.js'], }; diff --git a/lint-staged.config.js b/lint-staged.config.js index 677ce74..c3a3846 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,6 +1,4 @@ -/** @typedef {import('lint-staged').Config} Config */ - -/** @type {Config} */ +/** @type {import('lint-staged').Config} */ const config = { '*': [ 'npm run ci:lint:fs', diff --git a/package.json b/package.json index f68a75b..3cb8503 100644 --- a/package.json +++ b/package.json @@ -29,16 +29,17 @@ }, "scripts": { "postinstall": "npx simple-git-hooks", + "_prettier": "prettier \"**/*.{json,md,yml,js}\"", "ci:lint:commit": "npx @commitlint/cli --edit", "ci:lint:fs": "ls-lint", "ci:lint:editor": "editorconfig-checker", "ci:lint:trash": "knip --config knip.config.js", - "ci:lint:format": "npm run ci:format -- --check", + "ci:lint:format": "npm run _prettier -- --check", "ci:lint:js": "eslint \"**/*.js\"", "ci:lint:type": "tsc --noEmit", "ci:lint": "npm run ci:lint:fs && npm run ci:lint:editor && npm run ci:lint:trash && npm run ci:lint:format && npm run ci:lint:js && npm run ci:lint:type", "ci:test": "node --import jsdom-global/register.js --test", - "ci:format": "prettier --write \"**/*.{json,md,yml,js}\"", + "ci:format": "npm run _prettier -- --write", "build:clean": "rm -rf dist", "build:dist": "tsc -p tsconfig.build.json", "build:cp": "cp -r src readme.md package.json LICENSE dist", diff --git a/prettier.config.js b/prettier.config.js index 4410d98..8459ede 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,6 +1,4 @@ -/** @typedef {import('prettier').Config} Config */ - -/** @type {Config} */ +/** @type {import('prettier').Config} */ const config = { arrowParens: 'always', bracketSpacing: true, diff --git a/src/libs/types/html-form-control-element.type.js b/src/libs/types/html-form-control-element.type.js index 30cb692..060eb1a 100644 --- a/src/libs/types/html-form-control-element.type.js +++ b/src/libs/types/html-form-control-element.type.js @@ -1,9 +1,10 @@ -/** @typedef {import('./html-form-non-operational-control-element.type.js').HTMLFormNonOperationalControlElement} HTMLFormNonOperationalControlElement */ -/** @typedef {import('./html-form-operational-control-element.type.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ +import { HTMLFormNonOperationalControlElement } from './html-form-non-operational-control-element.type.js'; +import { HTMLFormOperationalControlElement } from './html-form-operational-control-element.type.js'; /** * @typedef {HTMLFormNonOperationalControlElement - * | HTMLFormOperationalControlElement} HTMLFormControlElement + * | HTMLFormOperationalControlElement} */ +let HTMLFormControlElement; -export {}; +export { HTMLFormControlElement }; diff --git a/src/libs/types/html-form-non-operational-control-element.type.js b/src/libs/types/html-form-non-operational-control-element.type.js index 5df95a2..d63835f 100644 --- a/src/libs/types/html-form-non-operational-control-element.type.js +++ b/src/libs/types/html-form-non-operational-control-element.type.js @@ -1,3 +1,4 @@ -/** @typedef {HTMLButtonElement | HTMLObjectElement} HTMLFormNonOperationalControlElement */ +/** @typedef {HTMLButtonElement | HTMLObjectElement} */ +let HTMLFormNonOperationalControlElement; -export {}; +export { HTMLFormNonOperationalControlElement }; diff --git a/src/libs/types/html-form-operational-control-element.type.js b/src/libs/types/html-form-operational-control-element.type.js index 2229a7b..eee4a8d 100644 --- a/src/libs/types/html-form-operational-control-element.type.js +++ b/src/libs/types/html-form-operational-control-element.type.js @@ -3,7 +3,8 @@ * | HTMLSelectElement * | HTMLOutputElement * | HTMLFieldSetElement - * | HTMLTextAreaElement} HTMLFormOperationalControlElement + * | HTMLTextAreaElement} */ +let HTMLFormOperationalControlElement; -export {}; +export { HTMLFormOperationalControlElement }; diff --git a/src/libs/types/types.js b/src/libs/types/types.js index d5d91f6..84a2984 100644 --- a/src/libs/types/types.js +++ b/src/libs/types/types.js @@ -1,5 +1,2 @@ -/** @typedef {import('./html-form-non-operational-control-element.type.js').HTMLFormNonOperationalControlElement} HTMLFormNonOperationalControlElement */ -/** @typedef {import('./html-form-operational-control-element.type.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ -/** @typedef {import('./html-form-control-element.type.js').HTMLFormControlElement} HTMLFormControlElement */ - -export {}; +export { HTMLFormControlElement } from './html-form-control-element.type.js'; +export { HTMLFormOperationalControlElement } from './html-form-operational-control-element.type.js'; diff --git a/src/packages/get-form-control-payload/get-form-control-payload.js b/src/packages/get-form-control-payload/get-form-control-payload.js index 17d2196..65deca5 100644 --- a/src/packages/get-form-control-payload/get-form-control-payload.js +++ b/src/packages/get-form-control-payload/get-form-control-payload.js @@ -1,5 +1,6 @@ import { ControlElementType } from '../../libs/enums/enums.js'; import { FormPayloadError } from '../../libs/exceptions/exceptions.js'; +import { HTMLFormOperationalControlElement } from '../../libs/types/types.js'; import { getCheckboxControlElementValue, getControlElementValue, @@ -13,8 +14,6 @@ import { getRadioControlElementValue, } from './libs/helpers/helpers.js'; -/** @typedef {import('../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ - /** * @template {unknown} T * @param {HTMLFormOperationalControlElement} controlElement diff --git a/src/packages/get-form-control-payload/libs/helpers/check-has-value-as-array/check-has-value-as-array.helper.js b/src/packages/get-form-control-payload/libs/helpers/check-has-value-as-array/check-has-value-as-array.helper.js index 0af4576..9c2d631 100644 --- a/src/packages/get-form-control-payload/libs/helpers/check-has-value-as-array/check-has-value-as-array.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/check-has-value-as-array/check-has-value-as-array.helper.js @@ -2,8 +2,7 @@ import { VALUE_AS_ARRAY_CUSTOM_CONTROL_ELEMENT_TYPES, VALUE_AS_ARRAY_IDENTIFIER, } from '../../../../../libs/constants/constants.js'; - -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ +import { HTMLFormOperationalControlElement } from '../../../../../libs/types/types.js'; /** * @param {HTMLFormOperationalControlElement} element diff --git a/src/packages/get-form-control-payload/libs/helpers/check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js b/src/packages/get-form-control-payload/libs/helpers/check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js index dfd955c..22ab3c0 100644 --- a/src/packages/get-form-control-payload/libs/helpers/check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js @@ -1,4 +1,4 @@ -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ +import { HTMLFormOperationalControlElement } from '../../../../../libs/types/types.js'; /** * @param {HTMLFormOperationalControlElement} currentElement diff --git a/src/packages/get-form-control-payload/libs/helpers/get-fieldset-control-element-value/get-fieldset-control-element-value.helper.js b/src/packages/get-form-control-payload/libs/helpers/get-fieldset-control-element-value/get-fieldset-control-element-value.helper.js index e0ac648..72e1d63 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-fieldset-control-element-value/get-fieldset-control-element-value.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-fieldset-control-element-value/get-fieldset-control-element-value.helper.js @@ -1,13 +1,10 @@ import { VALUE_AS_ARRAY_IDENTIFIER } from '../../../../../libs/constants/constants.js'; +import { HTMLFormOperationalControlElement } from '../../../../../libs/types/types.js'; import { getFormControlElementsPayload } from '../get-form-control-elements-payload/get-form-control-elements-payload.js'; -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ - /** * @template {Record} T - * @param {( - * element: HTMLFormOperationalControlElement, - * ) => T} getFormControlElementPayloadCallback + * @param {(element: HTMLFormOperationalControlElement) => unknown} getFormControlElementPayloadCallback * @param {HTMLFieldSetElement} element * @returns {T | [T]} */ diff --git a/src/packages/get-form-control-payload/libs/helpers/get-form-control-elements-payload/get-form-control-elements-payload.js b/src/packages/get-form-control-payload/libs/helpers/get-form-control-elements-payload/get-form-control-elements-payload.js index 6be435a..76b9ff3 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-form-control-elements-payload/get-form-control-elements-payload.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-form-control-elements-payload/get-form-control-elements-payload.js @@ -1,19 +1,18 @@ import { ControlElementType } from '../../../../../libs/enums/enums.js'; import { checkIsOnOf } from '../../../../../libs/helpers/helpers.js'; +import { + HTMLFormControlElement, + HTMLFormOperationalControlElement, +} from '../../../../../libs/types/types.js'; import { checkHasValueAsArray } from '../check-has-value-as-array/check-has-value-as-array.helper.js'; import { checkIsReferToAnotherElement } from '../check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js'; import { getControlElementValue } from '../get-control-element-value/get-control-element-value.helper.js'; import { getOperationalControlElements } from '../get-operational-control-elements/get-operational-control-elements.helper.js'; import { normalizeValueAsArrayControlElementName } from '../normalize-value-as-array-control-element-name/normalize-value-as-array-control-element-name.helper.js'; -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */ - /** * @template {Record} T - * @param {( - * element: HTMLFormOperationalControlElement, - * ) => T} getFormControlElementPayloadCallback + * @param {(element: HTMLFormOperationalControlElement) => unknown} getFormControlElementPayloadCallback * @param {HTMLFormControlsCollection} elements * @returns {T} */ diff --git a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/get-operational-control-elements.helper.js b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/get-operational-control-elements.helper.js index 07e671f..7453dbe 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/get-operational-control-elements.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/get-operational-control-elements.helper.js @@ -1,12 +1,13 @@ +import { + HTMLFormControlElement, + HTMLFormOperationalControlElement, +} from '../../../../../libs/types/types.js'; import { checkHasControlElementName, checkIsAllowedControlElement, checkIsAllowedControlElementType, } from './helpers/helpers.js'; -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */ -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ - const OPERATIONAL_CONTROL_ELEMENT_CHECKERS = /** @type {const} */ ([ checkHasControlElementName, checkIsAllowedControlElement, @@ -20,11 +21,11 @@ const OPERATIONAL_CONTROL_ELEMENT_CHECKERS = /** @type {const} */ ([ const getOperationalControlElements = (elements) => { return elements.filter( /** - * @type {( - * element: HTMLFormControlElement, - * ) => element is HTMLFormOperationalControlElement} - */ (element) => { - return Object.values(OPERATIONAL_CONTROL_ELEMENT_CHECKERS).every( + * @param {HTMLFormControlElement} element + * @returns {element is HTMLFormOperationalControlElement} + */ + (element) => { + return OPERATIONAL_CONTROL_ELEMENT_CHECKERS.every( (checkFunction) => { return checkFunction(element); }, diff --git a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-has-control-element-name/check-has-control-element-name.helper.js b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-has-control-element-name/check-has-control-element-name.helper.js index 28e55e4..03a7473 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-has-control-element-name/check-has-control-element-name.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-has-control-element-name/check-has-control-element-name.helper.js @@ -1,4 +1,4 @@ -/** @typedef {import('../../../../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */ +import { HTMLFormControlElement } from '../../../../../../../libs/types/types.js'; /** * @param {HTMLFormControlElement} element diff --git a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element-type/check-is-allowed-control-element-type.helper.js b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element-type/check-is-allowed-control-element-type.helper.js index b8519e4..77f4f8b 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element-type/check-is-allowed-control-element-type.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element-type/check-is-allowed-control-element-type.helper.js @@ -1,6 +1,5 @@ import { BANNED_CONTROL_ELEMENT_TYPES } from '../../../../../../../libs/constants/constants.js'; - -/** @typedef {import('../../../../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */ +import { HTMLFormControlElement } from '../../../../../../../libs/types/types.js'; /** * @param {HTMLFormControlElement} element diff --git a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element/check-is-allowed-control-element.helper.js b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element/check-is-allowed-control-element.helper.js index 93d1cae..4ac2578 100644 --- a/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element/check-is-allowed-control-element.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/get-operational-control-elements/helpers/check-is-allowed-control-element/check-is-allowed-control-element.helper.js @@ -1,6 +1,5 @@ import { bannedElementNameToElementInstance } from '../../../../../../../libs/maps/maps.js'; - -/** @typedef {import('../../../../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */ +import { HTMLFormControlElement } from '../../../../../../../libs/types/types.js'; /** * @param {HTMLFormControlElement} element diff --git a/src/packages/get-form-control-payload/libs/helpers/normalize-value-as-array-control-element-name/normalize-value-as-array-control-element-name.helper.js b/src/packages/get-form-control-payload/libs/helpers/normalize-value-as-array-control-element-name/normalize-value-as-array-control-element-name.helper.js index 6b2a3e2..4e28be4 100644 --- a/src/packages/get-form-control-payload/libs/helpers/normalize-value-as-array-control-element-name/normalize-value-as-array-control-element-name.helper.js +++ b/src/packages/get-form-control-payload/libs/helpers/normalize-value-as-array-control-element-name/normalize-value-as-array-control-element-name.helper.js @@ -1,6 +1,5 @@ import { VALUE_AS_ARRAY_IDENTIFIER } from '../../../../../libs/constants/constants.js'; - -/** @typedef {import('../../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ +import { HTMLFormOperationalControlElement } from '../../../../../libs/types/types.js'; /** * @param {HTMLFormOperationalControlElement} element