From 2ed9356cffc42686140ee6b1133a703e1b74cfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Mon, 10 Jun 2024 17:55:44 +0200 Subject: [PATCH] fix lint warnings --- components/content-search/SearchItem.tsx | 10 ++-- components/content-search/index.tsx | 58 ++++++++++++++------- components/inner-block-slider/index.js | 2 + components/is-admin/index.tsx | 2 +- components/media-toolbar/index.tsx | 2 +- components/post-term-list/index.js | 2 +- components/post-title/index.tsx | 4 +- hooks/use-block-parent-attributes/index.ts | 2 +- hooks/use-has-selected-inner-block/index.ts | 2 +- hooks/use-is-plugin-active/index.ts | 5 +- hooks/use-on-click-outside.ts | 9 ++-- stores/icons/reducer.ts | 7 +-- 12 files changed, 60 insertions(+), 45 deletions(-) diff --git a/components/content-search/SearchItem.tsx b/components/content-search/SearchItem.tsx index 4bb29a8e..c3d6cac8 100644 --- a/components/content-search/SearchItem.tsx +++ b/components/content-search/SearchItem.tsx @@ -68,6 +68,11 @@ interface SearchItemProps { renderType?: (suggestion: Suggestion) => string; } +export function defaultRenderItemType(suggestion: Suggestion): string { + // Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label. + return suggestion.type === 'post_tag' ? 'tag' : suggestion.subtype; +} + const SearchItem: React.FC = ({ suggestion, onClick, @@ -127,9 +132,4 @@ const SearchItem: React.FC = ({ ); }; -export function defaultRenderItemType(suggestion: Suggestion): string { - // Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label. - return suggestion.type === 'post_tag' ? 'tag' : suggestion.subtype; -} - export default SearchItem; diff --git a/components/content-search/index.tsx b/components/content-search/index.tsx index 27a89001..b24a1ba1 100644 --- a/components/content-search/index.tsx +++ b/components/content-search/index.tsx @@ -116,8 +116,8 @@ const ContentSearch: React.FC = ({ fetchInitialResults, }) => { const [searchString, setSearchString] = useState(''); - const [searchQueries, setSearchQueries] = useState<{[key: string]: QueryCache}>({}); - const [selectedItem, setSelectedItem] = useState(null); + const [searchQueries, setSearchQueries] = useState<{ [key: string]: QueryCache }>({}); + const [selectedItem, setSelectedItem] = useState(null); const [currentPage, setCurrentPage] = useState(1); const [isFocused, setIsFocused] = useState(false); @@ -219,13 +219,16 @@ const ContentSearch: React.FC = ({ const normalizedResults = filterResults(result); if (mode === 'user') { - return normalizedResults.map((item) => ({ - id: item.id, - subtype: mode, - title: item.name || '', - type: mode, - url: item.link || '', - } as SearchResult)); + return normalizedResults.map( + (item) => + ({ + id: item.id, + subtype: mode, + title: item.name || '', + type: mode, + url: item.link || '', + }) as SearchResult, + ); } return normalizedResults; @@ -255,7 +258,7 @@ const ContentSearch: React.FC = ({ if (!searchQueries[preparedQuery] || searchQueries[preparedQuery].controller === 1) { setSearchQueries((queries) => { // New queries. - const newQueries: {[key: string]: QueryCache} = {}; + const newQueries: { [key: string]: QueryCache } = {}; // Remove errored or cancelled queries. Object.keys(queries).forEach((query) => { @@ -314,7 +317,7 @@ const ContentSearch: React.FC = ({ }) .then((results: Response) => { const totalPages = parseInt( - ( results.headers && results.headers.get('X-WP-TotalPages') ) || '0', + (results.headers && results.headers.get('X-WP-TotalPages')) || '0', 10, ); @@ -401,7 +404,11 @@ const ContentSearch: React.FC = ({ if (i === currentPage) { isLoading = false; - if ( searchQuery.totalPages && searchQuery.currentPage && searchQuery.totalPages > searchQuery.currentPage) { + if ( + searchQuery.totalPages && + searchQuery.currentPage && + searchQuery.totalPages > searchQuery.currentPage + ) { showLoadMore = true; } } @@ -424,9 +431,7 @@ const ContentSearch: React.FC = ({ useEffect(() => { document.addEventListener('mouseup', (e: MouseEvent) => { // Bail if anywhere inside search container is clicked. - if ( - searchContainer.current?.contains(e.target as Node) - ) { + if (searchContainer.current?.contains(e.target as Node)) { return; } @@ -436,7 +441,11 @@ const ContentSearch: React.FC = ({ return ( - + { @@ -454,7 +463,12 @@ const ContentSearch: React.FC = ({ {hasSearchString || hasInitialResults ? ( <> - {isLoading && currentPage === 1 && } + {isLoading && currentPage === 1 && ( + + )} {!isLoading && !hasSearchResults && (
  • = ({ {__('Nothing found.', '10up-block-components')}
  • )} - { - (!isLoading || currentPage > 1) && + {(!isLoading || currentPage > 1) && searchResults && searchResults.map((item, index) => { if (!item.title.length) { @@ -522,7 +535,12 @@ const ContentSearch: React.FC = ({ )} - {isLoading && currentPage > 1 && } + {isLoading && currentPage > 1 && ( + + )} ) : null}
    diff --git a/components/inner-block-slider/index.js b/components/inner-block-slider/index.js index 8eef2281..755b4c6e 100644 --- a/components/inner-block-slider/index.js +++ b/components/inner-block-slider/index.js @@ -1,3 +1,5 @@ +/* eslint-disable */ +// @ts-nocheck // eslint-disable-file import { useSelect, useDispatch } from '@wordpress/data'; import { useEffect, useState, useRef } from '@wordpress/element'; diff --git a/components/is-admin/index.tsx b/components/is-admin/index.tsx index 7d6a7f46..53083f8b 100644 --- a/components/is-admin/index.tsx +++ b/components/is-admin/index.tsx @@ -12,7 +12,7 @@ interface IsAdminProps { children: React.ReactNode; } -/** +/* * IsAdmin * * A wrapper component that checks wether the current user has admin capabilities diff --git a/components/media-toolbar/index.tsx b/components/media-toolbar/index.tsx index 1173dd94..5c9daeb9 100644 --- a/components/media-toolbar/index.tsx +++ b/components/media-toolbar/index.tsx @@ -26,7 +26,7 @@ interface MediaToolbarProps { id: number; } -/** +/* * MediaToolbar * * This is a helper component that adds the Media Replace Flow diff --git a/components/post-term-list/index.js b/components/post-term-list/index.js index 6a4a074d..b06b3cfd 100644 --- a/components/post-term-list/index.js +++ b/components/post-term-list/index.js @@ -6,9 +6,9 @@ import { PostTaxonomiesHierarchicalTermSelector, PostTaxonomiesFlatTermSelector, } from '@wordpress/editor'; +import { Optional } from '@10up/block-components'; import { usePopover, usePost, useSelectedTerms, useTaxonomy } from '../../hooks'; -import { Optional } from '..'; import { PostTermContext } from './context'; import { ListItem, TermLink } from './item'; diff --git a/components/post-title/index.tsx b/components/post-title/index.tsx index c81b1645..bcd1f06d 100644 --- a/components/post-title/index.tsx +++ b/components/post-title/index.tsx @@ -4,7 +4,7 @@ import { useSelect } from '@wordpress/data'; import { usePost } from '../../hooks'; interface PostTitleProps { - tagName?: TElementType | keyof JSX.IntrinsicElements; + tagName: TElementType | keyof JSX.IntrinsicElements; } type PostTitlePropsWithOmit = PostTitleProps & @@ -20,7 +20,7 @@ export const PostTitle = ({ 'postType', postType, 'title', - postId, + postId as undefined | string, ); const titlePlaceholder = useSelect( diff --git a/hooks/use-block-parent-attributes/index.ts b/hooks/use-block-parent-attributes/index.ts index afe6e033..85ddb1a5 100644 --- a/hooks/use-block-parent-attributes/index.ts +++ b/hooks/use-block-parent-attributes/index.ts @@ -1,7 +1,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { store as blockEditorStore, useBlockEditContext } from '@wordpress/block-editor'; -/** +/* * useBlockParentAttributes * * allows you to easily interface with the attributes of the direct diff --git a/hooks/use-has-selected-inner-block/index.ts b/hooks/use-has-selected-inner-block/index.ts index af718cd4..772ea19e 100644 --- a/hooks/use-has-selected-inner-block/index.ts +++ b/hooks/use-has-selected-inner-block/index.ts @@ -1,7 +1,7 @@ import { useSelect } from '@wordpress/data'; import { useBlockEditContext, store as blockEditorStore } from '@wordpress/block-editor'; -/** +/* * useHasSelectedInnerBlock * Determine whether one of the inner blocks currently is selected */ diff --git a/hooks/use-is-plugin-active/index.ts b/hooks/use-is-plugin-active/index.ts index 594f7f5c..bf3c1b7b 100644 --- a/hooks/use-is-plugin-active/index.ts +++ b/hooks/use-is-plugin-active/index.ts @@ -7,9 +7,8 @@ const ACTIVE_STATUSES = ['active', 'network-active'] as const; /** * Custom hook to check if a plugin is active and whether its resolution has finished. * - * @param pluginName The name of the plugin to check. - * @returns A tuple containing two boolean values: the first indicating whether the plugin is active, - * and the second indicating whether the resolution for the plugin has finished. + * @param {string} pluginName The name of the plugin to check. + * @returns {[boolean, boolean]} A tuple with the first value being whether the plugin is active and the second value being whether the resolution has finished. */ export const useIsPluginActive = (pluginName: string) => { return useSelect( diff --git a/hooks/use-on-click-outside.ts b/hooks/use-on-click-outside.ts index 1f5fef38..8e8ff5d8 100644 --- a/hooks/use-on-click-outside.ts +++ b/hooks/use-on-click-outside.ts @@ -12,7 +12,7 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven const ref = useRefEffect( (element) => { if (!element) { - return; + return () => {}; } const listener = (event: MouseEvent | TouchEvent) => { // Do nothing if clicking ref's element or descendent elements @@ -25,7 +25,8 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven const ownerDocument = element.ownerDocument || document; const isRenderedInsideIframe = ownerDocument !== document; - const editorCanvasIframe = document.querySelector('[name="editor-canvas"]'); + const editorCanvasIframe = + document.querySelector('[name="editor-canvas"]'); const editorCanvasDocument = editorCanvasIframe?.contentDocument; ownerDocument.addEventListener('mousedown', listener); @@ -37,8 +38,8 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven document.addEventListener('mousedown', listener); document.addEventListener('touchstart', listener); - // If the element is rendered outside the editor canvas iframe, we need to listen to events on the editor canvas - // document as well to detect clicks inside the editor canvas. + // If the element is rendered outside the editor canvas iframe, we need to listen to events on the editor canvas + // document as well to detect clicks inside the editor canvas. } else if (editorCanvasDocument) { editorCanvasDocument.addEventListener('mousedown', listener); editorCanvasDocument.addEventListener('touchstart', listener); diff --git a/stores/icons/reducer.ts b/stores/icons/reducer.ts index 23b97ab1..a32c489f 100644 --- a/stores/icons/reducer.ts +++ b/stores/icons/reducer.ts @@ -3,13 +3,8 @@ import { IconSetAction } from './actions'; import { IconSet } from './types'; -/** +/* * Reducer managing the block style variations. - * - * @param {object} state Current state. - * @param {object} action Dispatched action. - * - * @returns {object} Updated state. */ export default function reducer( state: { iconSets: { [key: string]: IconSet } } = { iconSets: {} },