Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove temporary linting rules #2520

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .dev/tests/a11y/pa11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const config = {
/**
* Run Accessibility Test
*
* @param {string} url test URL
* @param {Object} config test configuration option
* @param {Function} [cb] Callback
* @param {string} url test URL
* @param {Object} config test configuration option
* @param {Function} [cb] Callback
* @return {Object} test results
*/
pa11y( url, config, ( error, results ) => {
Expand Down
15 changes: 3 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,13 @@ module.exports = {
assertFunctionNames: [ 'expect', 'cy.get', 'helpers.checkForBlockErrors' ],
} ],

// Temp override to slowly change everything
'sort-imports': [ 'warn', {
allowSeparatedGroups: true,
ignoreCase: true,
memberSyntaxSortOrder: [ 'all', 'single', 'multiple', 'none' ],
} ],
'jest/no-conditional-expect': [ 'warn' ],
'sort-keys': [ 'warn', 'asc', { natural: true } ],
'react/destructuring-assignment': [ 'warn', 'always' ],
'react/jsx-sort-props': [ 'warn', { ignoreCase: true } ],
'jsx-a11y/img-redundant-alt': [ 'warn' ],
'sort-imports': [ 'off' ],
'sort-keys': [ 'off' ],
'react/jsx-sort-props': [ 'off' ],
},
overrides: [
{
files: [ 'deprecated.js', 'save.js' ],
rules: { 'sort-keys': 'warn' },
},
],
};
29 changes: 15 additions & 14 deletions src/blocks/accordion/accordion-item/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import Inspector from './inspector';
import applyWithColors from './colors';
import Controls from './controls';
import Inspector from './inspector';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { Icon } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { InnerBlocks, RichText } from '@wordpress/block-editor';
import { Icon } from '@wordpress/components';

/**
* Constants
Expand Down Expand Up @@ -46,6 +46,7 @@ const AccordionItemEdit = ( props ) => {
attributes,
backgroundColor,
className,
clientId,
isSelected,
onReplace,
setAttributes,
Expand All @@ -63,10 +64,10 @@ const AccordionItemEdit = ( props ) => {
} = select( 'core/block-editor' );

const selectedBlock = getSelectedBlockClientId();
const anySelectedChildrenBlocks = anySelectedBlocks( getBlocks( props.clientId ), selectedBlock );
const anySelectedChildrenBlocks = anySelectedBlocks( getBlocks( clientId ), selectedBlock );

return {
isEditing: getSelectedBlockClientId() === props.clientId || anySelectedChildrenBlocks,
isEditing: getSelectedBlockClientId() === clientId || anySelectedChildrenBlocks,
};
} );

Expand All @@ -92,20 +93,13 @@ const AccordionItemEdit = ( props ) => {
) }
>
<RichText
tagName="p"
/* translators: Accordion is the block name */
placeholder={ __( 'Write accordion item title…', 'coblocks' ) }
value={ title }
className={ classnames(
'wp-block-coblocks-accordion-item__title', {
'has-background': backgroundColor.color,
'has-text-color': textColor.color,
}
) }
style={ {
backgroundColor: backgroundColor.color,
color: textColor.color,
} }
/* translators: Accordion is the block name */
onChange={ ( nextTitle ) => setAttributes( { title: nextTitle } ) }
onRemove={ ( forward ) => {
const hasEmptyTitle = typeof title === 'undefined' || ( typeof title !== 'undefined' && title.length === 0 );
Expand All @@ -114,15 +108,22 @@ const AccordionItemEdit = ( props ) => {
onReplace( [] );
}
} }
placeholder={ __( 'Write accordion item title…', 'coblocks' ) }
style={ {
backgroundColor: backgroundColor.color,
color: textColor.color,
} }
tagName="p"
value={ title }
/>
<Icon className={ classnames( { 'has-text-color': textColor.color } ) } style={ { color: textColor.color } } icon={ isEditing === true || attributes.open ? 'arrow-down' : 'arrow-right' } />
<Icon className={ classnames( { 'has-text-color': textColor.color } ) } icon={ isEditing === true || attributes.open ? 'arrow-down' : 'arrow-right' } style={ { color: textColor.color } } />

{ ( isEditing === true || attributes.open ) &&
<div className="wp-block-coblocks-accordion-item__content" style={ { borderColor: backgroundColor.color } }>
<InnerBlocks
__experimentalCaptureToolbars={ true }
template={ TEMPLATE }
templateInsertUpdatesSelection={ false }
__experimentalCaptureToolbars={ true }
/>
</div>
}
Expand Down
36 changes: 18 additions & 18 deletions src/blocks/accordion/accordion-item/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import applyWithColors from './colors';
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { InspectorControls, ContrastChecker, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, withFallbackStyles, ToggleControl } from '@wordpress/components';
import { ContrastChecker, InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, ToggleControl, withFallbackStyles } from '@wordpress/components';

/**
* Fallback styles
Expand All @@ -31,29 +31,29 @@ const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
* @param { Object } props
*/
const Inspector = ( props ) => {
const getDisplayOpenHelp = ( checked ) => {
return checked ? __( 'Accordion item is open by default.', 'coblocks' ) : __( 'Toggle to set this accordion item to be open by default.', 'coblocks' );
};

const setBorderColor = () => {
props.setAttributes( {
borderColor: props.backgroundColor.color,
} );

return setBackgroundColor;
};

const {
attributes,
setAttributes,
backgroundColor,
textColor,
fallbackBackgroundColor,
fallbackTextColor,
setAttributes,
setBackgroundColor,
setTextColor,
} = props;

const getDisplayOpenHelp = ( checked ) => {
return checked ? __( 'Accordion item is open by default.', 'coblocks' ) : __( 'Toggle to set this accordion item to be open by default.', 'coblocks' );
};

const setBorderColor = () => {
setAttributes( {
borderColor: backgroundColor.color,
} );

return setBackgroundColor;
};

const {
open,
} = attributes;
Expand All @@ -64,15 +64,13 @@ const Inspector = ( props ) => {
<PanelBody title={ __( 'Accordion Item settings', 'coblocks' ) }>
<ToggleControl
/* translators: visually display open as opposed to closed */
label={ __( 'Display as open', 'coblocks' ) }
checked={ !! open }
help={ getDisplayOpenHelp }
label={ __( 'Display as open', 'coblocks' ) }
onChange={ () => setAttributes( { open: ! open } ) }
/>
</PanelBody>
<PanelColorSettings
title={ __( 'Color settings', 'coblocks' ) }
initialOpen={ false }
colorSettings={ [
{
value: backgroundColor.color,
Expand All @@ -85,6 +83,8 @@ const Inspector = ( props ) => {
label: __( 'Text color', 'coblocks' ),
},
] }
initialOpen={ false }
title={ __( 'Color settings', 'coblocks' ) }
>
<ContrastChecker
{ ...{
Expand Down
27 changes: 17 additions & 10 deletions src/blocks/features/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { BackgroundStyles, BackgroundClasses, BackgroundVideo, BackgroundDropZone } from '../../components/background';
import { BackgroundClasses, BackgroundDropZone, BackgroundStyles, BackgroundVideo } from '../../components/background';
import applyWithColors from './colors';
import Inspector from './inspector';
import Controls from './controls';
Expand All @@ -20,7 +20,7 @@ import { compose } from '@wordpress/compose';
import { InnerBlocks } from '@wordpress/block-editor';
import { isBlobURL } from '@wordpress/blob';
import { Spinner } from '@wordpress/components';
import { withDispatch, withSelect, useSelect, useDispatch } from '@wordpress/data';
import { useDispatch, useSelect, withDispatch, withSelect } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -169,10 +169,10 @@ const Edit = ( props ) => {
{ isBlobURL( backgroundImg ) && <Spinner /> }
{ BackgroundVideo( attributes ) }
<InnerBlocks
template={ TEMPLATE }
__experimentalCaptureToolbars={ true }
allowedBlocks={ ALLOWED_BLOCKS }
template={ TEMPLATE }
templateInsertUpdatesSelection={ false }
__experimentalCaptureToolbars={ true }
/>
</div>
</GutterWrapper>
Expand All @@ -191,16 +191,23 @@ export default compose( [
} ) ),
// Ensure there is a minimum of one coblocks/feature innerBlock per column set.
( WrappedComponent ) => ( ownProps ) => {
const {
attributes,
clientId,
innerBlocks,
insertBlock,
} = ownProps;

// This is a newly added block if we have zero innerBlocks. We want the TEMPLATE definition to be used in this case.
if ( ownProps.innerBlocks.length > 0 ) {
const featureBlocksCount = ownProps.innerBlocks.reduce( ( acc, cur ) => acc + ( cur.name === 'coblocks/feature' ), 0 );
if ( innerBlocks.length > 0 ) {
const featureBlocksCount = innerBlocks.reduce( ( acc, cur ) => acc + ( cur.name === 'coblocks/feature' ), 0 );
// Add a new block if the count is less than the columns set.
// We don't need a loop here because this will trigger a component update as soon as we insert a block (triggering this HOC again).
if ( featureBlocksCount < ownProps.attributes.columns ) {
ownProps.insertBlock(
if ( featureBlocksCount < attributes.columns ) {
insertBlock(
createBlock( 'coblocks/feature' ),
ownProps.innerBlocks.length,
ownProps.clientId,
innerBlocks.length,
clientId,
false
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/features/feature/test/save.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable jest/no-conditional-expect */
/**
* External dependencies
*/
import '@testing-library/jest-dom/extend-expect';
import { createBlock, registerBlockType, serialize } from '@wordpress/blocks';
import '@testing-library/jest-dom/extend-expect';

/**
* Internal dependencies.
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/features/test/save.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable jest/no-conditional-expect */
/**
* External dependencies
*/
import '@testing-library/jest-dom/extend-expect';
import { createBlock, registerBlockType, serialize } from '@wordpress/blocks';
import '@testing-library/jest-dom/extend-expect';

/**
* Internal dependencies.
Expand Down
31 changes: 19 additions & 12 deletions src/blocks/food-and-drinks/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,21 @@ const FoodAndDrinksEdit = ( props ) => {
onChangeHeadingLevel={ onChangeHeadingLevel }
/>
<Inspector
attributes={ attributes }
activeStyle={ activeStyle }
attributes={ attributes }
layoutOptions={ layoutOptions }
onSetColumns={ setColumns }
onSetGutter={ setGutter }
onToggleImages={ toggleImages }
onTogglePrices={ togglePrices }
onUpdateStyle={ updateStyle }
onSetColumns={ setColumns }
onSetGutter={ setGutter }
/>
<div className={ classes }>
<InnerBlocks
__experimentalCaptureToolbars={ true }
allowedBlocks={ ALLOWED_BLOCKS }
template={ TEMPLATE }
templateInsertUpdatesSelection={ false }
__experimentalCaptureToolbars={ true }
/>
{ isSelected &&
<CustomAppender onClick={ insertNewItem } />
Expand Down Expand Up @@ -274,20 +274,27 @@ export default compose( [

// Ensure there is a minimum of one coblocks/food-item innerBlock per column set.
( WrappedComponent ) => ( ownProps ) => {
const {
attributes,
clientId,
innerBlocks,
insertBlock,
} = ownProps;

// This is a newly added block if we have zero innerBlocks. We want the TEMPLATE definition to be used in this case.
if ( ownProps.innerBlocks.length > 0 ) {
const foodItemBlocksCount = ownProps.innerBlocks.reduce( ( acc, cur ) => acc + ( cur.name === 'coblocks/food-item' ), 0 );
if ( innerBlocks.length > 0 ) {
const foodItemBlocksCount = innerBlocks.reduce( ( acc, cur ) => acc + ( cur.name === 'coblocks/food-item' ), 0 );

// Add a new block if the count is less than the columns set.
// We don't need a loop here because this will trigger a component update as soon as we insert a block (triggering this HOC again).
if ( foodItemBlocksCount < ownProps.attributes.columns ) {
ownProps.insertBlock(
if ( foodItemBlocksCount < attributes.columns ) {
insertBlock(
createBlock( 'coblocks/food-item', {
showImage: ownProps.attributes.showImages,
showPrice: ownProps.attributes.showPrices,
showImage: attributes.showImages,
showPrice: attributes.showPrices,
} ),
ownProps.innerBlocks.length,
ownProps.clientId,
innerBlocks.length,
clientId,
false
);
}
Expand Down
Loading