Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit dc98a4b

Browse files
authored
Add anti yoda conditional eslint rule (#1142)
* add anti yoda rule * apply eslint fix to all existing yoda conditional uses
1 parent 6195e42 commit dc98a4b

File tree

12 files changed

+26
-25
lines changed

12 files changed

+26
-25
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ module.exports = {
1010
rules: {
1111
'@wordpress/dependency-group': 'off',
1212
'valid-jsdoc': 'off',
13+
yoda: [ 'error', 'never' ],
1314
},
1415
};

assets/js/atomic/components/product/rating/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ProductRating extends Component {
1616
const { product, className } = this.props;
1717
const rating = parseFloat( product.average_rating );
1818

19-
if ( ! Number.isFinite( rating ) || 0 === rating ) {
19+
if ( ! Number.isFinite( rating ) || rating === 0 ) {
2020
return null;
2121
}
2222

assets/js/base/components/price-slider/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const formatCurrencyForInput = (
5656
priceFormat,
5757
currencySymbol
5858
) => {
59-
if ( '' === value || undefined === value ) {
59+
if ( value === '' || undefined === value ) {
6060
return '';
6161
}
6262
const formattedNumber = parseInt( value, 10 );

assets/js/base/components/read-more/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ReadMore extends Component {
113113
return null;
114114
}
115115

116-
if ( false === clampEnabled ) {
116+
if ( clampEnabled === false ) {
117117
return (
118118
<div className={ className }>
119119
<div ref={ this.reviewContent }>{ content }</div>
@@ -123,7 +123,7 @@ class ReadMore extends Component {
123123

124124
return (
125125
<div className={ className }>
126-
{ ( ! isExpanded || null === clampEnabled ) && (
126+
{ ( ! isExpanded || clampEnabled === null ) && (
127127
<div
128128
ref={ this.reviewSummary }
129129
aria-hidden={ isExpanded }
@@ -132,7 +132,7 @@ class ReadMore extends Component {
132132
} }
133133
/>
134134
) }
135-
{ ( isExpanded || null === clampEnabled ) && (
135+
{ ( isExpanded || clampEnabled === null ) && (
136136
<div
137137
ref={ this.reviewContent }
138138
aria-hidden={ ! isExpanded }

assets/js/blocks/price-filter/edit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function( { attributes, setAttributes } ) {
5858
] }
5959
onChange={ ( value ) =>
6060
setAttributes( {
61-
showInputFields: 'editable' === value,
61+
showInputFields: value === 'editable',
6262
} )
6363
}
6464
/>
@@ -131,7 +131,7 @@ export default function( { attributes, setAttributes } ) {
131131

132132
return (
133133
<Fragment>
134-
{ 0 === PRODUCT_COUNT ? (
134+
{ PRODUCT_COUNT === 0 ? (
135135
noProductsPlaceholder()
136136
) : (
137137
<Fragment>

assets/js/blocks/product-categories/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const ProductCategoriesBlock = ( { attributes, setAttributes, name } ) => {
139139
] }
140140
onChange={ ( value ) =>
141141
setAttributes( {
142-
isDropdown: 'dropdown' === value,
142+
isDropdown: value === 'dropdown',
143143
} )
144144
}
145145
/>

assets/js/blocks/products/all-products/edit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Editor extends Component {
185185
allowedBlocks: Object.keys( this.blockMap ),
186186
};
187187

188-
if ( 0 !== this.props.attributes.layoutConfig.length ) {
188+
if ( this.props.attributes.layoutConfig.length !== 0 ) {
189189
InnerBlockProps.renderAppender = false;
190190
}
191191

@@ -248,7 +248,7 @@ class Editor extends Component {
248248
renderViewMode = () => {
249249
const { attributes } = this.props;
250250
const { layoutConfig } = attributes;
251-
const hasContent = layoutConfig && 0 !== layoutConfig.length;
251+
const hasContent = layoutConfig && layoutConfig.length !== 0;
252252
const blockTitle = this.getTitle();
253253
const blockIcon = this.getIcon();
254254

assets/js/blocks/reviews/editor-block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EditorBlock extends Component {
5050
);
5151
}
5252

53-
if ( 0 === reviews.length && ! isLoading ) {
53+
if ( reviews.length === 0 && ! isLoading ) {
5454
return <NoReviewsPlaceholder attributes={ attributes } />;
5555
}
5656

assets/js/blocks/reviews/frontend-block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const FrontendBlock = ( {
2626
} ) => {
2727
const { orderby } = attributes;
2828

29-
if ( 0 === reviews.length ) {
29+
if ( reviews.length === 0 ) {
3030
return null;
3131
}
3232

assets/js/components/product-attribute-control/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ProductAttributeControl = ( {
5757
isSelected={ expandedAttribute === item.id }
5858
onSelect={ onSelectAttribute }
5959
isSingle
60-
disabled={ '0' === item.count }
60+
disabled={ item.count === '0' }
6161
aria-expanded={ expandedAttribute === item.id }
6262
aria-label={ sprintf(
6363
_n(

0 commit comments

Comments
 (0)