From d53d375d09dd86a85ffb249de1c0cc7c3b3438bc Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 4 Jan 2022 13:35:25 +0100 Subject: refactor: avoid useless assignement before return statement --- src/utils/helpers/format.ts | 8 ++------ src/utils/hooks/useHeadingsTree.tsx | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/utils') diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 94aa2e7..44536dd 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -61,15 +61,11 @@ export const getFormattedPostPreview = (rawPost: RawArticlePreview) => { export const getFormattedPostsList = ( rawPosts: RawArticlePreview[] ): ArticlePreview[] => { - const formattedPosts = rawPosts + return rawPosts .filter((post) => Object.getOwnPropertyNames(post).length > 0) .map((post) => { - const formattedPost = getFormattedPostPreview(post); - - return formattedPost; + return getFormattedPostPreview(post); }); - - return formattedPosts; }; /** diff --git a/src/utils/hooks/useHeadingsTree.tsx b/src/utils/hooks/useHeadingsTree.tsx index 94d3b4b..745ba23 100644 --- a/src/utils/hooks/useHeadingsTree.tsx +++ b/src/utils/hooks/useHeadingsTree.tsx @@ -8,9 +8,7 @@ const useHeadingsTree = (wrapper: string) => { const getElementDepth = useCallback( (el: HTMLHeadingElement) => { - const elDepth = depths.findIndex((depth) => depth === el.localName); - - return elDepth; + return depths.findIndex((depth) => depth === el.localName); }, [depths] ); @@ -73,9 +71,8 @@ const useHeadingsTree = (wrapper: string) => { const getHeadingsList = useCallback( (headings: NodeListOf): Heading[] => { const formattedHeadings = formatHeadings(headings); - const headingsList = buildTree(formattedHeadings); - return headingsList; + return buildTree(formattedHeadings); }, [formatHeadings, buildTree] ); -- cgit v1.2.3