Fix most of lint warnings (#50869)

* Fix number of lint warnings

* Add changelog

* Improve mocking value

* Fix exports

* Fix mock

* Bring back the empty array hook dependency
This commit is contained in:
Karol Manijak 2024-08-23 14:30:14 +02:00 committed by GitHub
parent 257762b564
commit 2f68f9265b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 37 additions and 29 deletions

View File

@ -104,22 +104,20 @@ const { state } = store< Store >( 'woocommerce/product-button', {
},
get addToCartText(): string {
const context = getContext();
const inTheCartText = state.inTheCartText || '';
// We use the temporary number of items when there's no animation, or the
// second part of the animation hasn't started.
if (
const showTemporaryNumber =
context.animationStatus === AnimationStatus.IDLE ||
context.animationStatus === AnimationStatus.SLIDE_OUT
) {
return getButtonText(
context.addToCartText,
state.inTheCartText!,
context.temporaryNumberOfItems
);
}
context.animationStatus === AnimationStatus.SLIDE_OUT;
const numberOfItems = showTemporaryNumber
? context.temporaryNumberOfItems
: state.numberOfItemsInTheCart;
return getButtonText(
context.addToCartText,
state.inTheCartText!,
state.numberOfItemsInTheCart
inTheCartText,
numberOfItems
);
},
get displayViewCart(): boolean {

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/

View File

@ -1,20 +1,20 @@
export * from './block-error-boundary';
export { default as BlockErrorBoundary } from './block-error-boundary';
export * from './button';
export * from './cart-checkout';
export * from './combobox';
export * from './country-input';
export * from './drawer';
export * from './filter-element-label';
export * from './filter-placeholder';
export * from './filter-reset-button';
export * from './filter-submit-button';
export * from './form';
export { default as FilterElementLabel } from './filter-element-label';
export { default as FilterPlaceholder } from './filter-placeholder';
export { default as FilterResetButton } from './filter-reset-button';
export { default as FilterSubmitButton } from './filter-submit-button';
export { default as FormComponent } from './form';
export * from './form-token-field';
export * from './load-more-button';
export * from './loading-mask';
export * from './noninteractive';
export { default as LoadingMask } from './loading-mask';
export { default as Noninteractive } from './noninteractive';
export * from './notice-banner';
export * from './pagination';
export { default as Pagination } from './pagination';
export * from './price-slider';
export * from './product-list';
export * from './product-name';

View File

@ -115,6 +115,7 @@ export const useCollection = < T >(
currentResourceValues,
currentQuery,
shouldSelect,
throwError,
]
);
// if selector was not bailed, then update current results. Otherwise return

View File

@ -9,7 +9,6 @@ import {
CartShippingRate,
CartShippingPackageShippingRate,
} from '@woocommerce/type-defs/cart';
import * as blockSettings from '@woocommerce/block-settings';
/**
* Internal dependencies
@ -38,6 +37,7 @@ jest.mock( '@woocommerce/block-settings', () => ( {
...jest.requireActual( '@woocommerce/block-settings' ),
LOCAL_PICKUP_ENABLED: true,
} ) );
const blockSettingsMock = jest.requireMock( '@woocommerce/block-settings' );
// Returns a rate object with the given values
const generateRate = (
@ -133,8 +133,7 @@ describe( 'isPackageRateCollectable', () => {
expect( hasCollectableRate( ratesToTest2 ) ).toBe( false );
} );
it( 'returns false for all rates if local pickup is disabled', () => {
// Attempt to assign to const or readonly variable error on next line is OK because it is mocked by jest
blockSettings.LOCAL_PICKUP_ENABLED = false;
blockSettingsMock.LOCAL_PICKUP_ENABLED = false;
const ratesToTest = [ 'flat_rate', 'local_pickup' ];
expect( hasCollectableRate( ratesToTest ) ).toBe( false );
} );

View File

@ -1,4 +1,4 @@
export * from './attributes';
export { default as attributes } from './attributes';
export * from './form-step-block';
export * from './form-step-heading';
export { default as FormStepHeading } from './form-step-heading';
export * from './additional-fields';

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/

View File

@ -1,3 +1,4 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/* eslint-disable @typescript-eslint/naming-convention */
/**
* External dependencies

View File

@ -18,7 +18,7 @@ export const getValidationError = ( state: State, errorId: string ) =>
*
* @param { State } state The current state.
* @param { string } errorId The error ID.
* @return { string } The validation error ID.
* @return { string | undefined } The validation error ID.
*/
export const getValidationErrorId = ( state: State, errorId: string ) => {
if ( ! state.hasOwnProperty( errorId ) || state[ errorId ].hidden ) {

View File

@ -78,7 +78,7 @@ export const SearchListItem = < T extends object = object >( {
if ( hasChildren && isSelected ) {
setExpandedPanelId( item.id as number );
}
}, [ item, hasChildren, isSelected ] );
}, [ item, hasChildren, isSelected, setExpandedPanelId ] );
const name = props.name || `search-list-item-${ controlId }`;
const id = `${ name }-${ item.id }`;

View File

@ -57,8 +57,8 @@ class FlakyTestsReporter implements Reporter {
this.failingTestCaseResults.set( testTitle, [] );
}
this.failingTestCaseResults
.get( testTitle )!
.push( formatTestResult( testCaseResult ) );
.get( testTitle )
?.push( formatTestResult( testCaseResult ) );
break;
}
case 'flaky': {

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Fix eslint warnings