Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ESLint config for TypeScript files #40584

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Notice } from '@wordpress/components';
import useFairUsageNoticeMessage from '../hooks/use-fair-usage-notice-message.js';
/**
* Types
*/
import type { ReactElement } from 'react';

type FairUsageNoticeProps = {
variant?: 'error' | 'muted';
Expand All @@ -13,7 +9,7 @@ type FairUsageNoticeProps = {
* The fair usage notice component.
* @param {FairUsageNoticeProps} props - Fair usage notice component props.
* @param {FairUsageNoticeProps.variant} props.variant - The variant of the notice to render.
* @return {ReactElement} the Notice component with the fair usage message.
* @return the Notice component with the fair usage message.
*/
export const FairUsageNotice = ( { variant = 'error' }: FairUsageNoticeProps ) => {
const useFairUsageNoticeMessageElement = useFairUsageNoticeMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ import {
ACTION_SET_IS_LOADING_HISTORY,
} from './constants.js';
import INITIAL_STATE from './initial-state.js';
import type {
AiFeatureStateProps,
LogoGeneratorStateProp,
RequestError,
TierLimitProp,
} from './types.js';
import type { AiFeatureStateProps, RequestError, TierLimitProp } from './types.js';
import type { SiteDetails } from '../types.js';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fixed ESLint warning


Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Annotation } from '.';

import './style-annotation.scss';

// eslint-disable-next-line jsdoc/require-returns
/**
* Custom tooltips plugin for uPlot.
*
* @param {Annotation[]} annotations - The periods to display in the tooltip.
* @param annotations - The periods to display in the tooltip.
*
* @return The plugin object.
*/
export function annotationsPlugin( annotations: Annotation[] ) {
let containerEl, annotationsContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Period } from '.';
/**
* Custom tooltips plugin for uPlot.
*
* @param {Period[]} periods - The periods to display in the tooltip.
* @return {object} The uPlot plugin object with hooks.
* @param periods - The periods to display in the tooltip.
* @return The uPlot plugin object with hooks.
*/
export function tooltipsPlugin( periods ) {
export function tooltipsPlugin( periods: Period[] ) {
const reactRoot = document.createElement( 'div' );
const container = document.createElement( 'div' );
let reactDom;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
10 changes: 1 addition & 9 deletions projects/packages/jetpack-mu-wpcom/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import makeBaseConfig, { typescriptFiles, makeEnvConfig } from 'jetpack-js-tools/eslintrc/base.mjs';
import makeBaseConfig, { makeEnvConfig } from 'jetpack-js-tools/eslintrc/base.mjs';

export default [
...makeBaseConfig( import.meta.url ),
Expand All @@ -9,12 +9,4 @@ export default [
'react/jsx-no-bind': 'off',
},
},
{
files: typescriptFiles,
rules: {
// Not needed for TypeScript.
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ShieldInactive from './assets/shield-inactive.svg';
import ShieldOff from './assets/shield-off.svg';
import ShieldSuccess from './assets/shield-success.svg';
import { useProtectTooltipCopy } from './use-protect-tooltip-copy';
import type { ReactElement, PropsWithChildren } from 'react';

export const AutoFirewallStatus = () => {
const slug = 'protect';
Expand All @@ -35,10 +34,10 @@ export const AutoFirewallStatus = () => {
/**
* WafStatus component
*
* @param {PropsWithChildren} props - The component props
* @param {'active' | 'inactive' | 'off'} props.status - The status of the WAF
* @param props - The component props
* @param props.status - The status of the WAF
*
* @return {ReactElement} rendered component
* @return rendered component
*/
function WafStatus( { status }: { status: 'active' | 'inactive' | 'off' } ) {
const slug = 'protect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import baseStyles from '../style.module.scss';
import ShieldOff from './assets/shield-off.svg';
import ShieldPartial from './assets/shield-partial.svg';
import { useProtectTooltipCopy } from './use-protect-tooltip-copy';
import type { ReactElement, PropsWithChildren } from 'react';

export const LoginsBlockedStatus = () => {
const slug = 'protect';
Expand Down Expand Up @@ -43,10 +42,10 @@ export const LoginsBlockedStatus = () => {
/**
* BlockedStatus component
*
* @param {PropsWithChildren} props - The component props
* @param {'active' | 'inactive' | 'off'} props.status - The status of Brute Force Protection
* @param props - The component props
* @param props.status - The status of Brute Force Protection
*
* @return {ReactElement} rendered component
* @return rendered component
*/
function BlockedStatus( { status }: { status: 'active' | 'inactive' | 'off' } ) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ShieldOff from './assets/shield-off.svg';
import ShieldPartial from './assets/shield-partial.svg';
import ShieldSuccess from './assets/shield-success.svg';
import { useProtectTooltipCopy } from './use-protect-tooltip-copy';
import type { PropsWithChildren, ReactElement } from 'react';

export const ScanAndThreatStatus = () => {
const slug = 'protect';
Expand Down Expand Up @@ -69,11 +68,11 @@ export const ScanAndThreatStatus = () => {
/**
* ThreatStatus component
*
* @param {PropsWithChildren} props - The component props
* @param {number} props.numThreats - The number of threats
* @param {number} props.criticalThreatCount - The number of critical threats
* @param props - The component props
* @param props.numThreats - The number of threats
* @param props.criticalThreatCount - The number of critical threats
*
* @return {ReactElement} rendered component
* @return rendered component
*/
function ThreatStatus( {
numThreats,
Expand Down Expand Up @@ -171,10 +170,10 @@ function ThreatStatus( {
/**
* ScanStatus component
*
* @param {PropsWithChildren} props - The component props
* @param {'success' | 'partial' | 'off'} props.status - The number of threats
* @param props - The component props
* @param props.status - The number of threats
*
* @return { ReactElement} rendered component
* @return rendered component
*/
function ScanStatus( { status }: { status: 'success' | 'partial' | 'off' } ) {
const tooltipContent = useProtectTooltipCopy();
Expand Down
9 changes: 2 additions & 7 deletions projects/packages/my-jetpack/_inc/data/use-simple-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { useMutation } from '@tanstack/react-query';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { useFetchingErrorNotice } from './notices/use-fetching-error-notice';
import type {
UseMutationOptions,
UseMutateFunction,
// This variable is being used as a type declaration
UseMutationResult,
} from '@tanstack/react-query';
import type { UseMutationOptions, UseMutateFunction } from '@tanstack/react-query';
import type { APIFetchOptions } from '@wordpress/api-fetch';

export type APIFetchOptionsWithQueryParams = APIFetchOptions & {
Expand All @@ -33,7 +28,7 @@ export type MutateCallback = UseMutateFunction<
* @param {APIFetchOptions} params.query - The options to be passed to the API fetch function for the mutation.
* @param {Pick<UseMutationOptions, 'onSuccess'>} [params.options] - Optional. Mutation options from react-query, currently supports only the 'onSuccess' option.
* @param {string} [params.errorMessage] - Optional. A custom error message that can be displayed if the mutation fails.
* @return {UseMutationResult<T>} The result object from the useMutation hook, containing data and state information about the mutation (e.g., isPending, isError).
* @return {import('@tanstack/react-query').UseMutationResult<T>} The result object from the useMutation hook, containing data and state information about the mutation (e.g., isPending, isError).
*/

type QueryParams< T, E, V > = {
Expand Down
4 changes: 2 additions & 2 deletions projects/packages/my-jetpack/_inc/data/use-simple-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';
import apiFetch from '@wordpress/api-fetch';
import { useFetchingErrorNotice } from './notices/use-fetching-error-notice';
import type { WP_Error } from './types';
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import type { UseQueryOptions } from '@tanstack/react-query';
import type { APIFetchOptions } from '@wordpress/api-fetch';

/**
Expand All @@ -18,7 +18,7 @@ import type { APIFetchOptions } from '@wordpress/api-fetch';
* @param {APIFetchOptions} params.query - The options to be passed to the API fetch function.
* @param {Pick<UseQueryOptions, 'enabled'>} [params.options] - Optional. Query options from react-query, currently supports only the 'enabled' option.
* @param {string} [params.errorMessage] - Optional. A custom error message that can be displayed if the query fails.
* @return {UseQueryResult<T>} The result object from the useQuery hook, containing data and state information about the query (e.g., isLoading, isError).
* @return {import('@tanstack/react-query').UseQueryResult<T>} The result object from the useQuery hook, containing data and state information about the query (e.g., isLoading, isError).
*/
type QueryParams = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, ThemeProvider, useBreakpointMatch } from '@automattic/jetpack-c
import { Modal } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import clsx from 'clsx';
import { useState, ReactNode } from 'react';
import { useState } from 'react';
/**
* Internal dependencies
*/
Expand All @@ -17,7 +17,7 @@ import { VideoThumbnailSelectorModalProps } from './types';
* Video Thumbnail Selector component
*
* @param {VideoThumbnailSelectorModalProps} props - Component props.
* @return {ReactNode} - VideoThumbnailSelector react component.
* @return - VideoThumbnailSelector react component.
*/
const VideoThumbnailSelectorModal = ( {
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import { usePlan } from '../../hooks/use-plan';
import useSelectVideoFiles from '../../hooks/use-select-video-files';
import styles from './style.module.scss';
import { VideoUploadAreaProps } from './types';
/**
* Types
*/
import type { ReactNode } from 'react';

/**
* Video Upload Area component
*
* @param {VideoUploadAreaProps} props - Component props.
* @return {ReactNode} - VideoUploadArea react component.
* @return - VideoUploadArea react component.
*/
const VideoUploadArea = ( { className, onSelectFiles }: VideoUploadAreaProps ) => {
const [ isSm ] = useBreakpointMatch( 'sm' );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed lints following ESLint rule changes for TS
4 changes: 2 additions & 2 deletions projects/plugins/crm/src/js/data/hooks/queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';
import { getAutomationWorkflows } from 'crm/data/query-functions';
import { Workflow } from 'crm/state/automations-admin/types';

/**
* Gets the Automation Workflows.
*
* @param {Function} hydrate - A function which takes an array of workflows and hydrates the store with them.
* @return {UseQueryResult} - The result of the query.
* @return {import('@tanstack/react-query').UseQueryResult} - The result of the query.
*/
export const useGetAutomationWorkflows = ( hydrate: ( workflows: Workflow[] ) => void ) =>
useQuery( {
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/crm/src/js/state/automations-admin/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Workflow, ServerPreparedWorkflow } from 'crm/state/automations-admin/types';
import { Workflow } from 'crm/state/automations-admin/types';

/**
* Gets a workflow which has been prepared for sending to the server.
*
* @param {Workflow} workflow - The workflow to prepare
* @return {ServerPreparedWorkflow} The prepared workflow
* @return {import('crm/state/automations-admin/types').ServerPreparedWorkflow} The prepared workflow
*/
export const getServerPreparedWorkflow = ( workflow: Workflow ) => {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Fixed lints following ESLint rule changes for TS
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import './style.scss';
import type { AiAssistantDropdownOnChangeOptionsArgProps } from './dropdown-content';
import type { ExtendedBlockProp } from '../../extensions/constants';
import type { PromptTypeProp } from '../../lib/prompt';
import type { ReactElement } from 'react';

const debug = debugFactory( 'jetpack-ai-assistant:dropdown' );

Expand All @@ -35,7 +34,7 @@ type AiAssistantBlockToolbarDropdownContentProps = {
/**
* The dropdown component with logic for the AI Assistant block.
* @param {AiAssistantBlockToolbarDropdownContentProps} props - The props.
* @return {ReactElement} The React content of the dropdown.
* @return The React content of the dropdown.
*/
function AiAssistantBlockToolbarDropdownContent( {
onClose,
Expand Down Expand Up @@ -165,7 +164,7 @@ type AiAssistantBlockToolbarDropdownProps = {
/**
* The AI Assistant dropdown component.
* @param {AiAssistantBlockToolbarDropdownProps} props - The props.
* @return {ReactElement} The AI Assistant dropdown component.
* @return The AI Assistant dropdown component.
*/
export default function AiAssistantBlockToolbarDropdown( {
blockType,
Expand Down
7 changes: 7 additions & 0 deletions tools/js-tools/eslintrc/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ export default function makeBaseConfig( configurl, opts = {} ) {
'error',
{ allowInterfaces: 'with-single-extends' },
],
// Mark types in jsdoc as used without reporting about any that are undefined.
'jsdoc/no-undefined-types': [ 'warn', { disableReporting: true } ],
// TS should mostly have the type set.
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-type': 'off',
// Let us use TS return type for better inference
'jsdoc/require-returns-type': 'off',
},
} ),
// Jest.
Expand Down
Loading