Skip to content

Commit

Permalink
feat: stricter jsdoc eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix committed Nov 6, 2024
1 parent 5559d9e commit f29b4c9
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 53 deletions.
14 changes: 9 additions & 5 deletions angular/bootstrap/src/components/modal/modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -15,7 +11,15 @@ export class ModalService {
private readonly _injector = inject(Injector);
private readonly _applicationRef = inject(ApplicationRef);

async open<Data>(options: Partial<ModalProps<Data>>, {injector = this._injector}: ModalServiceOpenOptions = {}): Promise<any> {
/**
* 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<Data>(options: Partial<ModalProps<Data>>, injector = this._injector): Promise<any> {
const component = createComponent(ModalComponent, {
environmentInjector: injector.get(EnvironmentInjector),
elementInjector: injector,
Expand Down
7 changes: 6 additions & 1 deletion angular/headless/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ export interface AngularWidget<W extends Widget> extends Pick<W, 'api' | 'direct
updateSlots: () => 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<W extends Widget> extends Pick<W, 'api' | 'directives'> {
/**
* 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<W>;
}
2 changes: 1 addition & 1 deletion angular/headless/src/utils/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export abstract class BaseWidgetDirective<W extends Widget> 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<W> {
Expand Down
3 changes: 3 additions & 0 deletions core/src/components/components.spec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,6 +61,7 @@ export function attachDirectiveAndClick<T = void>(directive: Directive<T>, 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
*/
Expand Down
14 changes: 14 additions & 0 deletions core/src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ interface SelectCommonPropsAndState<Item> extends WidgetsCommonPropsAndState {

/**
* Props for the Select component.
*
* @template Item - The type of the Select Items
*/
export interface SelectProps<Item> extends SelectCommonPropsAndState<Item> {
/**
Expand Down Expand Up @@ -167,6 +169,8 @@ export interface SelectProps<Item> extends SelectCommonPropsAndState<Item> {

/**
* Item representation built from the items provided in parameters
*
* @template T - The type of the Select Items
*/
export interface ItemContext<T> {
/**
Expand All @@ -187,6 +191,8 @@ export interface ItemContext<T> {

/**
* Represents the state of a Select component.
*
* @template Item - The type of the Select Items
*/
export interface SelectState<Item> extends SelectCommonPropsAndState<Item> {
/**
Expand All @@ -213,6 +219,8 @@ export interface SelectState<Item> extends SelectCommonPropsAndState<Item> {

/**
* Interface representing the API for a Select component.
*
* @template Item - The type of the Select Items
*/
export interface SelectApi<Item> {
/**
Expand Down Expand Up @@ -287,6 +295,8 @@ export interface SelectApi<Item> {

/**
* Interface representing the directives used in the Select component.
*
* @template Item - The type of the Select Items
*/
export interface SelectDirectives<Item> {
/**
Expand Down Expand Up @@ -336,6 +346,8 @@ export interface SelectDirectives<Item> {

/**
* Represents a Select widget component.
*
* @template Item - The type of the Select Items
*/
export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, SelectDirectives<Item>>;

Expand Down Expand Up @@ -370,6 +382,8 @@ export function getSelectDefaultConfig(): SelectProps<any> {

/**
* Create a SelectWidget with given config props
*
* @template Item - The type of the Select Items
* @param config - an optional alert config
* @returns a SelectWidget
*/
Expand Down
3 changes: 3 additions & 0 deletions core/src/services/floatingUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export type DirectivesAndOptParam<T extends any[], U extends SSRHTMLElement = SS
* - `null`
* - A `string`
* - A function that takes `props` of type `Props` and returns a `string`
*
* @template Props - The type of the props when the slot is a function
*/
export type SlotContent<Props extends object = object> = undefined | null | string | ((props: Props) => string);

Expand Down
2 changes: 2 additions & 0 deletions core/src/utils/internal/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions core/src/utils/internal/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = PromiseFulfilledResult<T> | PromiseRejectedResult | PromisePendingResult;

Expand Down
7 changes: 5 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -333,6 +333,8 @@ export default tseslint.config(
'TSInterfaceDeclaration > TSInterfaceBody > TSMethodSignature',
'TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature',
'TSTypeAliasDeclaration > TSTypeLiteral > TSMethodSignature',
'TSInterfaceDeclaration',
'TSTypeAliasDeclaration',
],
require: {
FunctionExpression: true,
Expand All @@ -343,6 +345,7 @@ export default tseslint.config(
checkConstructors: false,
},
],
'jsdoc/require-template': ['error'],
},
},
// demo
Expand Down
14 changes: 7 additions & 7 deletions react/bootstrap/src/components/accordion/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const AccordionDIContext: React.Context<Partial<AccordionApi>> = 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) => (
<>
Expand Down Expand Up @@ -81,16 +81,16 @@ export const AccordionItem: ForwardRefExoticComponent<Partial<AccordionItemProps

/**
* Accordion component that provides a collapsible content container.
*
*
* This component uses a forward ref to expose the Accordion API to parent components.
* It leverages the {@link useWidgetWithConfig} hook to create the accordion widget and
* It leverages the {@link useWidgetWithConfig} hook to create the accordion widget and
* {@link https://react.dev/reference/react/useImperativeHandle | useImperativeHandle} to bind the widget API to the ref.
*
* @param {PropsWithChildren<Partial<AccordionProps>>} props - The properties for the Accordion component.
* @param {ForwardedRef<AccordionApi>} ref - The ref to be forwarded to the Accordion API.
*
*
* @returns {JSX.Element} The rendered Accordion component.
*
*
*/
export const Accordion: ForwardRefExoticComponent<PropsWithChildren<Partial<AccordionProps>> & RefAttributes<AccordionApi>> = forwardRef(
function Accordion(props: PropsWithChildren<Partial<AccordionProps>>, ref: ForwardedRef<AccordionApi>) {
Expand Down
12 changes: 6 additions & 6 deletions react/bootstrap/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const CloseButton = ({directive}: {directive: Directive}) => <button className="
* A default header component for the modal that displays a title and an optional close button.
*
* @template Data - The type of data used in the modal context.
* @param {ModalContext<Data>} slotContext - The context object containing the state and directives for the modal.
* @returns {JSX.Element} The JSX element representing the modal header.
* @param slotContext - The context object containing the state and directives for the modal.
* @returns The JSX element representing the modal header.
*/
export const ModalDefaultSlotHeader = <Data,>(slotContext: ModalContext<Data>) => (
<>
Expand All @@ -32,8 +32,8 @@ export const ModalDefaultSlotHeader = <Data,>(slotContext: ModalContext<Data>) =
* Renders the default slot structure for a modal component.
*
* @template Data - The type of the data used in the modal context.
* @param {ModalContext<Data>} slotContext - The context containing the state and props for the modal slots.
* @returns {JSX.Element} The JSX structure for the modal's default slots.
* @param slotContext - The context containing the state and props for the modal slots.
* @returns The JSX structure for the modal's default slots.
*/
export const ModalDefaultSlotStructure = <Data,>(slotContext: ModalContext<Data>) => (
<>
Expand Down Expand Up @@ -98,8 +98,8 @@ export const Modal = forwardRef(function Modal<Data>(props: Partial<ModalProps<D
* Opens a modal dialog with the specified options.
*
* @template Data - The type of data that the modal will handle.
* @param {Partial<ModalProps<Data>>} options - The options to configure the modal.
* @returns {Promise<any>} A promise that resolves when the modal is closed.
* @param options - The options to configure the modal.
* @returns A promise that resolves when the modal is closed.
*/
export async function openModal<Data>(options: Partial<ModalProps<Data>>) {
const root = ReactDOM.createRoot(document.createElement('div'));
Expand Down
12 changes: 6 additions & 6 deletions react/bootstrap/src/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {createPagination} from './pagination.gen';
/**
* Renders the default slot pages for the pagination component.
*
* @param {PaginationContext} slotContext - The context containing pagination state and directives.
* @returns {JSX.Element | null} The rendered pagination items or null if there are no pages.
* @param slotContext - The context containing pagination state and directives.
* @returns The rendered pagination items or null if there are no pages.
*
* The function iterates over the pages in the pagination state and generates JSX elements for each page.
* If a page is represented by -1, it renders an ellipsis item. Otherwise, it renders a page item.
Expand Down Expand Up @@ -53,8 +53,8 @@ export const PaginationDefaultSlotPages = (slotContext: PaginationContext) => {
/**
* Renders the default slot structure for the pagination component.
*
* @param {PaginationContext} slotContext - The context containing the state and directives for pagination.
* @returns {JSX.Element} The rendered pagination component.
* @param slotContext - The context containing the state and directives for pagination.
* @returns The rendered pagination component.
*
* The function constructs the pagination structure based on the provided state and directives.
* It conditionally includes navigation buttons for first, previous, next, and last pages based on the state.
Expand Down Expand Up @@ -113,8 +113,8 @@ export const PaginationDefaultSlotStructure = (slotContext: PaginationContext) =
* Pagination component that renders a navigation element for paginated content.
* It uses the {@link useWidgetWithConfig} hook to create a pagination widget with the provided props.
*
* @param {Partial<PaginationProps>} props - The properties for the Pagination component.
* @returns {JSX.Element} The rendered pagination navigation element.
* @param props - The properties for the Pagination component.
* @returns The rendered pagination navigation element.
*/
export function Pagination(props: Partial<PaginationProps>) {
const widgetContext = useWidgetWithConfig(createPagination, props, 'pagination', {
Expand Down
8 changes: 4 additions & 4 deletions react/bootstrap/src/components/progressbar/progressbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {createProgressbar} from './progressbar.gen';
/**
* Renders a progress bar component with customizable appearance and behavior.
*
* @param {ProgressbarContext} slotContext - The context containing the state and properties for the progress bar.
* @param slotContext - The context containing the state and properties for the progress bar.
*
* @returns {JSX.Element} The rendered progress bar component.
* @returns The rendered progress bar component.
*/
export const ProgressbarDefaultSlotStructure = (slotContext: ProgressbarContext) => {
const {striped, animated, type} = slotContext.state;
Expand All @@ -27,9 +27,9 @@ export const ProgressbarDefaultSlotStructure = (slotContext: ProgressbarContext)
/**
* Progressbar component that utilizes the {@link useWidgetWithConfig} hook to create a progress bar widget.
*
* @param {Partial<ProgressbarProps>} props - The properties to configure the progress bar.
* @param props - The properties to configure the progress bar.
*
* @returns {JSX.Element} A div element containing the progress bar with appropriate ARIA directives and slot content.
* @returns A div element containing the progress bar with appropriate ARIA directives and slot content.
*/
export const Progressbar = (props: Partial<ProgressbarProps>) => {
const widgetContext = useWidgetWithConfig(createProgressbar, props, 'progressbar', {
Expand Down
4 changes: 2 additions & 2 deletions react/bootstrap/src/components/rating/rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function Star({star, state, directive}: {star: StarContext; state: RatingState;
/**
* Rating component that displays a series of stars based on the provided state.
*
* @param {Partial<RatingProps>} props - The properties for the Rating component.
* @returns {JSX.Element} The rendered Rating component.
* @param props - The properties for the Rating component.
* @returns The rendered Rating component.
*
* @remarks
* This component uses the {@link useWidgetWithConfig} hook to initialize and configure the rating widget.
Expand Down
8 changes: 2 additions & 6 deletions react/bootstrap/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,12 @@ function Rows<Item>({slotContext}: {slotContext: SelectContext<Item>; menuId: st
* A generic Select component that provides a customizable dropdown selection interface.
*
* @template Item - The type of the items in the selection.
* @param {Partial<SelectProps<Item>>} props - The properties for the Select component.
* @returns {JSX.Element} The rendered Select component.
* @param props - The properties for the Select component.
* @returns The rendered Select component.
*
* @remarks
* This component uses a widget context to manage its state and directives. It supports
* custom badge labels and item labels through the widget configuration.
*
* @component
* @param {Partial<SelectProps<Item>>} props - The properties for the Select component.
* @returns {JSX.Element} The rendered Select component.
*/
export function Select<Item>(props: Partial<SelectProps<Item>>) {
const widgetContext = useWidgetWithConfig<SelectWidget<Item>>(createSelect, props, 'select', {
Expand Down
12 changes: 6 additions & 6 deletions react/bootstrap/src/components/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {createSlider} from './slider.gen';
* A functional component that renders a button element with a directive applied to it.
* The directive is provided through the `slotContext` parameter.
*
* @param {SliderSlotHandleContext} slotContext - The context object containing the directives and item for the slider handle.
* @returns {JSX.Element} A button element with the applied directive.
* @param slotContext - The context object containing the directives and item for the slider handle.
* @returns A button element with the applied directive.
*/
export const SliderDefaultSlotHandle = (slotContext: SliderSlotHandleContext) => {
return <button {...useDirective<{item: SliderHandle}>(slotContext.directives.handleDirective, {item: slotContext.item})}>&nbsp;</button>;
Expand Down Expand Up @@ -64,8 +64,8 @@ const CombinedLabel = (slotContext: SliderContext) => (
/**
* Renders the default slot structure for the Slider component.
*
* @param {SliderContext} slotContext - The context object containing state and directives for the slider.
* @returns {JSX.Element} The JSX element representing the default slot structure.
* @param slotContext - The context object containing state and directives for the slider.
* @returns The JSX element representing the default slot structure.
*
*/
export const SliderDefaultSlotStructure = (slotContext: SliderContext) => (
Expand Down Expand Up @@ -93,8 +93,8 @@ export const SliderDefaultSlotStructure = (slotContext: SliderContext) => (
/**
* Slider component that integrates with a widget context and renders a slot structure.
*
* @param {PropsWithChildren<Partial<SliderProps>>} props - The properties for the Slider component.
* @returns {JSX.Element} The rendered Slider component.
* @param props - The properties for the Slider component.
* @returns The rendered Slider component.
*
* The Slider component uses the {@link useWidgetWithConfig} hook to create a widget context with the provided
* configuration. It then applies the `sliderDirective` to a `div` element and renders the slot content
Expand Down
4 changes: 2 additions & 2 deletions react/bootstrap/src/components/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ToastCloseButtonNoHeader = (slotContext: ToastContext) => (
/**
* Renders the default slot structure for a Toast component.
*
* @param {ToastContext} slotContext - The context containing the state and properties for the Toast component.
* @returns {JSX.Element} The JSX element representing the default slot structure of the Toast.
* @param slotContext - The context containing the state and properties for the Toast component.
* @returns The JSX element representing the default slot structure of the Toast.
*/
export const ToastDefaultSlotStructure = (slotContext: ToastContext) => (
<>
Expand Down
Loading

0 comments on commit f29b4c9

Please sign in to comment.