diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js b/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js index ac29f39ac2a9..fcc6ae1e679f 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js @@ -1,6 +1,12 @@ import { uniqueId } from 'lodash'; import { NEW_NOTICE, REMOVE_NOTICE } from '../action-types'; +/** + * Creates a remove notice action. + * + * @param {string} noticeId - Notice ID. + * @return {object} Action object. + */ export function removeNotice( noticeId ) { return { noticeId: noticeId, @@ -8,6 +14,14 @@ export function removeNotice( noticeId ) { }; } +/** + * Creates a new notice action. + * + * @param {string} status - Notice status. + * @param {string} text - Notice text. + * @param {object} options - Notice options. + * @return {object} Action object. + */ export function createNotice( status, text, options = {} ) { const notice = { noticeId: options.id || uniqueId(), diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js b/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js index 3f7d3b491d81..0d9ee8531559 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js @@ -1,6 +1,13 @@ import { combineReducers } from 'redux'; import { NEW_NOTICE, REMOVE_NOTICE } from '../action-types'; +/** + * Reducer for global notices. + * + * @param {Array} state - Current state. + * @param {object} action - Action object. + * @return {Array} Updated state. + */ export function globalNotices( state = [], action ) { switch ( action.type ) { case NEW_NOTICE: diff --git a/projects/plugins/jetpack/_inc/client/components/modal/index.jsx b/projects/plugins/jetpack/_inc/client/components/modal/index.jsx index 7bd0f977893e..45dd4122c0ee 100644 --- a/projects/plugins/jetpack/_inc/client/components/modal/index.jsx +++ b/projects/plugins/jetpack/_inc/client/components/modal/index.jsx @@ -17,10 +17,16 @@ let preventCloseFlag = false; import './style.scss'; +/** + * Prevents any modals from closing until {@link allowClose} is called. + */ function preventClose() { preventCloseFlag = true; } +/** + * Allows modals to close again after {@link preventClose} was called. + */ function allowClose() { preventCloseFlag = false; } diff --git a/projects/plugins/jetpack/_inc/client/components/popover/util.js b/projects/plugins/jetpack/_inc/client/components/popover/util.js index 6e5ff3e76ba4..b88f928b18bb 100644 --- a/projects/plugins/jetpack/_inc/client/components/popover/util.js +++ b/projects/plugins/jetpack/_inc/client/components/popover/util.js @@ -7,6 +7,12 @@ import debugFactory from 'debug'; const debug = debugFactory( 'calypso:popover:util' ); // inspired by https://github.com/jkroso/viewport + +/** + * Updates and returns the current viewport dimensions. + * + * @return {object} Viewport object with top, left, width, height, right, and bottom. + */ function updateViewport() { const viewport = {}; viewport.top = window.scrollY; @@ -38,6 +44,9 @@ const adjacent = { let viewport = updateViewport(); +/** + * Updates the cached viewport on window resize or scroll. + */ function onViewportChange() { viewport = updateViewport(); } @@ -95,6 +104,13 @@ const suggested = ( pos, el, target ) => { return chooseSecondary( primary, pos1, el, target, w, h ) || pos; }; +/** + * Chooses the primary popover position based on available room. + * + * @param {string} prefered - Preferred position. + * @param {object} room - Available room in each direction. + * @return {string|undefined} Best primary position. + */ function choosePrimary( prefered, room ) { // top, bottom, left, right in order of preference const order = [ @@ -125,6 +141,17 @@ function choosePrimary( prefered, room ) { return bestPos; } +/** + * Chooses the secondary popover position based on visible area. + * + * @param {string} primary - Primary position. + * @param {string|null} prefered - Preferred secondary position. + * @param {HTMLElement} el - Tip element. + * @param {HTMLElement} target - Target element. + * @param {number} w - Tip width. + * @param {number} h - Tip height. + * @return {string|undefined} Best position string. + */ function chooseSecondary( primary, prefered, el, target, w, h ) { // top, top left, top right in order of preference const order = prefered @@ -170,6 +197,14 @@ function chooseSecondary( primary, prefered, el, target, w, h ) { return bestPos; } +/** + * Calculates the offset for a popover position. + * + * @param {string} pos - Position string. + * @param {HTMLElement} el - Tip element. + * @param {HTMLElement} target - Target element. + * @return {object} Offset with top and left properties. + */ function offset( pos, el, target ) { const pad = 15; const tipRect = getBoundingClientRect( el ); @@ -290,14 +325,13 @@ function offset( pos, el, target ) { /** * Extracted from `timoxley/offset`, but directly using a - * TextRectangle instead of getting another version. + * DOMRect instead of getting another version. * - * @param {TextRectangle} box - result from a `getBoundingClientRect()` call - * @param {Document} doc - Document instance to use - * @return {object} an object with `top` and `left` Number properties + * @param {DOMRect} box - Result from a `getBoundingClientRect()` call. + * @param {Document} doc - Document instance to use. + * @return {object} An object with `top` and `left` number properties. * @private */ - function _offset( box, doc ) { const body = doc.body || doc.getElementsByTagName( 'body' )[ 0 ]; const docEl = doc.documentElement || body.parentNode; diff --git a/projects/plugins/jetpack/_inc/client/config.js b/projects/plugins/jetpack/_inc/client/config.js index 3de626c01622..c7c5d7d348ff 100644 --- a/projects/plugins/jetpack/_inc/client/config.js +++ b/projects/plugins/jetpack/_inc/client/config.js @@ -4,6 +4,14 @@ const data = { google_analytics_enabled: false, google_analytics_key: null, }; + +/** + * Returns a configuration value. + * + * @param {string} key - Configuration key. + * @return {*} Configuration value. + * @throws {Error} If the key does not exist. + */ function config( key ) { if ( key in data ) { return data[ key ]; diff --git a/projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js b/projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js index 383c47cef608..cc451c876359 100644 --- a/projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js +++ b/projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js @@ -1,6 +1,9 @@ const keyboardNavigationKeycodes = [ 9, 32, 37, 38, 39, 40 ]; // keyCodes for tab, space, left, up, right, down respectively let keyboardNavigation = false; +/** + * Enables accessible focus styles when navigating via keyboard. + */ function accessibleFocus() { document.addEventListener( 'keydown', function ( event ) { if ( keyboardNavigation ) { diff --git a/projects/plugins/jetpack/_inc/client/mixins/emitter/index.js b/projects/plugins/jetpack/_inc/client/mixins/emitter/index.js index c1ec66c0de04..57cfd6a808ec 100644 --- a/projects/plugins/jetpack/_inc/client/mixins/emitter/index.js +++ b/projects/plugins/jetpack/_inc/client/mixins/emitter/index.js @@ -1,5 +1,10 @@ import { EventEmitter } from 'events'; +/** + * Adds EventEmitter methods to a prototype. + * + * @param {object} prototype - Prototype to extend. + */ export default function ( prototype ) { Object.assign( prototype, EventEmitter.prototype ); prototype.emitChange = function () { diff --git a/projects/plugins/jetpack/_inc/client/my-plan/index.jsx b/projects/plugins/jetpack/_inc/client/my-plan/index.jsx index dbbfd92d05f0..fdbb163c3208 100644 --- a/projects/plugins/jetpack/_inc/client/my-plan/index.jsx +++ b/projects/plugins/jetpack/_inc/client/my-plan/index.jsx @@ -15,6 +15,12 @@ import MyPlanBody from './my-plan-body'; import MyPlanHeader from './my-plan-header'; import MyPlanPartnerCoupon from './my-plan-partner-coupon'; +/** + * My Plan page component. + * + * @param {object} props - Component props. + * @return {import('react').ReactElement} React element. + */ export function MyPlan( props ) { let sitePlan = props.sitePlan.product_slug || '', availableFeatures = props.availableFeatures, diff --git a/projects/plugins/jetpack/_inc/twitter-timeline.js b/projects/plugins/jetpack/_inc/twitter-timeline.js index ff3dc79f162a..d747b1265336 100644 --- a/projects/plugins/jetpack/_inc/twitter-timeline.js +++ b/projects/plugins/jetpack/_inc/twitter-timeline.js @@ -1,4 +1,4 @@ -! ( function ( d, s, id ) { +void ( function ( d, s, id ) { var js, fjs = d.getElementsByTagName( s )[ 0 ], p = /^http:/.test( d.location ) ? 'http' : 'https'; diff --git a/projects/plugins/jetpack/changelog/update-eslint-fixes b/projects/plugins/jetpack/changelog/update-eslint-fixes new file mode 100644 index 000000000000..f8a0470dff03 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-eslint-fixes @@ -0,0 +1,4 @@ +Significance: patch +Type: other +Comment: Fix ESLint issues in legacy Jetpack admin client files. + diff --git a/tools/eslint-excludelist.json b/tools/eslint-excludelist.json index 9671bc7c5724..fe51488c7066 100644 --- a/tools/eslint-excludelist.json +++ b/tools/eslint-excludelist.json @@ -1,11 +1 @@ -[ - "projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js", - "projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js", - "projects/plugins/jetpack/_inc/client/components/modal/index.jsx", - "projects/plugins/jetpack/_inc/client/components/popover/util.js", - "projects/plugins/jetpack/_inc/client/config.js", - "projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js", - "projects/plugins/jetpack/_inc/client/mixins/emitter/index.js", - "projects/plugins/jetpack/_inc/client/my-plan/index.jsx", - "projects/plugins/jetpack/_inc/twitter-timeline.js" -] +[]