From f95f12d3215caf30f1f49e1d29c5826156914a33 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Sun, 16 May 2021 18:59:32 +0100 Subject: [PATCH] Fix es lint warnings (#4206) * Un-used PropTypes import * Avoid global and use ownerDocument * receiveCart return type * ignoreRestSiblings when destructuring for @typescript-eslint/no-unused-vars * Replace lodash find * Use global rather than window * Remove lodash map * move rule to overrides --- .eslintrc.js | 4 ++++ .../cart-checkout/product-summary/index.tsx | 1 - assets/js/base/components/price-slider/index.js | 8 ++++++-- assets/js/blocks/attribute-filter/edit.js | 9 ++++----- .../cart-checkout/cart/checkout-button/index.js | 14 ++++++-------- assets/js/data/cart/actions.ts | 6 ++++-- .../product-attribute-term-control/index.js | 7 +++++-- .../product-category-control/index.js | 5 +++-- .../editor-components/product-tag-control/index.js | 6 ++++-- assets/js/icons/stories/index.js | 13 +++++++------ assets/js/utils/attributes-query.js | 4 ++-- 11 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 182be0c3118..ae9a0f437ef 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -82,6 +82,10 @@ module.exports = { 'jsdoc/require-param': 'off', 'no-shadow': 'off', '@typescript-eslint/no-shadow': [ 'error' ], + '@typescript-eslint/no-unused-vars': [ + 'error', + { ignoreRestSiblings: true }, + ], }, }, { diff --git a/assets/js/base/components/cart-checkout/product-summary/index.tsx b/assets/js/base/components/cart-checkout/product-summary/index.tsx index b6e32093f95..4df04bb08d7 100644 --- a/assets/js/base/components/cart-checkout/product-summary/index.tsx +++ b/assets/js/base/components/cart-checkout/product-summary/index.tsx @@ -1,7 +1,6 @@ /** * External dependencies */ -import PropTypes from 'prop-types'; import Summary from '@woocommerce/base-components/summary'; import { blocksConfig } from '@woocommerce/block-settings'; diff --git a/assets/js/base/components/price-slider/index.js b/assets/js/base/components/price-slider/index.js index 90327c137f8..71163168db6 100644 --- a/assets/js/base/components/price-slider/index.js +++ b/assets/js/base/components/price-slider/index.js @@ -12,6 +12,7 @@ import { import PropTypes from 'prop-types'; import classnames from 'classnames'; import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount'; +import { isObject } from '@woocommerce/base-utils'; /** * Internal dependencies @@ -241,10 +242,13 @@ const PriceSlider = ( { ! hasValidConstraints && 'is-disabled' ); + const activeElement = isObject( minRange.current ) + ? minRange.current.ownerDocument.activeElement + : undefined; const minRangeStep = - minRange && document.activeElement === minRange.current ? stepValue : 1; + activeElement && activeElement === minRange.current ? stepValue : 1; const maxRangeStep = - maxRange && document.activeElement === maxRange.current ? stepValue : 1; + activeElement && activeElement === maxRange.current ? stepValue : 1; return (
diff --git a/assets/js/blocks/attribute-filter/edit.js b/assets/js/blocks/attribute-filter/edit.js index efd5c4bca47..c742f507619 100644 --- a/assets/js/blocks/attribute-filter/edit.js +++ b/assets/js/blocks/attribute-filter/edit.js @@ -15,7 +15,7 @@ import { } from '@wordpress/components'; import { Icon, server, external } from '@woocommerce/icons'; import { SearchListControl } from '@woocommerce/components'; -import { mapValues, toArray, sortBy, find } from 'lodash'; +import { mapValues, toArray, sortBy } from 'lodash'; import { getAdminLink, getSetting } from '@woocommerce/settings'; import HeadingToolbar from '@woocommerce/editor-components/heading-toolbar'; import BlockTitle from '@woocommerce/editor-components/block-title'; @@ -274,10 +274,9 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => { } const selectedId = selected[ 0 ].id; - const productAttribute = find( ATTRIBUTES, [ - 'attribute_id', - selectedId.toString(), - ] ); + const productAttribute = ATTRIBUTES.find( + ( attribute ) => attribute.attribute_id === selectedId.toString() + ); if ( ! productAttribute || attributeId === selectedId ) { return; diff --git a/assets/js/blocks/cart-checkout/cart/checkout-button/index.js b/assets/js/blocks/cart-checkout/cart/checkout-button/index.js index 56216da7ad3..3f96b5b7ae4 100644 --- a/assets/js/blocks/cart-checkout/cart/checkout-button/index.js +++ b/assets/js/blocks/cart-checkout/cart/checkout-button/index.js @@ -40,14 +40,12 @@ const CheckoutButton = ( { link } ) => { const { paymentMethods } = usePaymentMethods(); useEffect( () => { - // Add a listener for when the page is unloaded (specifically needed for Safari) - // to remove the spinner on the checkout button, so the saved page snapshot does not - // contain the spinner class. See https://archive.is/lOEW0 for why this is needed. + // Add a listener to remove the spinner on the checkout button, so the saved page snapshot does not + // contain the spinner class. See https://archive.is/lOEW0 for why this is needed for Safari. if ( - ! window || - typeof window.addEventListener !== 'function' || - typeof window.removeEventListener !== 'function' + typeof global.addEventListener !== 'function' || + typeof global.removeEventListener !== 'function' ) { return; } @@ -56,10 +54,10 @@ const CheckoutButton = ( { link } ) => { setShowSpinner( false ); }; - window.addEventListener( 'beforeunload', hideSpinner ); + global.addEventListener( 'pageshow', hideSpinner ); return () => { - window.removeEventListener( 'beforeunload', hideSpinner ); + global.removeEventListener( 'pageshow', hideSpinner ); }; }, [] ); diff --git a/assets/js/data/cart/actions.ts b/assets/js/data/cart/actions.ts index 330e748e5b6..c383cf81aff 100644 --- a/assets/js/data/cart/actions.ts +++ b/assets/js/data/cart/actions.ts @@ -28,14 +28,16 @@ import type { ResponseError } from '../types'; * * @param {CartResponse} response */ -export const receiveCart = ( response: CartResponse ) => { +export const receiveCart = ( + response: CartResponse +): { type: string; response: Cart } => { const cart = ( mapKeys( response, ( _, key ) => camelCase( key ) ) as unknown ) as Cart; return { type: types.RECEIVE_CART, response: cart, - } as const; + }; }; /** diff --git a/assets/js/editor-components/product-attribute-term-control/index.js b/assets/js/editor-components/product-attribute-term-control/index.js index 5351dd408ed..3b8d6bb9ad8 100644 --- a/assets/js/editor-components/product-attribute-term-control/index.js +++ b/assets/js/editor-components/product-attribute-term-control/index.js @@ -2,7 +2,6 @@ * External dependencies */ import { __, _n, sprintf } from '@wordpress/i18n'; -import { find } from 'lodash'; import PropTypes from 'prop-types'; import { SearchListControl, SearchListItem } from '@woocommerce/components'; import { SelectControl, Spinner } from '@wordpress/components'; @@ -139,7 +138,11 @@ const ProductAttributeTermControl = ( { list={ currentList } isLoading={ isLoading } selected={ selected - .map( ( { id } ) => find( currentList, { id } ) ) + .map( ( { id } ) => + currentList.find( + ( currentListItem ) => currentListItem.id === id + ) + ) .filter( Boolean ) } onChange={ onChange } renderItem={ renderItem } diff --git a/assets/js/editor-components/product-category-control/index.js b/assets/js/editor-components/product-category-control/index.js index b7927b17b6e..27e215e1b00 100644 --- a/assets/js/editor-components/product-category-control/index.js +++ b/assets/js/editor-components/product-category-control/index.js @@ -2,7 +2,6 @@ * External dependencies */ import { __, _n, sprintf } from '@wordpress/i18n'; -import { find } from 'lodash'; import PropTypes from 'prop-types'; import { SearchListControl, SearchListItem } from '@woocommerce/components'; import { SelectControl } from '@wordpress/components'; @@ -137,7 +136,9 @@ const ProductCategoryControl = ( { list={ categories } isLoading={ isLoading } selected={ selected - .map( ( id ) => find( categories, { id } ) ) + .map( ( id ) => + categories.find( ( category ) => category.id === id ) + ) .filter( Boolean ) } onChange={ onChange } renderItem={ renderItem } diff --git a/assets/js/editor-components/product-tag-control/index.js b/assets/js/editor-components/product-tag-control/index.js index ee5bca9c5e0..0f5fdff0f8a 100644 --- a/assets/js/editor-components/product-tag-control/index.js +++ b/assets/js/editor-components/product-tag-control/index.js @@ -3,7 +3,7 @@ */ import { __, _n, sprintf } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; -import { debounce, find } from 'lodash'; +import { debounce } from 'lodash'; import PropTypes from 'prop-types'; import { SearchListControl, SearchListItem } from '@woocommerce/components'; import { SelectControl } from '@wordpress/components'; @@ -132,7 +132,9 @@ class ProductTagControl extends Component { list={ list } isLoading={ loading } selected={ selected - .map( ( id ) => find( list, { id } ) ) + .map( ( { id } ) => + list.find( ( listItem ) => listItem.id === id ) + ) .filter( Boolean ) } onChange={ onChange } onSearch={ limitTags ? this.debouncedOnSearch : null } diff --git a/assets/js/icons/stories/index.js b/assets/js/icons/stories/index.js index 9f2d456cced..1c970983e48 100644 --- a/assets/js/icons/stories/index.js +++ b/assets/js/icons/stories/index.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { omitBy, omit, map } from 'lodash'; +import { omitBy, omit } from 'lodash'; import { useState } from '@wordpress/element'; /** @@ -22,6 +22,7 @@ const LibraryExample = () => { const filteredIcons = omitBy( availableIcons, ( _icon, name ) => { return ! name.includes( filter ); } ); + return (