Skip to content

Commit 07ddbe7

Browse files
authored
Jetpack: Fix some JS lints ahead of the eslint 9 upgrade (#40503)
To make the eslint 9 upgrade PR smaller, let's fix some of the lints that it'll complain about ahead of time. Also, let's take the opportunity to fix the old non-jsdoc lints we had been ignoring (and the easily fixable jsdoc ones too).
1 parent 532bf2b commit 07ddbe7

File tree

132 files changed

+529
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+529
-589
lines changed
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Not loaded by default eslint, but we use tools/js-tools/load-eslint-ignore.js in .eslintrc to pull it in.
22

3-
/3rd-party/debug-bar/debug-bar.js
4-
/_inc/jetpack-modules.models.js
5-
/_inc/postmessage.js
6-
3+
/modules/carousel/swiper-bundle.js
74
/modules/custom-css/custom-css/js/core-customizer-css-preview.js
85
/modules/custom-css/custom-css/js/core-customizer-css.core-4.9.js
96
/modules/custom-css/custom-css/js/core-customizer-css.js

projects/plugins/jetpack/3rd-party/debug-bar/debug-bar.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* global jQuery, JSON */
1+
/* eslint no-var: "off" */
22

3-
( function( $ ) {
4-
$( document ).ready( function() {
5-
$( '.jetpack-search-debug-bar .json-toggle-wrap .toggle' ).click( function() {
3+
( function ( $ ) {
4+
$( document ).ready( function () {
5+
$( '.jetpack-search-debug-bar .json-toggle-wrap .toggle' ).click( function () {
66
var t = $( this ),
77
wrap = t.closest( '.json-toggle-wrap' ),
88
pre = wrap.find( 'pre' ),

projects/plugins/jetpack/_inc/client/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ module.exports = {
1414
allowedTextDomain: 'jetpack',
1515
},
1616
],
17+
'jsdoc/check-tag-names': [ 1, { definedTags: [ 'ssr-ready' ] } ],
1718
},
1819
};

projects/plugins/jetpack/_inc/client/admin.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import store from 'state/redux-store';
1313
accessibleFocus();
1414

1515
// Add dispatch and actionTypes to the window object so we can use it from the browser's console
16+
// eslint-disable-next-line no-undef -- webpack sets process.env.NODE_ENV
1617
if ( 'undefined' !== typeof window && process.env.NODE_ENV === 'development' ) {
1718
assign( window, {
1819
actionTypes: actionTypes,

projects/plugins/jetpack/_inc/client/components/chart/bar.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable jsx-a11y/click-events-have-key-events */
21
import clsx from 'clsx';
32
import PropTypes from 'prop-types';
43
import React from 'react';

projects/plugins/jetpack/_inc/client/components/dash-item/test/component.js

+2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ describe( 'DashItem', () => {
8282

8383
describe( 'when site is connected, is a PRO module, user can toggle', () => {
8484
// While the button is passed to <SectionHeader>, that doesn't render it.
85+
// eslint-disable-next-line jest/no-disabled-tests -- @todo Fix this, or remove it.
8586
it.skip( 'displays a PRO button for a PRO feature', () => {
8687
render( <DashItem { ...testProps } />, { initialState: buildInitialState() } );
8788
expect( screen.getByRole( 'link', { name: 'Paid' } ) ).toBeInTheDocument();
8889
} );
8990

9091
// Same.
92+
// eslint-disable-next-line jest/no-disabled-tests -- @todo Fix this, or remove it.
9193
it.skip( 'the button for a PRO feature is linked to #/plans', () => {
9294
render( <DashItem { ...testProps } />, { initialState: buildInitialState() } );
9395
expect( screen.getByRole( 'link', { name: 'Paid' } ) ).toHaveAttribute( 'href', '#/plans' );

projects/plugins/jetpack/_inc/client/components/jetpack-notices/plan-conflict-warning.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { __, sprintf } from '@wordpress/i18n';
2-
import SimpleNotice from 'components/notice';
32
import React from 'react';
43
import { connect } from 'react-redux';
54
import { withRouter } from 'react-router-dom';
5+
import SimpleNotice from 'components/notice';
66
import { getActiveSitePurchases } from 'state/site';
77

88
/**

projects/plugins/jetpack/_inc/client/components/modal/index.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Modal extends React.Component {
5555
// onDeactivate: this.maybeClose,
5656
initialFocus: this.props.initialFocus,
5757
} );
58-
} catch ( e ) {
58+
} catch {
5959
//noop
6060
}
6161
}
@@ -65,7 +65,7 @@ class Modal extends React.Component {
6565
jQuery( document ).unbind( 'keyup', this.handleEscapeKey );
6666
try {
6767
this.focusTrap.deactivate();
68-
} catch ( e ) {
68+
} catch {
6969
//noop
7070
}
7171
}

projects/plugins/jetpack/_inc/client/components/module-settings/connect-module-options.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { __, sprintf } from '@wordpress/i18n';
22
import { get } from 'lodash';
3+
import React from 'react';
34
import { connect } from 'react-redux';
45
import { isCurrentUserLinked } from 'state/connection';
56
import {
@@ -22,7 +23,7 @@ import {
2223
* High order component that connects to Jetpack modules'options
2324
* redux state selectors and action creators.
2425
*
25-
* @param {React.Component} Component The component to be connected to the state
26+
* @param {React.Component} Component - The component to be connected to the state
2627
* @return {[React.Component]} The component with some props connected to the state
2728
*/
2829
export function connectModuleOptions( Component ) {

projects/plugins/jetpack/_inc/client/components/module-settings/with-module-settings-form-helpers.jsx

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { connectModuleOptions } from 'components/module-settings/connect-module-options';
2-
import analytics from 'lib/analytics';
31
import { each, get, omit } from 'lodash';
42
import React from 'react';
3+
import { connectModuleOptions } from 'components/module-settings/connect-module-options';
4+
import analytics from 'lib/analytics';
55

66
/**
77
* High order component that provides a <form> with functionality
88
* to handle input values on the forms' own React component state.
99
*
10-
* @param {React.Component} InnerComponent The component with a top level form element
10+
* @param {React.Component} InnerComponent - The component with a top level form element
1111
* @return {[React.Component]} The component with new functionality
1212
*/
1313
export function withModuleSettingsFormHelpers( InnerComponent ) {
@@ -34,8 +34,8 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
3434
* Updates the list of form values to save, usually options to set or modules to activate.
3535
* Receives an object with key => value pairs to set multiple options or a string and a value to set a single option.
3636
*
37-
* @param {string|object} optionMaybeOptions options to update.
38-
* @param {*} optionValue value to set if it's a single option
37+
* @param {string|object} optionMaybeOptions - options to update.
38+
* @param {*} optionValue - value to set if it's a single option
3939
* @return {boolean} Always true
4040
*/
4141
updateFormStateOptionValue = ( optionMaybeOptions, optionValue = undefined ) => {
@@ -69,9 +69,9 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
6969
* If the module is active, only the option is added to the list of form values to send.
7070
* If it's inactive, an additional option stating that the module must be activated is added to the list.
7171
*
72-
* @param {String} module the module.
73-
* @param {String} moduleOption the option slug for the module.
74-
* @param {Boolean} deactivate whether to deactive the module too.
72+
* @param {string} module - the module.
73+
* @param {string} moduleOption - the option slug for the module.
74+
* @param {boolean} deactivate - whether to deactive the module too.
7575
*/
7676
updateFormStateModuleOption = ( module, moduleOption, deactivate = false ) => {
7777
this.trackSettingsToggle( module, moduleOption, ! this.getOptionValue( moduleOption ) );
@@ -102,7 +102,7 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
102102
/**
103103
* Instantly activate or deactivate a module.
104104
*
105-
* @param {String} module the module slug.
105+
* @param {string} module - the module slug.
106106
*/
107107
toggleModuleNow = module => {
108108
this.props.updateOptions( { [ module ]: ! this.getOptionValue( module ) } );
@@ -141,8 +141,8 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
141141
/**
142142
* Retrieves an option from an existing module, or from an array of modules
143143
* if the form was initialized with an array
144-
* @param {String} settingName the setting to get.
145-
* @param {String} module the module related to the setting.
144+
* @param {string} settingName - the setting to get.
145+
* @param {string} module - the module related to the setting.
146146
* @param {boolean} ignoreDisabledModules - Whether to ignore settings for disabled modules.
147147
* @return {*} the current value of the settings.
148148
*/
@@ -162,7 +162,7 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
162162
/**
163163
* Check if there are unsaved settings in the card.
164164
*
165-
* @return {Boolean} True if the form has unsaved changes.
165+
* @return {boolean} True if the form has unsaved changes.
166166
*/
167167
isDirty = () => {
168168
return !! Object.keys( this.state.options ).length;
@@ -171,27 +171,27 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
171171
/**
172172
* Checks if a setting is currently being saved.
173173
*
174-
* @param {String|Array} settings The settings to check for a current saving in progress
174+
* @param {string | Array} settings - The settings to check for a current saving in progress
175175
*
176-
* @return {Boolean} True if specified settings are being saved, false otherwise.
176+
* @return {boolean} True if specified settings are being saved, false otherwise.
177177
*/
178178
isSavingAnyOption = ( settings = '' ) => {
179179
return this.props.isUpdating( settings );
180180
};
181181

182182
/**
183183
* Tracks form submissions
184-
* @param {Object } options options passed to recordEvent
184+
* @param {object} options - options passed to recordEvent
185185
*/
186186
trackFormSubmission = options => {
187187
analytics.tracks.recordEvent( 'jetpack_wpa_settings_form_submit', options );
188188
};
189189

190190
/**
191191
* Tracks settings toggles
192-
* @param {String} module the module slug.
193-
* @param {String} setting the setting slug.
194-
* @param {Boolean} activated whether the settings is currently on
192+
* @param {string} module - the module slug.
193+
* @param {string} setting - the setting slug.
194+
* @param {boolean} activated - whether the settings is currently on
195195
*/
196196
trackSettingsToggle = ( module, setting, activated ) => {
197197
analytics.tracks.recordEvent( 'jetpack_wpa_settings_toggle', {

projects/plugins/jetpack/_inc/client/components/navigation-settings/test/component.js

-4
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ describe( 'NavigationSettings', () => {
111111
// eslint-disable-next-line react/jsx-no-bind
112112
<NavigationSettings { ...currentTestProps } isModuleActivated={ m => 'publicize' !== m } />
113113
);
114-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
115114
expect( screen.getAllByRole( 'menuitem' ) ).toHaveLength( 1 );
116-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
117115
expect( screen.getAllByRole( 'option' ) ).toHaveLength( 1 );
118116
expect( screen.getByRole( 'menuitem', { name: 'Writing' } ) ).toBeInTheDocument();
119117
expect( screen.getByRole( 'option', { name: 'Writing' } ) ).toBeInTheDocument();
@@ -129,9 +127,7 @@ describe( 'NavigationSettings', () => {
129127
isModuleActivated={ m => 'post-by-email' !== m }
130128
/>
131129
);
132-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
133130
expect( screen.getAllByRole( 'menuitem' ) ).toHaveLength( 1 );
134-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
135131
expect( screen.getAllByRole( 'option' ) ).toHaveLength( 1 );
136132
expect( screen.queryByRole( 'menuitem', { name: 'Writing' } ) ).not.toBeInTheDocument();
137133
expect( screen.queryByRole( 'option', { name: 'Writing' } ) ).not.toBeInTheDocument();

projects/plugins/jetpack/_inc/client/components/navigation/test/component.js

-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ describe( 'Navigation', () => {
1717
it( 'renders 1 NavItem component', () => {
1818
render( <Navigation { ...testProps } /> );
1919

20-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
2120
expect( screen.getAllByRole( 'menuitem' ) ).toHaveLength( 1 );
22-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
2321
expect( screen.getAllByRole( 'option' ) ).toHaveLength( 1 );
2422

2523
expect( screen.getByRole( 'menuitem', { name: 'At a Glance' } ) ).toBeInTheDocument();
@@ -35,9 +33,7 @@ describe( 'Navigation', () => {
3533

3634
it( 'renders 1 NavItem components', () => {
3735
render( <Navigation { ...currentTestProps } /> );
38-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
3936
expect( screen.getAllByRole( 'menuitem' ) ).toHaveLength( 1 );
40-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
4137
expect( screen.getAllByRole( 'option' ) ).toHaveLength( 1 );
4238
} );
4339

projects/plugins/jetpack/_inc/client/components/popover/index.jsx

-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class Popover extends Component {
9090
if ( ! context || this.isDOMNode( context ) ) {
9191
this.domContextRef.current = context;
9292
} else {
93-
// eslint-disable-next-line no-console
9493
this.debug( 'Expected a DOM node for props.context', context );
9594
}
9695
}
@@ -203,7 +202,6 @@ class Popover extends Component {
203202
if ( ! this.props.ignoreContext || this.isDOMNode( this.props.ignoreContext ) ) {
204203
ignoreContext = this.props.ignoreContext;
205204
} else {
206-
// eslint-disable-next-line no-console
207205
this.debug( 'Expected a DOM node for props.context', this.props.ignoreContext );
208206
}
209207
if ( ignoreContext && ignoreContext.contains ) {
@@ -255,7 +253,6 @@ class Popover extends Component {
255253
if ( ! this.props.context || this.isDOMNode( this.props.context ) ) {
256254
this.domContextRef.current = this.props.context;
257255
} else {
258-
// eslint-disable-next-line no-console
259256
this.debug( 'Expected a DOM node for props.context', this.props.context );
260257
}
261258

projects/plugins/jetpack/_inc/client/components/popover/util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ function offset( pos, el, target ) {
294294
*
295295
* @param {TextRectangle} box - result from a `getBoundingClientRect()` call
296296
* @param {Document} doc - Document instance to use
297-
* @return {Object} an object with `top` and `left` Number properties
298-
* @api private
297+
* @return {object} an object with `top` and `left` Number properties
298+
* @private
299299
*/
300300

301301
function _offset( box, doc ) {
@@ -314,7 +314,7 @@ function _offset( box, doc ) {
314314

315315
/*
316316
* Constrain a left to keep the element in the window
317-
* @param {Object} pl proposed left
317+
* @param {object} pl proposed left
318318
* @param {Number} ew tip element width
319319
* @return {Number} the best width
320320
*/
@@ -329,7 +329,7 @@ const isElement = obj => {
329329
try {
330330
//Using W3 DOM2 (works for FF, Opera and Chrom)
331331
return obj instanceof HTMLElement;
332-
} catch ( error ) {
332+
} catch {
333333
return (
334334
typeof obj === 'object' &&
335335
obj.nodeType === 1 &&

projects/plugins/jetpack/_inc/client/components/section-nav/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** @ssr-ready **/
22

33
import clsx from 'clsx';
4-
import Search from 'components/search';
54
import { isEqual } from 'lodash';
65
import PropTypes from 'prop-types';
76
import React from 'react';
7+
import Search from 'components/search';
88
import NavItem from './item';
99
import NavTabs from './tabs';
1010
import './style.scss';

projects/plugins/jetpack/_inc/client/components/section-nav/item.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { ExternalLink } from '@wordpress/components';
44
import clsx from 'clsx';
5-
import Count from 'components/count';
65
import PropTypes from 'prop-types';
76
import React from 'react';
7+
import Count from 'components/count';
88

99
/**
1010
* Main

projects/plugins/jetpack/_inc/client/components/section-nav/tabs.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import { getWindowInnerWidth } from '@automattic/viewport';
44
import clsx from 'clsx';
5-
import SelectDropdown from 'components/select-dropdown';
6-
import DropdownItem from 'components/select-dropdown/item';
75
import { debounce } from 'lodash';
86
import PropTypes from 'prop-types';
97
import React from 'react';
8+
import SelectDropdown from 'components/select-dropdown';
9+
import DropdownItem from 'components/select-dropdown/item';
1010

1111
/**
1212
* Internal Variables

projects/plugins/jetpack/_inc/client/components/select-dropdown/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/** @ssr-ready **/
22

33
import clsx from 'clsx';
4+
import { filter, find, findIndex, map, result } from 'lodash';
5+
import PropTypes from 'prop-types';
6+
import React from 'react';
47
import Count from 'components/count';
58
import DropdownItem from 'components/select-dropdown/item';
69
import DropdownLabel from 'components/select-dropdown/label';
710
import DropdownSeparator from 'components/select-dropdown/separator';
8-
import { filter, find, findIndex, map, result } from 'lodash';
9-
import PropTypes from 'prop-types';
10-
import React from 'react';
1111

1212
import './style.scss';
1313

projects/plugins/jetpack/_inc/client/components/select-dropdown/item.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** @ssr-ready **/
22

33
import clsx from 'clsx';
4-
import Count from 'components/count';
54
import PropTypes from 'prop-types';
65
import React from 'react';
6+
import Count from 'components/count';
77

88
class SelectDropdownItem extends React.Component {
99
static propTypes = {

projects/plugins/jetpack/_inc/client/components/settings-card/test/component.js

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ describe( 'SettingsCard', () => {
150150
<Child />
151151
</SettingsCard>
152152
);
153-
// eslint-disable-next-line jest-dom/prefer-in-document -- No, we really want to assert there's exactly 1.
154153
expect( screen.getAllByRole( 'button' ) ).toHaveLength( 1 );
155154
} );
156155
} );

projects/plugins/jetpack/_inc/client/lib/decode-entities/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* @since 5.8.0
55
*
6-
* @param {String} text The text to decode
7-
* @return {String} Returns the string with HTML entities decoded if DOMParser is available. Returns the original text otherwise.
6+
* @param {string} text - The text to decode
7+
* @return {string} Returns the string with HTML entities decoded if DOMParser is available. Returns the original text otherwise.
88
*/
99
export default function decodeEntities( text ) {
1010
if ( 'undefined' === typeof DOMParser ) {

projects/plugins/jetpack/_inc/client/lib/touch-detect/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* It may not accurately detect a touch screen, but may be close enough depending on the use case.
44
*
55
* @copyright Modernizr © 2009-2015.
6-
* @license See CREDITS.md.
7-
* @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
6+
* @license MIT
7+
* @see https://github.com/Modernizr/Modernizr/blob/d5f881a4de0d5fc1af85921ce9c7dc3919c6d335/feature-detects/touchevents.js
88
*
9-
* @return {Boolean} whether touch screen is available
9+
* @return {boolean} whether touch screen is available
1010
*/
1111
export function hasTouch() {
1212
/* global DocumentTouch:true */

0 commit comments

Comments
 (0)