From 3074bcadc673a47d1e3ad7db8773e426e2931d9f Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Wed, 31 Aug 2022 11:40:15 +0000 Subject: [PATCH] Bug 1787389 - [devtools] Fix ESLint consistent-return failures in devtools/client/debugger/src/actions. r=bomsy. Differential Revision: https://phabricator.services.mozilla.com/D155824 --- devtools/.eslintrc.js | 15 ------- .../debugger/src/actions/breakpoints/index.js | 4 +- .../src/actions/breakpoints/modify.js | 12 +++--- .../src/actions/breakpoints/syncBreakpoint.js | 4 +- .../debugger/src/actions/expressions.js | 6 ++- .../debugger/src/actions/pause/commands.js | 39 +++++++++++-------- .../src/actions/pause/highlightCalls.js | 12 +++--- .../src/actions/pause/inlinePreview.js | 10 ++--- .../debugger/src/actions/pause/mapScopes.js | 3 +- .../debugger/src/actions/pause/selectFrame.js | 3 +- .../src/actions/pause/tests/pause.spec.js | 2 + .../client/debugger/src/actions/preview.js | 4 +- .../src/actions/sources/newSources.js | 5 ++- .../debugger/src/actions/sources/select.js | 5 ++- devtools/client/debugger/src/actions/ui.js | 2 +- .../debugger/src/client/firefox/commands.js | 39 ++++++++++++------- 16 files changed, 88 insertions(+), 77 deletions(-) diff --git a/devtools/.eslintrc.js b/devtools/.eslintrc.js index 30dda1c9c7da..a5d9f6d4184d 100644 --- a/devtools/.eslintrc.js +++ b/devtools/.eslintrc.js @@ -33,21 +33,6 @@ module.exports = { }, { files: [ - "client/debugger/src/actions/breakpoints/index.js", - "client/debugger/src/actions/breakpoints/modify.js", - "client/debugger/src/actions/breakpoints/syncBreakpoint.js", - "client/debugger/src/actions/expressions.js", - "client/debugger/src/actions/pause/commands.js", - "client/debugger/src/actions/pause/highlightCalls.js", - "client/debugger/src/actions/pause/inlinePreview.js", - "client/debugger/src/actions/pause/mapScopes.js", - "client/debugger/src/actions/pause/selectFrame.js", - "client/debugger/src/actions/pause/tests/pause.spec.js", - "client/debugger/src/actions/preview.js", - "client/debugger/src/actions/sources/newSources.js", - "client/debugger/src/actions/sources/select.js", - "client/debugger/src/actions/ui.js", - "client/debugger/src/client/firefox/commands.js", "client/debugger/src/components/App.js", "client/debugger/src/components/Editor/Breakpoint.js", "client/debugger/src/components/Editor/ColumnBreakpoint.js", diff --git a/devtools/client/debugger/src/actions/breakpoints/index.js b/devtools/client/debugger/src/actions/breakpoints/index.js index d6821831871a..ddef5bb0dbb7 100644 --- a/devtools/client/debugger/src/actions/breakpoints/index.js +++ b/devtools/client/debugger/src/actions/breakpoints/index.js @@ -215,7 +215,7 @@ export function toggleBreakpointAtLine(cx, line) { const selectedSource = getSelectedSource(state); if (!selectedSource) { - return; + return null; } const bp = getBreakpointAtLocation(state, { line, column: undefined }); @@ -243,7 +243,7 @@ export function addBreakpointAtLine( const source = getSelectedSource(state); if (!source) { - return; + return null; } const breakpointLocation = { sourceId: source.id, diff --git a/devtools/client/debugger/src/actions/breakpoints/modify.js b/devtools/client/debugger/src/actions/breakpoints/modify.js index 77f4587be50b..68f54ecf185f 100644 --- a/devtools/client/debugger/src/actions/breakpoints/modify.js +++ b/devtools/client/debugger/src/actions/breakpoints/modify.js @@ -83,7 +83,7 @@ export function enableBreakpoint(cx, initialBreakpoint) { const { dispatch, getState, client } = thunkArgs; const breakpoint = getBreakpoint(getState(), initialBreakpoint.location); if (!breakpoint || !breakpoint.disabled) { - return; + return null; } dispatch(setSkipPausing(false)); @@ -121,7 +121,7 @@ export function addBreakpoint( // No position is found if the `initialLocation` is on a non-breakable line or // the line no longer exists. if (!position) { - return; + return null; } const { location, generatedLocation } = position; @@ -130,7 +130,7 @@ export function addBreakpoint( const generatedSource = getLocationSource(getState(), generatedLocation); if (!source || !generatedSource) { - return; + return null; } const originalContent = getSourceContent(getState(), source.id); @@ -160,7 +160,7 @@ export function addBreakpoint( }); if (shouldCancel()) { - return; + return null; } dispatch(setSkipPausing(false)); @@ -189,7 +189,7 @@ export function removeBreakpoint(cx, initialBreakpoint) { const breakpoint = getBreakpoint(getState(), initialBreakpoint.location); if (!breakpoint) { - return; + return null; } dispatch(setSkipPausing(false)); @@ -270,7 +270,7 @@ export function disableBreakpoint(cx, initialBreakpoint) { return ({ dispatch, getState, client }) => { const breakpoint = getBreakpoint(getState(), initialBreakpoint.location); if (!breakpoint || breakpoint.disabled) { - return; + return null; } dispatch(setSkipPausing(false)); diff --git a/devtools/client/debugger/src/actions/breakpoints/syncBreakpoint.js b/devtools/client/debugger/src/actions/breakpoints/syncBreakpoint.js index c0a2febce342..0b4b1198ec10 100644 --- a/devtools/client/debugger/src/actions/breakpoints/syncBreakpoint.js +++ b/devtools/client/debugger/src/actions/breakpoints/syncBreakpoint.js @@ -56,7 +56,7 @@ export function syncBreakpoint(cx, sourceId, pendingBreakpoint) { const generatedSource = getSource(getState(), generatedSourceId); if (!source || !generatedSource) { - return; + return null; } const { location, generatedLocation } = pendingBreakpoint; @@ -110,7 +110,7 @@ export function syncBreakpoint(cx, sourceId, pendingBreakpoint) { removeBreakpointAtGeneratedLocation(cx, sourceGeneratedLocation) ); } - return; + return null; } const isSameLocation = comparePosition( diff --git a/devtools/client/debugger/src/actions/expressions.js b/devtools/client/debugger/src/actions/expressions.js index a548e8c5522d..6a30303b5d0d 100644 --- a/devtools/client/debugger/src/actions/expressions.js +++ b/devtools/client/debugger/src/actions/expressions.js @@ -30,7 +30,7 @@ import { features } from "../utils/prefs"; export function addExpression(cx, input) { return async ({ dispatch, getState, evaluationsParser }) => { if (!input) { - return; + return null; } const expressionError = await evaluationsParser.hasSyntaxError(input); @@ -46,6 +46,8 @@ export function addExpression(cx, input) { if (newExpression) { return dispatch(evaluateExpression(cx, newExpression)); } + + return null; }; } @@ -126,7 +128,7 @@ function evaluateExpression(cx, expression) { return async function({ dispatch, getState, client, sourceMaps }) { if (!expression.input) { console.warn("Expressions should not be empty"); - return; + return null; } let { input } = expression; diff --git a/devtools/client/debugger/src/actions/pause/commands.js b/devtools/client/debugger/src/actions/pause/commands.js index 9eddf6a3e980..7766b75bf07e 100644 --- a/devtools/client/debugger/src/actions/pause/commands.js +++ b/devtools/client/debugger/src/actions/pause/commands.js @@ -61,7 +61,7 @@ export function selectThread(cx, thread) { export function command(type) { return async ({ dispatch, getState, client }) => { if (!type) { - return; + return null; } // For now, all commands are by default against the currently selected thread const thread = getCurrentThread(getState()); @@ -85,9 +85,10 @@ export function command(type) { */ export function stepIn() { return ({ dispatch, getState }) => { - if (getIsCurrentThreadPaused(getState())) { - return dispatch(command("stepIn")); + if (!getIsCurrentThreadPaused(getState())) { + return null; } + return dispatch(command("stepIn")); }; } @@ -99,9 +100,10 @@ export function stepIn() { */ export function stepOver() { return ({ dispatch, getState }) => { - if (getIsCurrentThreadPaused(getState())) { - return dispatch(command("stepOver")); + if (!getIsCurrentThreadPaused(getState())) { + return null; } + return dispatch(command("stepOver")); }; } @@ -113,9 +115,10 @@ export function stepOver() { */ export function stepOut() { return ({ dispatch, getState }) => { - if (getIsCurrentThreadPaused(getState())) { - return dispatch(command("stepOut")); + if (!getIsCurrentThreadPaused(getState())) { + return null; } + return dispatch(command("stepOut")); }; } @@ -127,10 +130,11 @@ export function stepOut() { */ export function resume() { return ({ dispatch, getState }) => { - if (getIsCurrentThreadPaused(getState())) { - recordEvent("continue"); - return dispatch(command("resume")); + if (!getIsCurrentThreadPaused(getState())) { + return null; } + recordEvent("continue"); + return dispatch(command("resume")); }; } @@ -141,13 +145,14 @@ export function resume() { */ export function restart(cx, frame) { return async ({ dispatch, getState, client }) => { - if (getIsCurrentThreadPaused(getState())) { - return dispatch({ - type: "COMMAND", - command: "restart", - thread: cx.thread, - [PROMISE]: client.restart(cx.thread, frame.id), - }); + if (!getIsCurrentThreadPaused(getState())) { + return null; } + return dispatch({ + type: "COMMAND", + command: "restart", + thread: cx.thread, + [PROMISE]: client.restart(cx.thread, frame.id), + }); }; } diff --git a/devtools/client/debugger/src/actions/pause/highlightCalls.js b/devtools/client/debugger/src/actions/pause/highlightCalls.js index 7cf26ded0752..69a0178106da 100644 --- a/devtools/client/debugger/src/actions/pause/highlightCalls.js +++ b/devtools/client/debugger/src/actions/pause/highlightCalls.js @@ -27,7 +27,7 @@ function inHouseContainsPosition(a, b) { export function highlightCalls(cx) { return async function({ dispatch, getState, parser, client }) { if (!cx) { - return; + return null; } const frame = await getSelectedFrame( @@ -36,29 +36,29 @@ export function highlightCalls(cx) { ); if (!frame) { - return; + return null; } const { thread } = cx; const originalAstScopes = await parser.getScopes(frame.location); if (!originalAstScopes) { - return; + return null; } const source = getLocationSource(getState(), frame.location); if (!source) { - return; + return null; } const symbols = getSymbols(getState(), source); if (!symbols) { - return; + return null; } if (!symbols.callExpressions) { - return; + return null; } const localAstScope = originalAstScopes[0]; diff --git a/devtools/client/debugger/src/actions/pause/inlinePreview.js b/devtools/client/debugger/src/actions/pause/inlinePreview.js index 854cafd6aa42..90284f6b5a01 100644 --- a/devtools/client/debugger/src/actions/pause/inlinePreview.js +++ b/devtools/client/debugger/src/actions/pause/inlinePreview.js @@ -27,14 +27,14 @@ function getLocalScopeLevels(originalAstScopes) { export function generateInlinePreview(cx, frame) { return async function({ dispatch, getState, parser, client }) { if (!frame || !features.inlinePreview) { - return; + return null; } const { thread } = cx; // Avoid regenerating inline previews when we already have preview data if (getInlinePreviews(getState(), thread, frame.id)) { - return; + return null; } const originalFrameScopes = getOriginalFrameScope( @@ -53,20 +53,20 @@ export function generateInlinePreview(cx, frame) { let scopes = originalFrameScopes?.scope || generatedFrameScopes?.scope; if (!scopes || !scopes.bindings) { - return; + return null; } // It's important to use selectedLocation, because we don't know // if we'll be viewing the original or generated frame location const selectedLocation = getSelectedLocation(getState()); if (!selectedLocation) { - return; + return null; } const originalAstScopes = await parser.getScopes(selectedLocation); validateThreadContext(getState(), cx); if (!originalAstScopes) { - return; + return null; } const allPreviews = []; diff --git a/devtools/client/debugger/src/actions/pause/mapScopes.js b/devtools/client/debugger/src/actions/pause/mapScopes.js index 78afe32fa988..bb4bc31bba35 100644 --- a/devtools/client/debugger/src/actions/pause/mapScopes.js +++ b/devtools/client/debugger/src/actions/pause/mapScopes.js @@ -84,7 +84,8 @@ export async function buildOriginalScopes( export function toggleMapScopes() { return async function({ dispatch, getState, client, sourceMaps }) { if (isMapScopesEnabled(getState())) { - return dispatch({ type: "TOGGLE_MAP_SCOPES", mapScopes: false }); + dispatch({ type: "TOGGLE_MAP_SCOPES", mapScopes: false }); + return; } dispatch({ type: "TOGGLE_MAP_SCOPES", mapScopes: true }); diff --git a/devtools/client/debugger/src/actions/pause/selectFrame.js b/devtools/client/debugger/src/actions/pause/selectFrame.js index b3879679f7e0..50203a4da5b6 100644 --- a/devtools/client/debugger/src/actions/pause/selectFrame.js +++ b/devtools/client/debugger/src/actions/pause/selectFrame.js @@ -18,7 +18,8 @@ export function selectFrame(cx, frame) { // Frames that aren't on-stack do not support evalling and may not // have live inspectable scopes, so we do not allow selecting them. if (frame.state !== "on-stack") { - return dispatch(selectLocation(cx, frame.location)); + dispatch(selectLocation(cx, frame.location)); + return; } dispatch({ diff --git a/devtools/client/debugger/src/actions/pause/tests/pause.spec.js b/devtools/client/debugger/src/actions/pause/tests/pause.spec.js index 9464d747c51f..c9b0115faf7b 100644 --- a/devtools/client/debugger/src/actions/pause/tests/pause.spec.js +++ b/devtools/client/debugger/src/actions/pause/tests/pause.spec.js @@ -64,6 +64,8 @@ const mockCommandClient = { contentType: "text/rust", }); } + + return resolve(); }); }, getSourceActorBreakpointPositions: async () => ({}), diff --git a/devtools/client/debugger/src/actions/preview.js b/devtools/client/debugger/src/actions/preview.js index ceb874c990c6..15925508dd60 100644 --- a/devtools/client/debugger/src/actions/preview.js +++ b/devtools/client/debugger/src/actions/preview.js @@ -25,7 +25,7 @@ import { getMappedExpression } from "./expressions"; function findExpressionMatch(state, codeMirror, tokenPos) { const source = getSelectedSource(state); if (!source) { - return; + return null; } const symbols = getSymbols(state, source); @@ -167,7 +167,7 @@ export function clearPreview(cx) { return ({ dispatch, getState, client }) => { const currentSelection = getPreview(getState()); if (!currentSelection) { - return; + return null; } return dispatch({ diff --git a/devtools/client/debugger/src/actions/sources/newSources.js b/devtools/client/debugger/src/actions/sources/newSources.js index d0dcea77b536..c78ea4ae4a8e 100644 --- a/devtools/client/debugger/src/actions/sources/newSources.js +++ b/devtools/client/debugger/src/actions/sources/newSources.js @@ -65,6 +65,8 @@ function loadSourceMaps(cx, sources) { throw error; } } + + return []; }; } @@ -136,7 +138,8 @@ function checkSelectedSource(cx, sourceId) { if (rawPendingUrl === source.url) { if (isPrettyURL(pendingUrl)) { const prettySource = await dispatch(togglePrettyPrint(cx, source.id)); - return dispatch(checkPendingBreakpoints(cx, prettySource.id)); + dispatch(checkPendingBreakpoints(cx, prettySource.id)); + return; } await dispatch( diff --git a/devtools/client/debugger/src/actions/sources/select.js b/devtools/client/debugger/src/actions/sources/select.js index 5037b7302902..e827709362fa 100644 --- a/devtools/client/debugger/src/actions/sources/select.js +++ b/devtools/client/debugger/src/actions/sources/select.js @@ -131,7 +131,8 @@ export function selectLocation(cx, location, { keepContext = true } = {}) { if (!source) { // If there is no source we deselect the current selected source - return dispatch(clearSelectedLocation(cx)); + dispatch(clearSelectedLocation(cx)); + return; } const activeSearch = getActiveSearch(getState()); @@ -228,7 +229,7 @@ export function selectSpecificLocation(cx, location) { export function jumpToMappedLocation(cx, location) { return async function({ dispatch, getState, client, sourceMaps }) { if (!client) { - return; + return null; } // Map to either an original or a generated source location diff --git a/devtools/client/debugger/src/actions/ui.js b/devtools/client/debugger/src/actions/ui.js index b6f49a91fb1d..a8830cd26b1f 100644 --- a/devtools/client/debugger/src/actions/ui.js +++ b/devtools/client/debugger/src/actions/ui.js @@ -165,7 +165,7 @@ export function clearHighlightLineRange() { export function openConditionalPanel(location, log = false) { if (!location) { - return; + return null; } return { diff --git a/devtools/client/debugger/src/client/firefox/commands.js b/devtools/client/debugger/src/client/firefox/commands.js index c9684e5b4325..79d114750867 100644 --- a/devtools/client/debugger/src/client/firefox/commands.js +++ b/devtools/client/debugger/src/client/firefox/commands.js @@ -50,13 +50,15 @@ async function loadObjectProperties(root, threadActorID) { function releaseActor(actor) { if (!actor) { - return; + return Promise.resolve(); } const objFront = commands.client.getFrontByID(actor); - if (objFront) { - return objFront.release().catch(() => {}); + if (!objFront) { + return Promise.resolve(); } + + return objFront.release().catch(() => {}); } function lookupTarget(thread) { @@ -133,7 +135,8 @@ async function setXHRBreakpoint(path, method) { const hasWatcherSupport = commands.targetCommand.hasTargetWatcherSupport(); if (!hasWatcherSupport) { // Without watcher support, forward setXHRBreakpoint to all threads. - return forEachThread(thread => thread.setXHRBreakpoint(path, method)); + await forEachThread(thread => thread.setXHRBreakpoint(path, method)); + return; } const breakpointsFront = await commands.targetCommand.watcherFront.getBreakpointListActor(); await breakpointsFront.setXHRBreakpoint(path, method); @@ -143,7 +146,8 @@ async function removeXHRBreakpoint(path, method) { const hasWatcherSupport = commands.targetCommand.hasTargetWatcherSupport(); if (!hasWatcherSupport) { // Without watcher support, forward removeXHRBreakpoint to all threads. - return forEachThread(thread => thread.removeXHRBreakpoint(path, method)); + await forEachThread(thread => thread.removeXHRBreakpoint(path, method)); + return; } const breakpointsFront = await commands.targetCommand.watcherFront.getBreakpointListActor(); await breakpointsFront.removeXHRBreakpoint(path, method); @@ -155,18 +159,20 @@ export function toggleJavaScriptEnabled(enabled) { }); } -function addWatchpoint(object, property, label, watchpointType) { - if (currentTarget().getTrait("watchpoints")) { - const objectFront = createObjectFront(object); - return objectFront.addWatchpoint(property, label, watchpointType); +async function addWatchpoint(object, property, label, watchpointType) { + if (!currentTarget().getTrait("watchpoints")) { + return; } + const objectFront = createObjectFront(object); + await objectFront.addWatchpoint(property, label, watchpointType); } async function removeWatchpoint(object, property) { - if (currentTarget().getTrait("watchpoints")) { - const objectFront = createObjectFront(object); - await objectFront.removeWatchpoint(property); + if (!currentTarget().getTrait("watchpoints")) { + return; } + const objectFront = createObjectFront(object); + await objectFront.removeWatchpoint(property); } function hasBreakpoint(location) { @@ -183,7 +189,7 @@ async function setBreakpoint(location, options) { breakpoint && JSON.stringify(breakpoint.options) == JSON.stringify(options) ) { - return; + return null; } breakpoints[makePendingLocationId(location)] = { location, options }; @@ -216,6 +222,8 @@ async function setBreakpoint(location, options) { ) { return thread.setBreakpoint(location, serverOptions); } + + return Promise.resolve(); }); } @@ -240,6 +248,8 @@ async function removeBreakpoint(location) { ) { return thread.removeBreakpoint(location); } + + return Promise.resolve(); }); } @@ -358,7 +368,8 @@ async function setSkipPausing(shouldSkip) { async function setEventListenerBreakpoints(ids) { const hasWatcherSupport = commands.targetCommand.hasTargetWatcherSupport(); if (!hasWatcherSupport) { - return forEachThread(thread => thread.setActiveEventBreakpoints(ids)); + await forEachThread(thread => thread.setActiveEventBreakpoints(ids)); + return; } const breakpointListFront = await commands.targetCommand.watcherFront.getBreakpointListActor(); await breakpointListFront.setActiveEventBreakpoints(ids);