Skip to content

Commit

Permalink
eslint: Enable more lints from @wordpress/eslint-plugin (#39000)
Browse files Browse the repository at this point in the history
- no-alert: Enabled for new instances. Existing instances are ignored,
  some with todo comments.
- no-bitwise: Most existing instances were intentional. Replaced one
  `| 0` with `Math.floor()`.
- no-fallthrough: One error detected and fixed. Added fall-through
  comments to the rest.
- no-useless-computed-key: Auto-fixed them all.
- no-useless-return: Auto-fixed, then had to clean up some places where
  it left empty blocks or otherwise exposed weird code flows.
  • Loading branch information
anomiex authored Aug 22, 2024
1 parent ffbb646 commit befb138
Show file tree
Hide file tree
Showing 56 changed files with 118 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Remove ineffectual code paths and update comment.


Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ async function flagOss( payload, octokit ) {
}

// Check if PR author is org member
// Result is communicated by status code, and non-successful status codes throw.
// https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
try {
const orgMembershipRequest = await octokit.rest.orgs.checkMembershipForUser( {
await octokit.rest.orgs.checkMembershipForUser( {
org: owner.login,
username: head.user.login,
} );

if ( 204 === orgMembershipRequest.status ) {
return;
}
} catch ( error ) {
debug( `flag-oss: Adding OSS Citizen label to PR #${ number }` );
await octokit.rest.issues.addLabels( {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-alert -- ok for demo */
import { ExternalLink } from '@wordpress/components';
import Button from '../../button';
import Notice from '../index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const Typographies = args => (
);

Typographies.args = {
[ 'Text Instance' ]: '',
'Text Instance': '',
};
Typographies.parameters = {
docs: { source: { code: null } },
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/jetpack-components",
"version": "0.55.9",
"version": "0.55.10-alpha",
"description": "Jetpack Components Package",
"author": "Automattic",
"license": "GPL-2.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


2 changes: 2 additions & 0 deletions projects/js-packages/eslint-changed/tests/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ describe( 'bin/eslint-changed.js', () => {
[ '--eslint-orig', path.join( dirname, 'fixtures/no-new-errors.orig.json' ) ],
[ '--eslint-new', path.join( dirname, 'fixtures/no-new-errors.new.json' ) ],
];
// eslint-disable-next-line no-bitwise
for ( let i = ( 1 << argsets.length ) - 2; i > 0; i-- ) {
const args = [];
const missing = [];
for ( let j = 0; j < argsets.length; j++ ) {
// eslint-disable-next-line no-bitwise
if ( i & ( 1 << j ) ) {
args.push( ...argsets[ j ] );
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const RESTRICTIONS = {
minLength: 3,
},
},
[ 'instagram-business' ]: {
'instagram-business': {
requiresMedia: true,
allowedMediaTypes: [ 'image/jpg', 'image/jpeg', MP4, MOV, VIDEOPRESS ],
image: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function useDataSync<
try {
return datasync.getInitialValue();
} catch ( e ) {
return;
return undefined;
}
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


2 changes: 1 addition & 1 deletion projects/js-packages/social-logos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "social-logos",
"version": "3.1.6",
"version": "3.1.7-alpha",
"description": "A repository of all the social logos used on WordPress.com.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/social-logos/",
"bugs": {
Expand Down
1 change: 1 addition & 0 deletions projects/js-packages/social-logos/src/react/example.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-alert -- ok for demo */
import React, { useState } from 'react';
import { SocialLogo } from './social-logo';
import { SocialLogoData } from './social-logo-data';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ class JetpackOption extends Component {
if ( event.key === 'Enter' ) {
this.props.onAddOption( this.props.index );
event.preventDefault();
return;
}

if ( event.key === 'Backspace' && event.target.value === '' ) {
} else if ( event.key === 'Backspace' && event.target.value === '' ) {
this.props.onChangeOption( this.props.index );
event.preventDefault();
return;
}
}

Expand Down
8 changes: 2 additions & 6 deletions projects/packages/forms/tools/webpack.config.dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpac
module.exports = {
mode: jetpackWebpackConfig.mode,
entry: {
[ 'jetpack-forms-dashboard' ]: path.join( __dirname, '..', 'src/dashboard/index.js' ),
[ 'jetpack-forms-dashboard.wpcom' ]: path.join(
__dirname,
'..',
'src/dashboard/style.wpcom.scss'
),
'jetpack-forms-dashboard': path.join( __dirname, '..', 'src/dashboard/index.js' ),
'jetpack-forms-dashboard.wpcom': path.join( __dirname, '..', 'src/dashboard/style.wpcom.scss' ),
},
output: {
...jetpackWebpackConfig.output,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export const liveResizeModifier: liveResizeModifierFactory = (
name: 'liveResizeModifier',
enabled: true,
phase: 'main',
fn: () => {
return;
},
fn: () => {},
effect: arg0 => {
try {
const { state, instance } = arg0 as ModifierArgumentsWithObserversProp; // augment types here because we are mutating the properties on the argument that is passed in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable react/react-in-jsx-scope */
/* eslint-disable no-alert -- ok for demo */
import { arrowUp } from '@wordpress/icons';
import React from 'react';
import { PRODUCT_STATUSES } from '../../../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


4 changes: 2 additions & 2 deletions projects/packages/publicize/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpac
module.exports = [
{
entry: {
[ 'classic-editor-share-limits' ]: './src/js/classic-editor-share-limits.js',
[ 'classic-editor-connections' ]: './src/js/classic-editor-connections.js',
'classic-editor-share-limits': './src/js/classic-editor-share-limits.js',
'classic-editor-connections': './src/js/classic-editor-connections.js',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { generateDateRangeFilter, setDocumentCountsToZero } from '../api';
describe( 'generateDateRangeFilter', () => {
test( 'generates correct ranges for yearly date ranges', () => {
expect( generateDateRangeFilter( 'something', '2020-01-01 00:00:00', 'year' ) ).toEqual( {
range: { [ 'something' ]: { gte: '2020-01-01', lt: '2021-01-01' } },
range: { something: { gte: '2020-01-01', lt: '2021-01-01' } },
} );
} );
test( 'generates correct ranges for monthly date ranges', () => {
// Note that the next month value has been left padded; it's "02" instead of "2".
expect( generateDateRangeFilter( 'something', '2020-01-01 00:00:00', 'month' ) ).toEqual( {
range: { [ 'something' ]: { gte: '2020-01-01', lt: '2020-02-01' } },
range: { something: { gte: '2020-01-01', lt: '2020-02-01' } },
} );
// Note that the LT value is in 2021.
expect( generateDateRangeFilter( 'something', '2020-12-01 00:00:00', 'month' ) ).toEqual( {
range: { [ 'something' ]: { gte: '2020-12-01', lt: '2021-01-01' } },
range: { something: { gte: '2020-12-01', lt: '2021-01-01' } },
} );
} );
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const useDashboardVideos = () => {
setVideosQuery( {
search: searchFromSearchParam,
} );

return;
}
}, [ totalOfPages, page, pageFromSearchParam, search, searchFromSearchParam, tempPage.current ] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const InputWrapper = ( {
onChange: handleChangeEvent,
onKeyUp: handleKeyUpEvent,
disabled: disabled,
[ 'aria-disabled' ]: disabled,
'aria-disabled': disabled,
};

const isTextarea = inputProps?.type === 'textarea';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const useUnloadPrevent = ( {
// Note: The message only shows on older browsers, with a standard non-customizable message on current browsers
// ref https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#compatibility_notes
event.returnValue = message;
return;
};

window.addEventListener( 'beforeunload', beforeUnloadListener );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function VideoHoverPreviewControl( {
Math.min( MAX_LOOP_DURATION, videoDuration - previewAtTime )
);

const maxLoopDurationSeconds = ( ( maxLoopDuration / 10 ) | 0 ) / 100;
const maxLoopDurationSeconds = Math.floor( maxLoopDuration / 10 ) / 100;

const startingPointHelp = createInterpolateElement(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const useMetaUpdate = id => {
// check for code, if set
if ( 'success' !== result?.code ) {
reject();
return;
}
} )
.catch( e => reject( e ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Footer extends React.Component {
static displayName = 'Footer';

resetOnClick = () => {
// eslint-disable-next-line no-alert -- @todo Is there a better dialog we could use?
if ( window.confirm( __( 'This will reset all Jetpack options, are you sure?', 'jetpack' ) ) ) {
this.props.resetOptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class ClipboardButton extends React.Component {
}

displayPrompt = () => {
// eslint-disable-next-line no-alert -- Fallback if clipboard doesn't work, lets the user copy it manually.
window.prompt( this.props.prompt, this.props.text );
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class Navigation extends React.Component {
count: (
<span
className={ clsx( 'dops-section-nav-tab__update-badge', {
[ 'is-hidden' ]:
'is-hidden':
this.props.location.pathname.startsWith( '/recommendations' ) ||
! this.props.newRecommendationsCount,
} ) }
Expand Down
18 changes: 10 additions & 8 deletions projects/plugins/jetpack/_inc/client/my-plan/my-plan-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,18 @@ class MyPlanBody extends React.Component {
};

switch ( planClass ) {
// DEPRECATED: Daily and Real-time variations will soon be retired.
// Remove after all customers are migrated to new products.
case 'is-daily-security-plan':
case 'is-realtime-security-plan':
// fall through
case 'is-personal-plan':
case 'is-premium-plan':
case 'is-jetpack-starter-plan':
case 'is-security-t1-plan':
case 'is-security-t2-plan':
case 'is-business-plan':
case 'is-complete-plan':
// DEPRECATED: Daily and Real-time variations will soon be retired.
// Remove after all customers are migrated to new products.
case 'is-daily-security-plan':
case 'is-realtime-security-plan':
planCard = (
<div className="jp-landing__plan-features">
{ 'is-personal-plan' === planClass && getRewindVaultPressCard() }
Expand Down Expand Up @@ -623,6 +624,11 @@ class MyPlanBody extends React.Component {
);
break;

// DEPRECATED: Daily and Real-time variations will soon be retired.
// Remove after all customers are migrated to new products.
case 'is-daily-backup-plan':
case 'is-realtime-backup-plan':
// fall through
case 'is-free-plan':
case 'is-backup-t0-plan':
case 'is-backup-t1-plan':
Expand All @@ -632,10 +638,6 @@ class MyPlanBody extends React.Component {
case 'is-free-search-plan':
case 'is-jetpack-creator-plan':
case 'offline':
// DEPRECATED: Daily and Real-time variations will soon be retired.
// Remove after all customers are migrated to new products.
case 'is-daily-backup-plan':
case 'is-realtime-backup-plan':
planCard = (
<div className="jp-landing__plan-features">
{ jetpackBackupCard }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SummaryTextLink = ( { href, label, isHidden, onClick }: SummaryTextLinkPro
target="_blank"
href={ href }
onClick={ onClick }
className={ clsx( 'jp-summary-text-link', { [ 'is-hidden' ]: isHidden } ) }
className={ clsx( 'jp-summary-text-link', { 'is-hidden': isHidden } ) }
>
{ label }
<span className="jp-summary-text-link__icon dashicons dashicons-arrow-right-alt2"></span>
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/_inc/client/state/site/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const data = ( state = {}, action ) => {
if ( action.siteDiscount?.code ) {
return merge( {}, state, { site: { discount: action.siteDiscount } } );
}
return state;
case JETPACK_SITE_CONNECTED_PLUGINS_FETCH_RECEIVE:
return merge( {}, state, { site: { connectedPlugins: action.connectedPlugins } } );
case JETPACK_SITE_FEATURES_FETCH_RECEIVE:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Resolve new eslint sniffs. Should be no changes to functionality.


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Fix incorrect case fall-through in `_inc/client/state/site/reducer.js`.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
const handleGetSuggestion = ( ...args ) => {
getSuggestionFromOpenAI( ...args );
focusOnBlock();
return;
};

const handleChange = value => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AddressEdit extends Component {
preventEnterKey( event ) {
if ( event.key === 'Enter' ) {
event.preventDefault();
return;
}
}

Expand Down
Loading

0 comments on commit befb138

Please sign in to comment.