From f29b4c947887749418fe96bec09837339ca89787 Mon Sep 17 00:00:00 2001 From: qderoubaix Date: Wed, 6 Nov 2024 23:07:05 +0100 Subject: [PATCH] feat: stricter jsdoc eslint rules --- .../src/components/modal/modal.service.ts | 14 +++++++++----- angular/headless/src/types.ts | 7 ++++++- angular/headless/src/utils/widget.ts | 2 +- core/src/components/components.spec-utils.ts | 3 +++ core/src/components/select/select.ts | 14 ++++++++++++++ core/src/services/floatingUI.ts | 3 +++ core/src/types.ts | 2 ++ core/src/utils/internal/checks.ts | 2 ++ core/src/utils/internal/promise.ts | 2 ++ eslint.config.js | 7 +++++-- .../src/components/accordion/accordion.tsx | 14 +++++++------- react/bootstrap/src/components/modal/modal.tsx | 12 ++++++------ .../src/components/pagination/pagination.tsx | 12 ++++++------ .../src/components/progressbar/progressbar.tsx | 8 ++++---- react/bootstrap/src/components/rating/rating.tsx | 4 ++-- react/bootstrap/src/components/select/select.tsx | 8 ++------ react/bootstrap/src/components/slider/slider.tsx | 12 ++++++------ react/bootstrap/src/components/toast/toast.tsx | 4 ++-- react/headless/src/utils/directive.ts | 1 + .../src/components/accordion/accordion.ts | 2 +- .../bootstrap/src/components/modal/modalService.ts | 8 ++++---- 21 files changed, 88 insertions(+), 53 deletions(-) diff --git a/angular/bootstrap/src/components/modal/modal.service.ts b/angular/bootstrap/src/components/modal/modal.service.ts index 849f153851..0b4d9ce01f 100644 --- a/angular/bootstrap/src/components/modal/modal.service.ts +++ b/angular/bootstrap/src/components/modal/modal.service.ts @@ -3,10 +3,6 @@ import type {Subscription} from 'rxjs'; import {ModalComponent} from './modal.component'; import type {ModalProps} from './modal.gen'; -interface ModalServiceOpenOptions { - injector?: Injector; -} - /** * Service to handle the opening and management of modal components. */ @@ -15,7 +11,15 @@ export class ModalService { private readonly _injector = inject(Injector); private readonly _applicationRef = inject(ApplicationRef); - async open(options: Partial>, {injector = this._injector}: ModalServiceOpenOptions = {}): Promise { + /** + * Opens a modal dialog with the specified options. + * + * @template Data - The type of data that the modal will handle. + * @param options - The options to configure the modal. + * @param injector - The injector to use when creating the modal component + * @returns A promise that resolves when the modal is closed. + */ + async open(options: Partial>, injector = this._injector): Promise { const component = createComponent(ModalComponent, { environmentInjector: injector.get(EnvironmentInjector), elementInjector: injector, diff --git a/angular/headless/src/types.ts b/angular/headless/src/types.ts index dae09ee5bf..4bdbbe7f5d 100644 --- a/angular/headless/src/types.ts +++ b/angular/headless/src/types.ts @@ -106,9 +106,14 @@ export interface AngularWidget extends Pick void; } +/** + * Represents the context for a widget slot, providing access to the widget and its state. + * + * @template W - The type of the widget. + */ export interface WidgetSlotContext extends Pick { /** - * the state of the widget + * The state of the widget. Each property of the state is exposed through an Angular {@link https://angular.dev/api/core/Signal | Signal} */ state: AngularState; } diff --git a/angular/headless/src/utils/widget.ts b/angular/headless/src/utils/widget.ts index 64f05848bd..c2004c432a 100644 --- a/angular/headless/src/utils/widget.ts +++ b/angular/headless/src/utils/widget.ts @@ -142,7 +142,7 @@ export abstract class BaseWidgetDirective implements OnChanges } /** - * Retrieves the widget state as an Angular {@link https://angular.dev/api/core/Signal | Signal} + * Retrieves the widget state. Each property of the state is exposed through an Angular {@link https://angular.dev/api/core/Signal | Signal} * @returns the widget state */ get state(): AngularState { diff --git a/core/src/components/components.spec-utils.ts b/core/src/components/components.spec-utils.ts index c796a4dca7..acf4e11e0c 100644 --- a/core/src/components/components.spec-utils.ts +++ b/core/src/components/components.spec-utils.ts @@ -16,6 +16,8 @@ export function getAttributes(node: HTMLElement) { /** * Utility method to register a directive to a fake dom element and send an event. + * + * @template T - The type of the directive parameters * @param directive - the directive to attach * @param args - the args of the directive * @param sendEvent - the event dispatcher function @@ -59,6 +61,7 @@ export function attachDirectiveAndClick(directive: Directive, args: /** * Utility method to register a directive to a fake button and click on it. * + * @template T - The type of the directive parameters * @param directive - the directive to attach * @param args - the args of the directive */ diff --git a/core/src/components/select/select.ts b/core/src/components/select/select.ts index 4517586997..d8efcab6d1 100644 --- a/core/src/components/select/select.ts +++ b/core/src/components/select/select.ts @@ -87,6 +87,8 @@ interface SelectCommonPropsAndState extends WidgetsCommonPropsAndState { /** * Props for the Select component. + * + * @template Item - The type of the Select Items */ export interface SelectProps extends SelectCommonPropsAndState { /** @@ -167,6 +169,8 @@ export interface SelectProps extends SelectCommonPropsAndState { /** * Item representation built from the items provided in parameters + * + * @template T - The type of the Select Items */ export interface ItemContext { /** @@ -187,6 +191,8 @@ export interface ItemContext { /** * Represents the state of a Select component. + * + * @template Item - The type of the Select Items */ export interface SelectState extends SelectCommonPropsAndState { /** @@ -213,6 +219,8 @@ export interface SelectState extends SelectCommonPropsAndState { /** * Interface representing the API for a Select component. + * + * @template Item - The type of the Select Items */ export interface SelectApi { /** @@ -287,6 +295,8 @@ export interface SelectApi { /** * Interface representing the directives used in the Select component. + * + * @template Item - The type of the Select Items */ export interface SelectDirectives { /** @@ -336,6 +346,8 @@ export interface SelectDirectives { /** * Represents a Select widget component. + * + * @template Item - The type of the Select Items */ export type SelectWidget = Widget, SelectState, SelectApi, SelectDirectives>; @@ -370,6 +382,8 @@ export function getSelectDefaultConfig(): SelectProps { /** * Create a SelectWidget with given config props + * + * @template Item - The type of the Select Items * @param config - an optional alert config * @returns a SelectWidget */ diff --git a/core/src/services/floatingUI.ts b/core/src/services/floatingUI.ts index 1bf69e9563..cd5d7543a4 100644 --- a/core/src/services/floatingUI.ts +++ b/core/src/services/floatingUI.ts @@ -61,6 +61,9 @@ export interface FloatingUIState { middlewareData: MiddlewareData | undefined; } +/** + * Interface representing the directives used to enable floating ui. + */ export interface FloatingUIDirectives { /** * Directive to attach to the reference element diff --git a/core/src/types.ts b/core/src/types.ts index 54387bf0de..ef7147a17b 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -180,6 +180,8 @@ export type DirectivesAndOptParam = undefined | null | string | ((props: Props) => string); diff --git a/core/src/utils/internal/checks.ts b/core/src/utils/internal/checks.ts index cd8dce562c..9ace1a5de6 100644 --- a/core/src/utils/internal/checks.ts +++ b/core/src/utils/internal/checks.ts @@ -71,6 +71,8 @@ export const allowNull = /** * Builds a new type guard to check if an element belongs to an enum list + * + * @template T - the type of the enum * @param list - the list of all enum values * @returns the type guard */ diff --git a/core/src/utils/internal/promise.ts b/core/src/utils/internal/promise.ts index 5eb068be91..a739ca97d8 100644 --- a/core/src/utils/internal/promise.ts +++ b/core/src/utils/internal/promise.ts @@ -16,6 +16,8 @@ export const promisePending: PromisePendingResult = {status: 'pending'}; /** * Represents the state of a promise, which can be either fulfilled, rejected, or pending. + * + * @template T - The type of the value promised */ export type PromiseState = PromiseFulfilledResult | PromiseRejectedResult | PromisePendingResult; diff --git a/eslint.config.js b/eslint.config.js index 8ff355cdbb..abc05ade60 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -310,8 +310,8 @@ export default tseslint.config( }, // jsdoc, { - files: ['{core,core-bootstrap}/src/**/*.{ts,tsx}', '{angular,react,svelte}/headless/src/**/*.{ts,tsx}'], - ignores: ['**/*.spec.ts'], + files: ['{core,core-bootstrap}/src/**/*.{ts,tsx}', '{angular,react,svelte}/{headless,bootstrap}/src/**/*.{ts,tsx}'], + ignores: ['**/*.spec.ts', 'angular/bootstrap/src/**/*.component.ts'], plugins: { jsdoc, }, @@ -333,6 +333,8 @@ export default tseslint.config( 'TSInterfaceDeclaration > TSInterfaceBody > TSMethodSignature', 'TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature', 'TSTypeAliasDeclaration > TSTypeLiteral > TSMethodSignature', + 'TSInterfaceDeclaration', + 'TSTypeAliasDeclaration', ], require: { FunctionExpression: true, @@ -343,6 +345,7 @@ export default tseslint.config( checkConstructors: false, }, ], + 'jsdoc/require-template': ['error'], }, }, // demo diff --git a/react/bootstrap/src/components/accordion/accordion.tsx b/react/bootstrap/src/components/accordion/accordion.tsx index 6423743361..441a8c4e63 100644 --- a/react/bootstrap/src/components/accordion/accordion.tsx +++ b/react/bootstrap/src/components/accordion/accordion.tsx @@ -27,8 +27,8 @@ const AccordionDIContext: React.Context> = createContext({ /** * Renders the default slot structure for an accordion item. * - * @param {AccordionItemContext} slotContext - The context containing state and directives for the accordion item. - * @returns {JSX.Element} The JSX element representing the accordion item's default slot structure. + * @param slotContext - The context containing state and directives for the accordion item. + * @returns The JSX element representing the accordion item's default slot structure. */ export const AccordionItemDefaultSlotStructure = (slotContext: AccordionItemContext) => ( <> @@ -81,16 +81,16 @@ export const AccordionItem: ForwardRefExoticComponent>} props - The properties for the Accordion component. * @param {ForwardedRef} ref - The ref to be forwarded to the Accordion API. - * + * * @returns {JSX.Element} The rendered Accordion component. - * + * */ export const Accordion: ForwardRefExoticComponent> & RefAttributes> = forwardRef( function Accordion(props: PropsWithChildren>, ref: ForwardedRef) { diff --git a/react/bootstrap/src/components/modal/modal.tsx b/react/bootstrap/src/components/modal/modal.tsx index 70eafd2992..da83769515 100644 --- a/react/bootstrap/src/components/modal/modal.tsx +++ b/react/bootstrap/src/components/modal/modal.tsx @@ -16,8 +16,8 @@ const CloseButton = ({directive}: {directive: Directive}) =>