From b7534ea50049b114d8d98cac43646e71bdfb854c Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 28 Aug 2024 14:09:59 -0400 Subject: [PATCH] eslint: Enable `@wordpress/no-unused-vars-before-return` rule This rule tries to find cases where a variable is set to the result of a function call, but then an early return happens before that value is used. The idea being that we can likely save work by not calling a bunch of functions unnecessarily. Watch out for functions that have side effects, though. It may be that those need to be called even if the return value doesn't seem to be used. React hooks particularly fall into this category; when our `jetpack-js-tools/eslintrc/react` config is extended any functions beginning with "use" are ignored as such, but sometimes it seems we're forgetting to extend that. --- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../js-packages/ai-client/src/jwt/index.ts | 3 +- .../components/logo-presenter.tsx | 1 + .../src/logo-generator/components/prompt.tsx | 7 +-- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../src/I18nCheckPlugin.js | 1 + ...int-wordpress-no-unused-vars-before-return | 5 ++ .../storage-help-popover/index.jsx | 13 ++--- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../responsive-videos/responsive-videos.js | 3 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../blocks/contact-form/util/form-styles.js | 6 +-- .../forms/src/dashboard/inbox/response.js | 8 +-- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../src/sharing-modal/index.tsx | 2 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../masterbar/src/admin-menu/admin-menu.js | 7 +-- .../components/redeem-token-screen/index.jsx | 4 +- .../my-jetpack/_inc/utils/format-time.ts | 5 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ ...int-wordpress-no-unused-vars-before-return | 5 ++ .../src/js/classic-editor-share-limits.js | 2 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../components/record-meter/notice-box.jsx | 2 +- .../instant-search/components/search-app.jsx | 5 +- .../components/search-results.jsx | 2 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../admin/components/admin-page/index.tsx | 11 ++-- .../admin/components/video-list/index.tsx | 3 +- .../components/video-storage-meter/index.tsx | 1 + .../components/tracks-control/track-form.tsx | 6 +++ .../blocks/video/transforms/index.tsx | 7 +-- ...int-wordpress-no-unused-vars-before-return | 5 ++ projects/plugins/beta/src/admin/updates.js | 11 ++-- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../components/step-label/index.tsx | 2 +- .../_inc/client/at-a-glance/stats/index.jsx | 8 +-- .../components/popover/docs/example.jsx | 2 +- .../client/components/settings-card/index.jsx | 51 ++++++++++--------- .../jetpack/_inc/client/discussion/index.jsx | 8 +-- .../jetpack/_inc/client/earn/index.jsx | 6 +-- .../jetpack/_inc/client/newsletter/index.jsx | 4 +- .../jetpack/_inc/client/performance/index.jsx | 8 +-- .../_inc/client/security/backups-scan.jsx | 8 +-- .../jetpack/_inc/client/security/index.jsx | 18 ++++--- .../jetpack/_inc/client/sharing/index.jsx | 8 +-- .../jetpack/_inc/client/sharing/publicize.jsx | 13 ++--- .../client/state/recommendations/reducer.js | 2 +- .../jetpack/_inc/client/traffic/index.jsx | 8 +-- .../jetpack/_inc/client/writing/index.jsx | 8 +-- ...int-wordpress-no-unused-vars-before-return | 5 ++ .../components/ai-assistant-bar/index.tsx | 12 ++--- .../extensions/jetpack-contact-form/index.tsx | 5 +- .../extensions/blocks/donations/save.js | 3 +- .../extensions/blocks/donations/view.js | 2 +- .../extensions/blocks/eventbrite/save.js | 2 +- .../blocks/google-docs-embed/view.js | 3 +- .../extensions/blocks/mailchimp/view.js | 6 +-- .../jetpack/extensions/blocks/map/edit.js | 2 +- .../extensions/blocks/podcast-player/save.js | 4 +- .../extensions/blocks/podcast-player/view.js | 2 +- .../whatsapp-button/configuration.js | 8 +-- .../simple-payments/deprecated/v2/edit.js | 2 +- .../extensions/blocks/simple-payments/edit.js | 3 +- .../extensions/blocks/simple-payments/save.js | 3 +- .../blocks/story/player/store/effects.js | 7 +-- .../tiled-gallery/deprecated/v5/save.js | 2 +- .../tiled-gallery/deprecated/v6/save.js | 2 +- .../extensions/blocks/tiled-gallery/save.js | 2 +- .../extensions/blocks/videopress/save.js | 12 ++--- .../components/details-control/index.js | 9 ++-- .../breve/features/spelling-mistakes/index.ts | 11 ++-- .../extensions/plugins/payments/index.js | 9 ++-- .../jetpack/extensions/plugins/seo/index.js | 6 +-- .../shared/block-editor-asset-loader.js | 1 + .../responsive-videos/responsive-videos.js | 3 +- ...int-wordpress-no-unused-vars-before-return | 5 ++ ...t-wordpress-no-unused-vars-before-return#2 | 5 ++ .../src/js/components/severity/index.jsx | 12 ++--- .../plugins/protect/src/js/state/selectors.js | 6 +-- tools/js-tools/eslintrc/base.js | 1 - 81 files changed, 295 insertions(+), 189 deletions(-) create mode 100644 projects/js-packages/ai-client/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/js-packages/i18n-check-webpack-plugin/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/backup/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/classic-theme-helper/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/forms/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/masterbar/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/my-jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/publicize/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/search/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/packages/videopress/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/plugins/beta/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/plugins/crm/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/plugins/jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return create mode 100644 projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return#2 diff --git a/projects/js-packages/ai-client/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/js-packages/ai-client/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/js-packages/ai-client/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/js-packages/ai-client/src/jwt/index.ts b/projects/js-packages/ai-client/src/jwt/index.ts index eaa463ca5a281..7166e0ea5048a 100644 --- a/projects/js-packages/ai-client/src/jwt/index.ts +++ b/projects/js-packages/ai-client/src/jwt/index.ts @@ -49,8 +49,6 @@ export default async function requestJwt( { siteId = siteId || window.JP_CONNECTION_INITIAL_STATE.siteSuffix; expirationTime = expirationTime || JWT_TOKEN_EXPIRATION_TIME; - const isSimple = isSimpleSite(); - // Trying to pick the token from localStorage const token = localStorage.getItem( JWT_TOKEN_ID ); let tokenData: TokenDataProps | null = null; @@ -70,6 +68,7 @@ export default async function requestJwt( { let data: TokenDataEndpointResponseProps; + const isSimple = isSimpleSite(); if ( ! isSimple ) { data = await apiFetch( { /* diff --git a/projects/js-packages/ai-client/src/logo-generator/components/logo-presenter.tsx b/projects/js-packages/ai-client/src/logo-generator/components/logo-presenter.tsx index a57f43e634156..7248aad5b2bc7 100644 --- a/projects/js-packages/ai-client/src/logo-generator/components/logo-presenter.tsx +++ b/projects/js-packages/ai-client/src/logo-generator/components/logo-presenter.tsx @@ -177,6 +177,7 @@ export const LogoPresenter: React.FC< LogoPresenterProps > = ( { logoAccepted = false, siteId, } ) => { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const { isRequestingImage } = useLogoGenerator(); const { saveToLibraryError, logoUpdateError } = useRequestErrors(); diff --git a/projects/js-packages/ai-client/src/logo-generator/components/prompt.tsx b/projects/js-packages/ai-client/src/logo-generator/components/prompt.tsx index 8f75fd9cbbc91..596f49a2e96da 100644 --- a/projects/js-packages/ai-client/src/logo-generator/components/prompt.tsx +++ b/projects/js-packages/ai-client/src/logo-generator/components/prompt.tsx @@ -100,13 +100,14 @@ export const Prompt: React.FC< { initialPrompt?: string } > = ( { initialPrompt const onPromptPaste = ( event: React.ClipboardEvent< HTMLInputElement > ) => { event.preventDefault(); - // Paste plain text only - const text = event.clipboardData.getData( 'text/plain' ); - const selection = window.getSelection(); if ( ! selection || ! selection.rangeCount ) { return; } + + // Paste plain text only + const text = event.clipboardData.getData( 'text/plain' ); + selection.deleteFromDocument(); const range = selection.getRangeAt( 0 ); range.insertNode( document.createTextNode( text ) ); diff --git a/projects/js-packages/i18n-check-webpack-plugin/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/js-packages/i18n-check-webpack-plugin/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..6066aa6b93883 --- /dev/null +++ b/projects/js-packages/i18n-check-webpack-plugin/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Add eslint-disable for a false positive of `@wordpress/no-unused-vars-before-return`. + + diff --git a/projects/js-packages/i18n-check-webpack-plugin/src/I18nCheckPlugin.js b/projects/js-packages/i18n-check-webpack-plugin/src/I18nCheckPlugin.js index 1309260725c9d..574473273efdc 100644 --- a/projects/js-packages/i18n-check-webpack-plugin/src/I18nCheckPlugin.js +++ b/projects/js-packages/i18n-check-webpack-plugin/src/I18nCheckPlugin.js @@ -214,6 +214,7 @@ class I18nCheckPlugin { * @param {Map} moduleCache - Cache for processed modules. */ async #processAsset( compilation, filename, moduleCache ) { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- Grabbing current timestamp for timing. const t0 = Date.now(); const asset = compilation.getAsset( filename ); diff --git a/projects/packages/backup/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/backup/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/backup/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/backup/src/js/components/backup-storage-space/storage-help-popover/index.jsx b/projects/packages/backup/src/js/components/backup-storage-space/storage-help-popover/index.jsx index a2a827816646d..40d4506071b0e 100644 --- a/projects/packages/backup/src/js/components/backup-storage-space/storage-help-popover/index.jsx +++ b/projects/packages/backup/src/js/components/backup-storage-space/storage-help-popover/index.jsx @@ -14,12 +14,6 @@ const StorageHelpPopover = ( { className, forecastInDays } ) => { const addonSlug = useSelect( select => select( STORE_ID ).getStorageAddonOfferSlug() ); const siteSlug = useSelect( select => select( STORE_ID ).getCalypsoSlug() ); const adminUrl = useSelect( select => select( STORE_ID ).getSiteData().adminUrl ); - const storageUpgradeUrl = getProductCheckoutUrl( - addonSlug, - siteSlug, - `${ adminUrl }admin.php?page=jetpack-backup`, - true - ); const popover = useRef( null ); @@ -44,6 +38,13 @@ const StorageHelpPopover = ( { className, forecastInDays } ) => { return null; } + const storageUpgradeUrl = getProductCheckoutUrl( + addonSlug, + siteSlug, + `${ adminUrl }admin.php?page=jetpack-backup`, + true + ); + const forecastStatement = sprintf( /* translators: %d: is number of days of the forecast */ _n( diff --git a/projects/packages/classic-theme-helper/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/classic-theme-helper/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/classic-theme-helper/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/classic-theme-helper/src/responsive-videos/responsive-videos.js b/projects/packages/classic-theme-helper/src/responsive-videos/responsive-videos.js index 4885e82ac88a9..8e19a77112b0c 100644 --- a/projects/packages/classic-theme-helper/src/responsive-videos/responsive-videos.js +++ b/projects/packages/classic-theme-helper/src/responsive-videos/responsive-videos.js @@ -27,7 +27,6 @@ function responsiveVideos() { video.style.margin = videoMargin; } - const videoWidth = video.getAttribute( 'data-width' ); const videoHeight = video.getAttribute( 'data-height' ); const videoRatio = video.getAttribute( 'data-ratio' ); const containerWidth = video.parentElement.clientWidth; @@ -41,6 +40,8 @@ function responsiveVideos() { return; } + const videoWidth = video.getAttribute( 'data-width' ); + if ( parseInt( videoWidth, 10 ) > containerWidth ) { video.style.width = containerWidth + 'px'; video.style.height = containerWidth * parseFloat( videoRatio ) + 'px'; diff --git a/projects/packages/forms/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/forms/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/forms/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/forms/src/blocks/contact-form/util/form-styles.js b/projects/packages/forms/src/blocks/contact-form/util/form-styles.js index b79813b2cf2d6..2121e7026af28 100644 --- a/projects/packages/forms/src/blocks/contact-form/util/form-styles.js +++ b/projects/packages/forms/src/blocks/contact-form/util/form-styles.js @@ -40,13 +40,13 @@ window.jetpackForms.generateStyleVariables = function ( formNode ) { `; - const _document = window[ 'editor-canvas' ] ? window[ 'editor-canvas' ].document : document; - const bodyNode = _document.querySelector( 'body' ); - if ( ! formNode ) { return; } + const _document = window[ 'editor-canvas' ] ? window[ 'editor-canvas' ].document : document; + const bodyNode = _document.querySelector( 'body' ); + const styleProbe = _document.createElement( 'div' ); styleProbe.className = STYLE_PROBE_CLASS; styleProbe.style = STYLE_PROBE_STYLE; diff --git a/projects/packages/forms/src/dashboard/inbox/response.js b/projects/packages/forms/src/dashboard/inbox/response.js index 5bac162dc6d38..9e4254417b57e 100644 --- a/projects/packages/forms/src/dashboard/inbox/response.js +++ b/projects/packages/forms/src/dashboard/inbox/response.js @@ -32,16 +32,16 @@ const InboxResponse = ( { loading, response } ) => { setTimeout( () => setEmailCopied( false ), 3000 ); }, [ response, setEmailCopied ] ); + if ( ! loading && ! response ) { + return null; + } + const titleClasses = clsx( 'jp-forms__inbox-response-title', { 'is-email': response && ! response.author_name && response.author_email, 'is-ip': response && ! response.author_name && ! response.author_email, 'is-name': response && response.author_name, } ); - if ( ! loading && ! response ) { - return null; - } - return ( { const [ isOpen, setIsOpen ] = useState( false ); const closeModal = () => setIsOpen( false ); const { createNotice } = useDispatch( noticesStore ); - const [ shouldShowSuggestedTags, setShouldShowSuggestedTags ] = React.useState( true ); + const [ shouldShowSuggestedTags, setShouldShowSuggestedTags ] = useState( true ); useEffect( () => { // The first post will show a different modal. diff --git a/projects/packages/masterbar/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/masterbar/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/masterbar/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/masterbar/src/admin-menu/admin-menu.js b/projects/packages/masterbar/src/admin-menu/admin-menu.js index 013aa2a3c1b37..55dbadf7809f6 100644 --- a/projects/packages/masterbar/src/admin-menu/admin-menu.js +++ b/projects/packages/masterbar/src/admin-menu/admin-menu.js @@ -8,14 +8,15 @@ import './admin-menu.css'; */ function init() { const adminbar = document.querySelector( '#wpadminbar' ); - const wpwrap = document.querySelector( '#wpwrap' ); - const adminMenu = document.querySelector( '#adminmenu' ); - const dismissClass = 'dismissible-card__close-icon'; if ( ! adminbar ) { return; } + const wpwrap = document.querySelector( '#wpwrap' ); + const adminMenu = document.querySelector( '#adminmenu' ); + const dismissClass = 'dismissible-card__close-icon'; + /** * * @param value diff --git a/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx b/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx index 81504d09c53a2..1f36f88d03b0f 100644 --- a/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx @@ -24,12 +24,12 @@ export default function RedeemTokenScreen() { }, } ); - const tokenRedeemed = includesLifetimePurchase( purchases ); - if ( isLoading ) { return <>{ __( 'Checking gold status…', 'jetpack-my-jetpack' ) }; } + const tokenRedeemed = includesLifetimePurchase( purchases ); + return ( <> diff --git a/projects/packages/my-jetpack/_inc/utils/format-time.ts b/projects/packages/my-jetpack/_inc/utils/format-time.ts index 61f1d2ba07491..603cd13912ade 100644 --- a/projects/packages/my-jetpack/_inc/utils/format-time.ts +++ b/projects/packages/my-jetpack/_inc/utils/format-time.ts @@ -1,8 +1,6 @@ type FormatTimeFunction = ( hours: number ) => string; const formatTime: FormatTimeFunction = ( hours: number ) => { - const seconds = Math.floor( hours * 3600 ); - const minutes = Math.floor( seconds / 60 ); hours = Math.floor( hours ); const days = Math.floor( hours / 24 ); const years = Math.floor( days / 365 ); @@ -15,6 +13,9 @@ const formatTime: FormatTimeFunction = ( hours: number ) => { return `${ days }d ${ hours % 24 }h`; } + const seconds = Math.floor( hours * 3600 ); + const minutes = Math.floor( seconds / 60 ); + if ( hours > 0 ) { return `${ hours }h ${ minutes % 60 }m`; } diff --git a/projects/packages/my-jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/my-jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/my-jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/publicize/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/publicize/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/publicize/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/publicize/src/js/classic-editor-share-limits.js b/projects/packages/publicize/src/js/classic-editor-share-limits.js index ef21d3bf992e8..625633c921cbf 100644 --- a/projects/packages/publicize/src/js/classic-editor-share-limits.js +++ b/projects/packages/publicize/src/js/classic-editor-share-limits.js @@ -2,7 +2,6 @@ import jQuery from 'jquery'; jQuery( function ( $ ) { const state = window.jetpackSocialClassicEditorInitialState ?? {}; - const form = $( '#publicize-form' ); if ( ! state || state.sharesRemaining > state.numberOfConnections ) { return; @@ -20,6 +19,7 @@ jQuery( function ( $ ) { return; } + const form = $( '#publicize-form' ); form.click( function ( event ) { const target = $( event.target ); diff --git a/projects/packages/search/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/search/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/search/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/search/src/dashboard/components/record-meter/notice-box.jsx b/projects/packages/search/src/dashboard/components/record-meter/notice-box.jsx index 6e9d71d0c5863..0c11a3581cfc0 100644 --- a/projects/packages/search/src/dashboard/components/record-meter/notice-box.jsx +++ b/projects/packages/search/src/dashboard/components/record-meter/notice-box.jsx @@ -70,7 +70,6 @@ const getNotices = ( tierMaximumRecords = null ) => { */ export function NoticeBox( props ) { const activeNoticeIds = []; - const NOTICES = getNotices( props.tierMaximumRecords ); const DATA_NOT_VALID = '1', HAS_NOT_BEEN_INDEXED = '2', @@ -96,6 +95,7 @@ export function NoticeBox( props ) { return null; } + const NOTICES = getNotices( props.tierMaximumRecords ); const notice = NOTICES[ activeNoticeIds[ 0 ] ]; const noticeBoxClassName = notice.isImportant diff --git a/projects/packages/search/src/instant-search/components/search-app.jsx b/projects/packages/search/src/instant-search/components/search-app.jsx index e00e8bfc89054..dae5377b1e26f 100644 --- a/projects/packages/search/src/instant-search/components/search-app.jsx +++ b/projects/packages/search/src/instant-search/components/search-app.jsx @@ -126,9 +126,6 @@ class SearchApp extends Component { } getResultFormat = () => { - // Override the result format from the query string if result_format= is specified - const resultFormatQuery = getResultFormatQuery(); - // Override the result format if group static filter is selected, always use expanded. const isMultiSite = this.props.staticFilters && @@ -138,6 +135,8 @@ class SearchApp extends Component { return RESULT_FORMAT_EXPANDED; } + // Override the result format from the query string if result_format= is specified + const resultFormatQuery = getResultFormatQuery(); return resultFormatQuery || this.state.overlayOptions.resultFormat; }; diff --git a/projects/packages/search/src/instant-search/components/search-results.jsx b/projects/packages/search/src/instant-search/components/search-results.jsx index 47466673028fb..76f975445deda 100644 --- a/projects/packages/search/src/instant-search/components/search-results.jsx +++ b/projects/packages/search/src/instant-search/components/search-results.jsx @@ -49,7 +49,6 @@ class SearchResults extends Component { const { total = 0, corrected_query = false } = this.props.response; const hasQuery = this.props.searchQuery !== ''; const hasCorrectedQuery = corrected_query !== false; - const num = new Intl.NumberFormat().format( total ); const isMultiSite = this.props.staticFilters && this.props.staticFilters.group_id && @@ -67,6 +66,7 @@ class SearchResults extends Component { return __( 'No results found', 'jetpack-search-pkg' ); } + const num = new Intl.NumberFormat().format( total ); if ( hasQuery && hasCorrectedQuery ) { return sprintf( /* translators: %1$s: number of results. %2$s: the corrected search query. */ diff --git a/projects/packages/videopress/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/packages/videopress/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/packages/videopress/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/packages/videopress/src/client/admin/components/admin-page/index.tsx b/projects/packages/videopress/src/client/admin/components/admin-page/index.tsx index 51867437b2aa4..c64a71fefd16c 100644 --- a/projects/packages/videopress/src/client/admin/components/admin-page/index.tsx +++ b/projects/packages/videopress/src/client/admin/components/admin-page/index.tsx @@ -329,6 +329,7 @@ const UpgradeTrigger = ( { hasUsedVideo = false }: { hasUsedVideo: boolean } ) = const { adminUri, siteSuffix } = window.jetpackVideoPressInitialState; const { product, hasVideoPressPurchase, isFetchingPurchases } = usePlan(); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const { run } = useProductCheckoutWorkflow( { siteSuffix, productSlug: product.productSlug, @@ -337,7 +338,13 @@ const UpgradeTrigger = ( { hasUsedVideo = false }: { hasUsedVideo: boolean } ) = useBlogIdSuffix: true, } ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const { recordEventHandler } = useAnalyticsTracks( {} ); + + if ( hasVideoPressPurchase || isFetchingPurchases ) { + return null; + } + const onButtonClickHandler = recordEventHandler( 'jetpack_videopress_upgrade_trigger_link_click', run @@ -352,10 +359,6 @@ const UpgradeTrigger = ( { hasUsedVideo = false }: { hasUsedVideo: boolean } ) = 'jetpack-videopress-pkg' ); - if ( hasVideoPressPurchase || isFetchingPurchases ) { - return null; - } - return ( setSelected( current => { - const indexOf = current.indexOf( index ); - if ( check ) { return [ ...current, index ]; } else if ( ! check && indexOf > -1 ) { + const indexOf = current.indexOf( index ); return [ ...current.slice( 0, indexOf ), ...current.slice( indexOf + 1 ) ]; } diff --git a/projects/packages/videopress/src/client/admin/components/video-storage-meter/index.tsx b/projects/packages/videopress/src/client/admin/components/video-storage-meter/index.tsx index 2cc98688c61ea..cb1486e5b85c3 100644 --- a/projects/packages/videopress/src/client/admin/components/video-storage-meter/index.tsx +++ b/projects/packages/videopress/src/client/admin/components/video-storage-meter/index.tsx @@ -59,6 +59,7 @@ const VideoStorageMeter: React.FC< VideoStorageMeterProps > = ( { export const ConnectVideoStorageMeter = props => { const { storageUsed, uploadedVideoCount } = useVideos(); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const { features } = usePlan(); const { settings } = useVideoPressSettings(); const { siteType } = settings; diff --git a/projects/packages/videopress/src/client/block-editor/blocks/video/components/tracks-control/track-form.tsx b/projects/packages/videopress/src/client/block-editor/blocks/video/components/tracks-control/track-form.tsx index c66493e795de6..0a5491bc53cc9 100644 --- a/projects/packages/videopress/src/client/block-editor/blocks/video/components/tracks-control/track-form.tsx +++ b/projects/packages/videopress/src/client/block-editor/blocks/video/components/tracks-control/track-form.tsx @@ -48,9 +48,13 @@ export default function TrackForm( { tracks, errorMessage, }: TrackFormProps ): React.ReactElement { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const [ isSavingTrack, setIsSavingTrack ] = useState( false ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const [ trackExists, setTrackExists ] = useState( false ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const [ error, setError ] = useState( '' ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const [ replaceTrack, setReplaceTrack ] = useState( false ); const [ track, setTrack ] = useState< UploadTrackDataProps >( { kind: DEFAULT_KIND, @@ -89,12 +93,14 @@ export default function TrackForm( { return select( blockEditorStore ).getSettings().mediaUpload; }, [] ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const onSaveHandler = useCallback( () => { setIsSavingTrack( true ); setError( '' ); onSave( track ); }, [ track ] ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- @todo Start extending jetpack-js-tools/eslintrc/react in eslintrc, then we can remove this disable comment. const setSourceLanguage = useCallback( ( newSrcLang: string ) => { updateTrack( 'srcLang', newSrcLang ); diff --git a/projects/packages/videopress/src/client/block-editor/blocks/video/transforms/index.tsx b/projects/packages/videopress/src/client/block-editor/blocks/video/transforms/index.tsx index 503cd0a7430aa..f71d6619cb720 100644 --- a/projects/packages/videopress/src/client/block-editor/blocks/video/transforms/index.tsx +++ b/projects/packages/videopress/src/client/block-editor/blocks/video/transforms/index.tsx @@ -75,8 +75,6 @@ const transformToCoreEmbed = { blocks: [ 'core/embed' ], isMatch: ( attrs: VideoBlockAttributes ) => attrs?.src || attrs?.guid, transform: ( attrs: VideoBlockAttributes ) => { - const { updateBlockAttributes } = dispatch( blockEditorStore ); - const { getBlockAttributes } = select( blockEditorStore ); const { guid, src: srcFromAttr, className } = attrs; // Build the source (URL) in case it isn't defined. @@ -87,6 +85,9 @@ const transformToCoreEmbed = { return createBlock( 'core/embed' ); } + const { updateBlockAttributes } = dispatch( blockEditorStore ); + const { getBlockAttributes } = select( blockEditorStore ); + const block = createBlock( 'core/embed', { allowResponsive: true, providerNameSlug: 'videopress', @@ -130,11 +131,11 @@ const transformFromPastingVideoPressURL = { const url = textContent.trim(); const guid = pickGUIDFromUrl( url ); - const attrs = pickVideoBlockAttributesFromUrl( url ); if ( ! guid ) { return false; } + const attrs = pickVideoBlockAttributesFromUrl( url ); return createBlock( 'videopress/video', { guid, ...attrs } ); }, }; diff --git a/projects/plugins/beta/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/plugins/beta/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/plugins/beta/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/plugins/beta/src/admin/updates.js b/projects/plugins/beta/src/admin/updates.js index b76b0a6195b92..4e0823f4620dc 100644 --- a/projects/plugins/beta/src/admin/updates.js +++ b/projects/plugins/beta/src/admin/updates.js @@ -56,8 +56,6 @@ */ function onError( response ) { // Too bad we can't just use wp.updates.updatePluginError(), but it assumes it's on one of core's pages. - const $adminBarUpdates = $( '#wp-admin-bar-updates' ); - if ( ! wp.updates.isValidResponse( response, 'update' ) ) { return; } @@ -66,6 +64,8 @@ return; } + const $adminBarUpdates = $( '#wp-admin-bar-updates' ); + let $notice; if ( response.plugin ) { $notice = $updateNotices.find( '[data-plugin="' + response.plugin + '"]' ); @@ -100,9 +100,7 @@ * @param {Event} event - Event interface. */ $updateNotices.on( 'click', '[data-plugin] .update-branch', function ( event ) { - const $button = $( event.target ), - $notice = $button.parents( '.dops-card' ), - $adminBarUpdates = $( '#wp-admin-bar-updates' ); + const $button = $( event.target ); event.preventDefault(); @@ -110,6 +108,9 @@ return; } + const $notice = $button.parents( '.dops-card' ), + $adminBarUpdates = $( '#wp-admin-bar-updates' ); + $notice.removeClass( 'is-error' ); $notice.find( '.error-message' ).remove(); $button.removeClass( 'is-error' ).addClass( 'is-disabled' ); diff --git a/projects/plugins/crm/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/plugins/crm/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/plugins/crm/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/plugins/crm/src/js/components/automations-admin/components/step-label/index.tsx b/projects/plugins/crm/src/js/components/automations-admin/components/step-label/index.tsx index 93515f5ddf0ce..75b3abcaa937a 100644 --- a/projects/plugins/crm/src/js/components/automations-admin/components/step-label/index.tsx +++ b/projects/plugins/crm/src/js/components/automations-admin/components/step-label/index.tsx @@ -10,7 +10,6 @@ type StepLabelProps = { type LabelType = 'trigger' | 'condition' | 'action'; export const StepLabel: React.FC< StepLabelProps > = ( { type, className } ) => { - const wrapperClassNames = clsx( styles.label, styles[ `label--${ type }` ], className ); let label; switch ( type ) { @@ -30,5 +29,6 @@ export const StepLabel: React.FC< StepLabelProps > = ( { type, className } ) => return `${ type } is not implemented`; } + const wrapperClassNames = clsx( styles.label, styles[ `label--${ type }` ], className ); return
{ label }
; }; diff --git a/projects/plugins/jetpack/_inc/client/at-a-glance/stats/index.jsx b/projects/plugins/jetpack/_inc/client/at-a-glance/stats/index.jsx index 0ef2de6a71417..9cbf90f63a7f4 100644 --- a/projects/plugins/jetpack/_inc/client/at-a-glance/stats/index.jsx +++ b/projects/plugins/jetpack/_inc/client/at-a-glance/stats/index.jsx @@ -58,6 +58,10 @@ export class DashStats extends Component { const { siteAdminUrl, siteRawUrl, statsData } = this.props, s = []; + if ( 'object' !== typeof statsData[ unit ] ) { + return { chartData: s, totalViews: false }; + } + let totalViews = 0; const /* translators: short date format, such as: Jan 12. */ @@ -67,10 +71,6 @@ export class DashStats extends Component { /* translators: long month/year format, such as: January, 2021. */ longMonthYearFormat = __( 'F Y', 'jetpack' ); - if ( 'object' !== typeof statsData[ unit ] ) { - return { chartData: s, totalViews: false }; - } - forEach( statsData[ unit ].data, v => { const views = v[ 1 ]; let date = v[ 0 ], diff --git a/projects/plugins/jetpack/_inc/client/components/popover/docs/example.jsx b/projects/plugins/jetpack/_inc/client/components/popover/docs/example.jsx index 11739ea616e80..10035486cd7b8 100644 --- a/projects/plugins/jetpack/_inc/client/components/popover/docs/example.jsx +++ b/projects/plugins/jetpack/_inc/client/components/popover/docs/example.jsx @@ -142,11 +142,11 @@ class Popovers extends React.PureComponent { handleClick( i, positions ) { return event => { - const index = parseInt( event.currentTarget.innerText ); if ( i === 4 ) { return null; } + const index = parseInt( event.currentTarget.innerText ); this.setState( { showRubicPopover: ! this.state.showRubicPopover, rubicPosition: positions[ index ], diff --git a/projects/plugins/jetpack/_inc/client/components/settings-card/index.jsx b/projects/plugins/jetpack/_inc/client/components/settings-card/index.jsx index 5efa3dbad223f..8cd5ff2403d3a 100644 --- a/projects/plugins/jetpack/_inc/client/components/settings-card/index.jsx +++ b/projects/plugins/jetpack/_inc/client/components/settings-card/index.jsx @@ -95,16 +95,19 @@ export const SettingsCard = inprops => { } const getBanner = () => { - const upgradeLabel = _x( - 'Upgrade', - 'A caption for a button to upgrade an existing paid feature to a higher tier.', - 'jetpack' - ), - connectLabel = _x( - 'Connect', - 'A caption for a button to connect a user account to access paid features.', - 'jetpack' - ); + // We'll only need one of these at most. Avoid unnecessary i18n loading by using callbacks to fetch when needed. + const upgradeLabel = () => + _x( + 'Upgrade', + 'A caption for a button to upgrade an existing paid feature to a higher tier.', + 'jetpack' + ), + connectLabel = () => + _x( + 'Connect', + 'A caption for a button to connect a user account to access paid features.', + 'jetpack' + ); switch ( feature ) { case FEATURE_VIDEO_HOSTING_JETPACK: @@ -118,7 +121,7 @@ export const SettingsCard = inprops => { 'Connect your WordPress.com account to enable high-quality, ad-free video.', 'jetpack' ) } - callToAction={ connectLabel } + callToAction={ connectLabel() } plan={ getJetpackProductUpsellByFeature( FEATURE_VIDEO_HOSTING_JETPACK ) } feature={ feature } onClick={ handleConnectClick( feature ) } @@ -138,7 +141,7 @@ export const SettingsCard = inprops => { { __( 'Generate income with high-quality ads.', 'jetpack' ) } } - callToAction={ upgradeLabel } + callToAction={ upgradeLabel() } plan={ getJetpackProductUpsellByFeature( FEATURE_WORDADS_JETPACK ) } feature={ feature } onClick={ handleClickForTracking( feature ) } @@ -151,7 +154,7 @@ export const SettingsCard = inprops => { 'Connect your WordPress.com account to upgrade and generate income with high-quality ads.', 'jetpack' ) } - callToAction={ connectLabel } + callToAction={ connectLabel() } plan={ getJetpackProductUpsellByFeature( FEATURE_WORDADS_JETPACK ) } feature={ feature } onClick={ handleConnectClick( feature ) } @@ -172,7 +175,7 @@ export const SettingsCard = inprops => { 'jetpack' ) } plan={ getJetpackProductUpsellByFeature( FEATURE_SITE_BACKUPS_JETPACK ) } - callToAction={ upgradeLabel } + callToAction={ upgradeLabel() } feature={ feature } onClick={ handleClickForTracking( feature ) } href={ props.securityUpgradeUrl } @@ -185,7 +188,7 @@ export const SettingsCard = inprops => { 'jetpack' ) } plan={ getJetpackProductUpsellByFeature( FEATURE_SITE_BACKUPS_JETPACK ) } - callToAction={ connectLabel } + callToAction={ connectLabel() } feature={ feature } onClick={ handleConnectClick( feature ) } rna @@ -195,7 +198,7 @@ export const SettingsCard = inprops => { return props.hasConnectedOwner ? ( { /> ) : ( { return props.hasConnectedOwner ? ( { /> ) : ( { /> ) : ( { return props.hasConnectedOwner ? ( { /> ) : ( { return props.hasConnectedOwner ? ( { /> ) : ( ) : ( diff --git a/projects/plugins/jetpack/_inc/client/sharing/index.jsx b/projects/plugins/jetpack/_inc/client/sharing/index.jsx index e17aeb79c7b39..71358d5c95760 100644 --- a/projects/plugins/jetpack/_inc/client/sharing/index.jsx +++ b/projects/plugins/jetpack/_inc/client/sharing/index.jsx @@ -48,14 +48,14 @@ class Sharing extends Component { useAdminUiV1: this.props.useAdminUiV1, }; - const foundPublicize = this.props.isModuleFound( 'publicize' ), - foundSharing = this.props.isModuleFound( 'sharedaddy' ), - foundLikes = this.props.isModuleFound( 'likes' ); - if ( ! this.props.searchTerm && ! this.props.active ) { return null; } + const foundPublicize = this.props.isModuleFound( 'publicize' ), + foundSharing = this.props.isModuleFound( 'sharedaddy' ), + foundLikes = this.props.isModuleFound( 'likes' ); + if ( ! foundPublicize && ! foundSharing && ! foundLikes ) { return null; } diff --git a/projects/plugins/jetpack/_inc/client/sharing/publicize.jsx b/projects/plugins/jetpack/_inc/client/sharing/publicize.jsx index 596b1dc3318bd..3d145073afd7a 100644 --- a/projects/plugins/jetpack/_inc/client/sharing/publicize.jsx +++ b/projects/plugins/jetpack/_inc/client/sharing/publicize.jsx @@ -35,18 +35,23 @@ export const Publicize = withModuleSettingsFormHelpers( } render() { + const isActive = this.props.getOptionValue( 'publicize' ), + userCanManageModules = this.props.userCanManageModules; + + if ( ! userCanManageModules && ! isActive ) { + return null; + } + const unavailableInOfflineMode = this.props.isUnavailableInOfflineMode( 'publicize' ), isLinked = this.props.isLinked, isOfflineMode = this.props.isOfflineMode, siteRawUrl = this.props.siteRawUrl, blogID = this.props.blogID, siteAdminUrl = this.props.siteAdminUrl, - isActive = this.props.getOptionValue( 'publicize' ), hasPaidFeatures = this.props.hasPaidFeatures, hasSocialImageGenerator = this.props.hasSocialImageGenerator, isAtomicSite = this.props.isAtomicSite, activeFeatures = this.props.activeFeatures, - userCanManageModules = this.props.userCanManageModules, useAdminUiV1 = this.props.useAdminUiV1; const showUpgradeLink = @@ -84,10 +89,6 @@ export const Publicize = withModuleSettingsFormHelpers( ); }; - if ( ! userCanManageModules && ! isActive ) { - return null; - } - return ( getStepsForOnboarding( // Gets the step to show when one has not been set in the state yet. export const getInitialStep = state => { // Gets new recommendations from initial state. - const newRecommendations = getNewRecommendations( state ); const initialStep = getInitialRecommendationsStep( state ); const onboardingData = getOnboardingData( state ); @@ -720,6 +719,7 @@ export const getInitialStep = state => { } // Jump to a new recommendation if there is one to show. + const newRecommendations = getNewRecommendations( state ); if ( newRecommendations.length > 0 ) { return newRecommendations[ 0 ]; } diff --git a/projects/plugins/jetpack/_inc/client/traffic/index.jsx b/projects/plugins/jetpack/_inc/client/traffic/index.jsx index 8dd556d24b8ae..ef64dc772f02b 100644 --- a/projects/plugins/jetpack/_inc/client/traffic/index.jsx +++ b/projects/plugins/jetpack/_inc/client/traffic/index.jsx @@ -47,6 +47,10 @@ export class Traffic extends React.Component { siteUsesWpAdminInterface: this.props.siteUsesWpAdminInterface, }; + if ( ! this.props.searchTerm && ! this.props.active ) { + return null; + } + const foundSeo = this.props.isModuleFound( 'seo-tools' ), foundStats = this.props.isModuleFound( 'stats' ), foundShortlinks = this.props.isModuleFound( 'shortlinks' ), @@ -56,10 +60,6 @@ export class Traffic extends React.Component { foundAnalytics = this.props.isWoASite, foundBlaze = this.props.isModuleFound( 'blaze' ); - if ( ! this.props.searchTerm && ! this.props.active ) { - return null; - } - if ( ! foundSeo && ! foundStats && diff --git a/projects/plugins/jetpack/_inc/client/writing/index.jsx b/projects/plugins/jetpack/_inc/client/writing/index.jsx index 0a62e77f137eb..74dae5ac366d6 100644 --- a/projects/plugins/jetpack/_inc/client/writing/index.jsx +++ b/projects/plugins/jetpack/_inc/client/writing/index.jsx @@ -33,6 +33,10 @@ export class Writing extends React.Component { getModuleOverride: this.props.getModuleOverride, }; + if ( ! this.props.searchTerm && ! this.props.active ) { + return null; + } + const found = [ 'carousel', 'copy-post', @@ -48,10 +52,6 @@ export class Writing extends React.Component { 'blocks', ].some( this.props.isModuleFound ); - if ( ! this.props.searchTerm && ! this.props.active ) { - return null; - } - if ( ! found ) { return null; } diff --git a/projects/plugins/jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/plugins/jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..e7445aa43dba5 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/components/ai-assistant-bar/index.tsx b/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/components/ai-assistant-bar/index.tsx index 75fbb13963429..7feceb389a151 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/components/ai-assistant-bar/index.tsx +++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/components/ai-assistant-bar/index.tsx @@ -82,8 +82,6 @@ export default function AiAssistantBar( { const inputRef = useRef< HTMLInputElement >( null ); const { tracks } = useAnalytics(); - const connected = isUserConnected(); - const { inputValue, setInputValue, isVisible, assistantAnchor } = useContext( AiAssistantUiContext ); @@ -108,10 +106,6 @@ export default function AiAssistantBar( { const showGuideLine = requestingState === 'suggesting' || requestingState === 'done'; - const placeholder = __( 'Ask Jetpack AI to create your form', 'jetpack' ); - - const loadingPlaceholder = __( 'Creating your form. Please wait a few moments.', 'jetpack' ); - const { removeNotice } = useDispatch( noticesStore ); const handleSend = useCallback( () => { @@ -245,6 +239,12 @@ export default function AiAssistantBar( { return null; } + const placeholder = __( 'Ask Jetpack AI to create your form', 'jetpack' ); + + const loadingPlaceholder = __( 'Creating your form. Please wait a few moments.', 'jetpack' ); + + const connected = isUserConnected(); + // Assistant bar component. const AiAssistantBarComponent = (
diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/index.tsx b/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/index.tsx index 0895c729cc4be..70cc5d206e27c 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/index.tsx +++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/jetpack-contact-form/index.tsx @@ -42,14 +42,15 @@ export function useIsPossibleToExtendJetpackFormBlock( clientId: '', } ): boolean { - // Check if the AI Assistant block is registered. - const isBlockRegistered = getBlockType( 'jetpack/ai-assistant' ); const { isModuleActive } = useModuleStatus( 'contact-form' ); if ( ! isModuleActive ) { return false; } + // Check if the AI Assistant block is registered. + const isBlockRegistered = getBlockType( 'jetpack/ai-assistant' ); + if ( ! isBlockRegistered ) { return false; } diff --git a/projects/plugins/jetpack/extensions/blocks/donations/save.js b/projects/plugins/jetpack/extensions/blocks/donations/save.js index 149f50aa6b79d..1cfb13354651b 100644 --- a/projects/plugins/jetpack/extensions/blocks/donations/save.js +++ b/projects/plugins/jetpack/extensions/blocks/donations/save.js @@ -4,7 +4,6 @@ import { getDefaultTexts } from './utils'; const DEFAULT_TEXTS = getDefaultTexts(); const Save = ( { attributes } ) => { - const blockProps = useBlockProps.save(); const { fallbackLinkUrl, oneTimeDonation, monthlyDonation, annualDonation } = attributes; if ( @@ -16,6 +15,8 @@ const Save = ( { attributes } ) => { return null; } + const blockProps = useBlockProps.save(); + return (
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/view.js b/projects/plugins/jetpack/extensions/blocks/donations/view.js index 902349804b7b2..0c5e15157f3d0 100644 --- a/projects/plugins/jetpack/extensions/blocks/donations/view.js +++ b/projects/plugins/jetpack/extensions/blocks/donations/view.js @@ -69,7 +69,6 @@ class JetpackDonations { updateAmountFromCustomAmountInput() { const input = this.block.querySelector( '.donations__custom-amount .donations__amount-value' ); - const wrapper = this.block.querySelector( '.donations__custom-amount' ); const amount = input.innerHTML; if ( ! amount ) { @@ -81,6 +80,7 @@ class JetpackDonations { // Validates the amount. const currency = input.dataset.currency; const parsedAmount = parseAmount( amount, currency ); + const wrapper = this.block.querySelector( '.donations__custom-amount' ); if ( parsedAmount && parsedAmount >= minimumTransactionAmountForCurrency( currency ) ) { wrapper.classList.remove( 'has-error' ); this.amount = parsedAmount; diff --git a/projects/plugins/jetpack/extensions/blocks/eventbrite/save.js b/projects/plugins/jetpack/extensions/blocks/eventbrite/save.js index b04cffbacfb10..465ee7cbabe98 100644 --- a/projects/plugins/jetpack/extensions/blocks/eventbrite/save.js +++ b/projects/plugins/jetpack/extensions/blocks/eventbrite/save.js @@ -1,7 +1,6 @@ import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; export default function save( { attributes } ) { - const blockProps = useBlockProps.save(); const { eventId, style, url } = attributes; if ( ! eventId ) { @@ -20,5 +19,6 @@ export default function save( { attributes } ) { ); } + const blockProps = useBlockProps.save(); return
{ content }
; } diff --git a/projects/plugins/jetpack/extensions/blocks/google-docs-embed/view.js b/projects/plugins/jetpack/extensions/blocks/google-docs-embed/view.js index 0140ffe23af1c..49fbd4abbae4e 100644 --- a/projects/plugins/jetpack/extensions/blocks/google-docs-embed/view.js +++ b/projects/plugins/jetpack/extensions/blocks/google-docs-embed/view.js @@ -17,13 +17,14 @@ const showError = () => { //for each embed block select the iframe within embeds.forEach( embed => { const embedIframe = embed.querySelector( 'iframe' ); - const loader = embed.querySelector( '.loader' ); //if there isn't an iframe inside then bail if ( ! embedIframe ) { return; } + const loader = embed.querySelector( '.loader' ); + // Check if it's presentation block. const embedUrlComponents = embedIframe .getAttribute( 'src' ) diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/view.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/view.js index 4bd93055b57c9..09c0207d8bc14 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/view.js +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/view.js @@ -65,13 +65,13 @@ function activateSubscription( block, blogId ) { emailField.addEventListener( 'input', handleEmailValidation( form, emailField ) ); form.addEventListener( 'submit', e => { e.preventDefault(); + if ( ! validateEmail( form, emailField ) ) { + return; + } const email = emailField.value; const params = [].slice .call( form.querySelectorAll( 'input[type=hidden].mc-submit-param' ) ) .reduce( ( accumulator, node ) => ( { ...accumulator, [ node.name ]: node.value } ), {} ); - if ( ! validateEmail( form, emailField ) ) { - return; - } block.classList.add( 'is-processing' ); emailField.removeEventListener( 'input', handleEmailValidation( form, emailField ) ); processingEl.classList.add( 'is-visible' ); diff --git a/projects/plugins/jetpack/extensions/blocks/map/edit.js b/projects/plugins/jetpack/extensions/blocks/map/edit.js index 9369304288f25..e5758c3475e1f 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/map/edit.js @@ -149,10 +149,10 @@ const MapEdit = ( { }; const addPoint = point => { - const newPoints = points.slice( 0 ); if ( points.some( existingPoint => existingPoint.id === point.id ) ) { return; } + const newPoints = points.slice( 0 ); newPoints.push( point ); setAttributes( { points: newPoints } ); setAddPointVisibility( false ); diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/save.js b/projects/plugins/jetpack/extensions/blocks/podcast-player/save.js index 972ac0873de23..ab3390f8fa5f2 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/save.js +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/save.js @@ -2,12 +2,12 @@ import { useBlockProps } from '@wordpress/block-editor'; import clsx from 'clsx'; export default function save( { attributes } ) { - const blockProps = useBlockProps.save(); - const { url } = attributes; if ( ! url || url === '' ) { return; } + + const blockProps = useBlockProps.save(); return ( { + if ( undefined === newPhoneNumber || newPhoneNumber.length < 1 ) { + return false; + } + // No alphabetical characters but allow dots, dashes, and brackets. // These will be stripped for the WhatsApp API (only numbers), but retain // them in the UI for a more readable number for the user. const phoneNumberRegEx = RegExp( /^[+]?[\s./0-9]*[(]?[0-9]{1,4}[)]?[-\s./0-9]*$/, 'g' ); - if ( undefined === newPhoneNumber || newPhoneNumber.length < 1 ) { - return false; - } - return phoneNumberRegEx.test( countryCode.replace( /\D/g, '' ) + newPhoneNumber ); }; diff --git a/projects/plugins/jetpack/extensions/blocks/simple-payments/deprecated/v2/edit.js b/projects/plugins/jetpack/extensions/blocks/simple-payments/deprecated/v2/edit.js index 4ce0f4f024d38..f10b7e37c09de 100644 --- a/projects/plugins/jetpack/extensions/blocks/simple-payments/deprecated/v2/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/simple-payments/deprecated/v2/edit.js @@ -244,7 +244,6 @@ class SimplePaymentsEdit extends Component { */ validatePrice = () => { const { currency, price } = this.props.attributes; - const { precision } = getCurrencyDefaults( currency ); if ( ! price || parseFloat( price ) === 0 ) { this.setState( { @@ -273,6 +272,7 @@ class SimplePaymentsEdit extends Component { return false; } + const { precision } = getCurrencyDefaults( currency ); if ( decimalPlaces( price ) > precision ) { if ( precision === 0 ) { this.setState( { diff --git a/projects/plugins/jetpack/extensions/blocks/simple-payments/edit.js b/projects/plugins/jetpack/extensions/blocks/simple-payments/edit.js index 71d7cc5ba7b1e..7eab06f7efb53 100644 --- a/projects/plugins/jetpack/extensions/blocks/simple-payments/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/simple-payments/edit.js @@ -184,8 +184,6 @@ export const SimplePaymentsEdit = ( { * @return {boolean} True when valid, false when invalid */ const validatePrice = () => { - const { precision } = getCurrencyDefaults( currency ); - if ( ! price || parseFloat( price ) === 0 ) { setFieldPriceError( __( 'If you’re selling something, you need a price tag. Add yours here.', 'jetpack' ) @@ -208,6 +206,7 @@ export const SimplePaymentsEdit = ( { return false; } + const { precision } = getCurrencyDefaults( currency ); if ( decimalPlaces( price ) > precision ) { if ( precision === 0 ) { setFieldPriceError( diff --git a/projects/plugins/jetpack/extensions/blocks/simple-payments/save.js b/projects/plugins/jetpack/extensions/blocks/simple-payments/save.js index c9dc1a8b92e79..02f268429affc 100644 --- a/projects/plugins/jetpack/extensions/blocks/simple-payments/save.js +++ b/projects/plugins/jetpack/extensions/blocks/simple-payments/save.js @@ -3,7 +3,6 @@ import clsx from 'clsx'; import { formatPrice } from './utils'; export default function Save( { attributes } ) { - const blockProps = useBlockProps.save(); const { content, currency, @@ -20,6 +19,8 @@ export default function Save( { attributes } ) { return null; } + const blockProps = useBlockProps.save(); + return (
diff --git a/projects/plugins/jetpack/extensions/blocks/tiled-gallery/deprecated/v6/save.js b/projects/plugins/jetpack/extensions/blocks/tiled-gallery/deprecated/v6/save.js index bb3d9d5e9479d..408e9d766a920 100644 --- a/projects/plugins/jetpack/extensions/blocks/tiled-gallery/deprecated/v6/save.js +++ b/projects/plugins/jetpack/extensions/blocks/tiled-gallery/deprecated/v6/save.js @@ -7,7 +7,6 @@ import Layout from './layout'; export default function TiledGallerySave( { attributes } ) { const { imageFilter, images } = attributes; - const blockProps = useBlockProps.save(); if ( ! images.length ) { return null; @@ -21,6 +20,7 @@ export default function TiledGallerySave( { attributes } ) { roundedCorners, columnWidths, } = attributes; + const blockProps = useBlockProps.save(); return (
diff --git a/projects/plugins/jetpack/extensions/blocks/tiled-gallery/save.js b/projects/plugins/jetpack/extensions/blocks/tiled-gallery/save.js index b6de36d32d354..acaf2c8287102 100644 --- a/projects/plugins/jetpack/extensions/blocks/tiled-gallery/save.js +++ b/projects/plugins/jetpack/extensions/blocks/tiled-gallery/save.js @@ -7,7 +7,6 @@ import Layout from './layout'; export default function TiledGallerySave( { attributes } ) { const { imageFilter, images } = attributes; - const blockProps = useBlockProps.save(); if ( ! images.length ) { return null; @@ -21,6 +20,7 @@ export default function TiledGallerySave( { attributes } ) { roundedCorners, columnWidths, } = attributes; + const blockProps = useBlockProps.save(); return (
diff --git a/projects/plugins/jetpack/extensions/blocks/videopress/save.js b/projects/plugins/jetpack/extensions/blocks/videopress/save.js index 6b7c550fbc18c..2eac00232653a 100644 --- a/projects/plugins/jetpack/extensions/blocks/videopress/save.js +++ b/projects/plugins/jetpack/extensions/blocks/videopress/save.js @@ -26,12 +26,6 @@ const VideoPressSave = CoreVideoSave => props => { } = {}, } = props; - const blockProps = useBlockProps.save( { - className: clsx( 'wp-block-video', className, videoPressClassNames, { - [ `align${ align }` ]: align, - } ), - } ); - if ( ! guid ) { /** * We return the element produced by the render so Gutenberg can add the block class when cloning the element. @@ -45,6 +39,12 @@ const VideoPressSave = CoreVideoSave => props => { return CoreVideoSave( props ); } + const blockProps = useBlockProps.save( { + className: clsx( 'wp-block-video', className, videoPressClassNames, { + [ `align${ align }` ]: align, + } ), + } ); + const url = getVideoPressUrl( guid, { autoplay, controls, diff --git a/projects/plugins/jetpack/extensions/blocks/videopress/video-chapters/components/details-control/index.js b/projects/plugins/jetpack/extensions/blocks/videopress/video-chapters/components/details-control/index.js index bf418485daff2..aad5a9b3d834c 100644 --- a/projects/plugins/jetpack/extensions/blocks/videopress/video-chapters/components/details-control/index.js +++ b/projects/plugins/jetpack/extensions/blocks/videopress/video-chapters/components/details-control/index.js @@ -18,6 +18,11 @@ const CHARACTERS_PER_LINE = 31; export default function DetailsControl( { isRequestingVideoItem } ) { const { attributes, setAttributes } = useBlockAttributes(); + + if ( ! isVideoChaptersEnabled ) { + return null; + } + const { title, description } = attributes; const isBeta = isBetaExtension( VIDEOPRESS_VIDEO_CHAPTERS_FEATURE ); @@ -33,10 +38,6 @@ export default function DetailsControl( { isRequestingVideoItem } ) { const descriptionControlRows = Math.min( maxRows, Math.max( rows, minRows ) ); - if ( ! isVideoChaptersEnabled ) { - return null; - } - const setTitleAttribute = newTitle => { setAttributes( { title: newTitle } ); }; diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts index 7175586da3dfb..e37d19b21407a 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts @@ -174,6 +174,12 @@ export const suggestSpellingFixes = ( export default function spellingMistakes( text: string ): Array< HighlightedText > { const highlightedTexts: Array< HighlightedText > = []; + const spellChecker = getSpellChecker(); + + if ( ! spellChecker ) { + return highlightedTexts; + } + // Regex to match words, including contractions and hyphenated words, possibly prefixed with special characters // \p{L} is a Unicode property that matches any letter in any language // \p{M} is a Unicode property that matches any character intended to be combined with another character @@ -184,11 +190,6 @@ export default function spellingMistakes( text: string ): Array< HighlightedText // Split hyphenated words into separate words as nspell doesn't work well with them .map( word => word.split( '-' ) ) .flat(); - const spellChecker = getSpellChecker(); - - if ( ! spellChecker ) { - return highlightedTexts; - } // To avoid highlighting the same word occurrence multiple times let searchStartIndex = 0; diff --git a/projects/plugins/jetpack/extensions/plugins/payments/index.js b/projects/plugins/jetpack/extensions/plugins/payments/index.js index a561e887206d6..2d8388627fbc0 100644 --- a/projects/plugins/jetpack/extensions/plugins/payments/index.js +++ b/projects/plugins/jetpack/extensions/plugins/payments/index.js @@ -9,16 +9,17 @@ import { currencyDollar } from '@wordpress/icons'; const PaymentsPostPublish = () => { const { tracks } = useAnalytics(); - const paymentInfoUrl = getRedirectUrl( 'wpcom-payments-donations' ); - const trackClick = () => { - tracks.recordEvent( 'jetpack_editor_payments_post_publish_click' ); - }; const postType = useSelect( select => select( editorStore ).getCurrentPostType(), [] ); if ( 'page' !== postType ) { return null; } + const paymentInfoUrl = getRedirectUrl( 'wpcom-payments-donations' ); + const trackClick = () => { + tracks.recordEvent( 'jetpack_editor_payments_post_publish_click' ); + }; + return ( { const { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } = useModuleStatus( 'seo-tools' ); - const requiredPlan = getRequiredPlan( 'advanced-seo' ); - const canShowUpsell = isAtomicSite() || isSimpleSite(); - const isViewable = useSelect( select => { const postTypeName = select( editorStore ).getCurrentPostType(); const postTypeObject = select( coreStore ).getPostType( postTypeName ); @@ -42,6 +39,9 @@ const Seo = () => { return null; } + const requiredPlan = getRequiredPlan( 'advanced-seo' ); + const canShowUpsell = isAtomicSite() || isSimpleSite(); + const jetpackSeoPanelProps = { title: __( 'SEO', 'jetpack' ), }; diff --git a/projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js b/projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js index 2dfef987ce90b..6dfc68263cc6c 100644 --- a/projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js +++ b/projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js @@ -124,6 +124,7 @@ export function loadBlockEditorAssets( resources, callbacks, elementRef ) { const currentHead = currentDoc.getElementsByTagName( 'head' )[ 0 ]; resources.forEach( resource => { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return -- https://github.com/WordPress/gutenberg/issues/45049 const [ filename, fileExtension ] = resource.file.split( '/' ).pop().split( '.' ); if ( fileExtension === 'css' ) { diff --git a/projects/plugins/jetpack/modules/theme-tools/responsive-videos/responsive-videos.js b/projects/plugins/jetpack/modules/theme-tools/responsive-videos/responsive-videos.js index 4885e82ac88a9..8e19a77112b0c 100644 --- a/projects/plugins/jetpack/modules/theme-tools/responsive-videos/responsive-videos.js +++ b/projects/plugins/jetpack/modules/theme-tools/responsive-videos/responsive-videos.js @@ -27,7 +27,6 @@ function responsiveVideos() { video.style.margin = videoMargin; } - const videoWidth = video.getAttribute( 'data-width' ); const videoHeight = video.getAttribute( 'data-height' ); const videoRatio = video.getAttribute( 'data-ratio' ); const containerWidth = video.parentElement.clientWidth; @@ -41,6 +40,8 @@ function responsiveVideos() { return; } + const videoWidth = video.getAttribute( 'data-width' ); + if ( parseInt( videoWidth, 10 ) > containerWidth ) { video.style.width = containerWidth + 'px'; video.style.height = containerWidth * parseFloat( videoRatio ) + 'px'; diff --git a/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return b/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return new file mode 100644 index 0000000000000..7f30b15d5fb4c --- /dev/null +++ b/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Rearranged some variable assignments for new eslint `@wordpress/no-unused-vars-before-return` rule. Should be no changes to functionality. + + diff --git a/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return#2 b/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return#2 new file mode 100644 index 0000000000000..d004f38abd24f --- /dev/null +++ b/projects/plugins/protect/changelog/add-enable-eslint-wordpress-no-unused-vars-before-return#2 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Something was needed to avoid optimization breaking the i18n with the rearranged code, and these seemed like they could use some context anyway. + +Added context to i18n messages "Low", "High", and "Critical". diff --git a/projects/plugins/protect/src/js/components/severity/index.jsx b/projects/plugins/protect/src/js/components/severity/index.jsx index d9b52dacbd9f6..310cb6e233aa7 100644 --- a/projects/plugins/protect/src/js/components/severity/index.jsx +++ b/projects/plugins/protect/src/js/components/severity/index.jsx @@ -1,4 +1,4 @@ -import { __ } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; import styles from './styles.module.scss'; const severityClassNames = severity => { @@ -11,16 +11,12 @@ const severityClassNames = severity => { }; const severityText = severity => { - const critical = __( 'Critical', 'jetpack-protect' ); - const high = __( 'High', 'jetpack-protect' ); - const low = __( 'Low', 'jetpack-protect' ); - if ( severity >= 5 ) { - return critical; + return _x( 'Critical', 'Severity label for issues rated 5 or higher.', 'jetpack-protect' ); } else if ( severity >= 3 && severity < 5 ) { - return high; + return _x( 'High', 'Severity label for issues rated between 3 and 5.', 'jetpack-protect' ); } - return low; + return _x( 'Low', 'Severity label for issues rated below 3.', 'jetpack-protect' ); }; const ThreatSeverityBadge = ( { severity } ) => { diff --git a/projects/plugins/protect/src/js/state/selectors.js b/projects/plugins/protect/src/js/state/selectors.js index 5ef5d949f3dbe..307bfdaffecd5 100644 --- a/projects/plugins/protect/src/js/state/selectors.js +++ b/projects/plugins/protect/src/js/state/selectors.js @@ -9,7 +9,6 @@ import { SCAN_IN_PROGRESS_STATUSES, SCAN_STATUS_OPTIMISTICALLY_SCANNING } from ' */ const scanInProgress = state => { const { status, lastChecked, error } = selectors.getStatus( state ); - const unavailable = selectors.getScanIsUnavailable( state ); // When "optimistically" scanning, ignore any other status or error. if ( SCAN_STATUS_OPTIMISTICALLY_SCANNING === status ) { @@ -17,6 +16,7 @@ const scanInProgress = state => { } // If the scan is unavailable, scanning is not in progress. + const unavailable = selectors.getScanIsUnavailable( state ); if ( unavailable ) { return false; } @@ -47,8 +47,6 @@ const scanInProgress = state => { */ const scanError = state => { const { status, error, errorCode, errorMessage } = selectors.getStatus( state ); - const unavailable = selectors.getScanIsUnavailable( state ); - const isFetching = selectors.getStatusIsFetching( state ); // If the scan results include an error, return it. if ( error ) { @@ -56,6 +54,7 @@ const scanError = state => { } // If the scan is unavailable, return an error. + const unavailable = selectors.getScanIsUnavailable( state ); if ( unavailable ) { return { code: 'scan_unavailable', @@ -64,6 +63,7 @@ const scanError = state => { } // If there is no status and we are not requesting it, return an error. + const isFetching = selectors.getStatusIsFetching( state ); if ( ! status && ! isFetching ) { return { code: 'scan_unavailable', diff --git a/tools/js-tools/eslintrc/base.js b/tools/js-tools/eslintrc/base.js index 3b821a25d58c1..85b64fd93a5aa 100644 --- a/tools/js-tools/eslintrc/base.js +++ b/tools/js-tools/eslintrc/base.js @@ -219,6 +219,5 @@ module.exports = { '@wordpress/no-base-control-with-label-without-id': 'off', '@wordpress/no-global-active-element': 'off', '@wordpress/no-global-get-selection': 'off', - '@wordpress/no-unused-vars-before-return': 'off', }, };