From b64be353ccc7a39b45a35dcceb5d58897595bcb3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 11 May 2022 16:06:35 -0500 Subject: [PATCH] eslint: indent switch statements --- .eslintrc.js | 1 + app/soapbox/actions/compose.js | 18 +- app/soapbox/actions/streaming.js | 78 ++-- app/soapbox/components/autosuggest_input.js | 74 ++-- .../components/autosuggest_textarea.js | 56 +-- app/soapbox/components/dropdown_menu.tsx | 62 +-- app/soapbox/components/emoji_selector.tsx | 32 +- app/soapbox/components/filter_bar.js | 12 +- app/soapbox/components/relative_timestamp.js | 20 +- app/soapbox/features/audio/index.js | 40 +- .../auth_login/components/captcha.tsx | 36 +- .../chats/components/chat_message_list.js | 12 +- .../compose/components/compose_form.js | 4 +- .../compose/components/privacy_dropdown.js | 62 +-- app/soapbox/features/introduction/index.js | 12 +- .../notifications/components/notification.tsx | 78 ++-- .../features/onboarding/onboarding-wizard.tsx | 12 +- .../features/ui/components/media_modal.js | 20 +- .../modals/report-modal/report-modal.tsx | 68 +-- .../features/ui/components/theme-selector.tsx | 16 +- .../features/ui/components/upload_area.tsx | 10 +- .../features/verification/email_passthru.js | 56 +-- app/soapbox/features/video/index.js | 70 +-- app/soapbox/reducers/account_notes.ts | 30 +- app/soapbox/reducers/accounts.ts | 112 ++--- app/soapbox/reducers/accounts_counters.js | 26 +- app/soapbox/reducers/accounts_meta.js | 16 +- app/soapbox/reducers/admin.ts | 48 +-- app/soapbox/reducers/admin_log.js | 8 +- app/soapbox/reducers/alerts.ts | 16 +- app/soapbox/reducers/aliases.js | 38 +- app/soapbox/reducers/auth.js | 42 +- app/soapbox/reducers/backups.js | 10 +- app/soapbox/reducers/chat_message_lists.ts | 34 +- app/soapbox/reducers/chat_messages.ts | 48 +-- app/soapbox/reducers/chats.ts | 32 +- app/soapbox/reducers/compose.js | 408 +++++++++--------- app/soapbox/reducers/contexts.js | 34 +- app/soapbox/reducers/conversations.js | 42 +- app/soapbox/reducers/domain_lists.js | 16 +- app/soapbox/reducers/dropdown_menu.js | 12 +- app/soapbox/reducers/filters.tsx | 8 +- app/soapbox/reducers/group_editor.js | 62 +-- app/soapbox/reducers/group_lists.js | 8 +- app/soapbox/reducers/group_relationships.js | 14 +- app/soapbox/reducers/groups.js | 18 +- app/soapbox/reducers/history.ts | 28 +- app/soapbox/reducers/identity_proofs.js | 24 +- app/soapbox/reducers/index.ts | 8 +- app/soapbox/reducers/instance.ts | 32 +- app/soapbox/reducers/list_adder.ts | 44 +- app/soapbox/reducers/list_editor.ts | 106 ++--- app/soapbox/reducers/lists.ts | 22 +- app/soapbox/reducers/me.ts | 26 +- app/soapbox/reducers/meta.ts | 14 +- app/soapbox/reducers/modals.js | 28 +- app/soapbox/reducers/mutes.js | 20 +- app/soapbox/reducers/notifications.js | 76 ++-- app/soapbox/reducers/onboarding.ts | 12 +- app/soapbox/reducers/patron.ts | 12 +- app/soapbox/reducers/pending_statuses.js | 12 +- app/soapbox/reducers/polls.ts | 8 +- app/soapbox/reducers/profile_hover_card.js | 26 +- app/soapbox/reducers/push_notifications.js | 32 +- app/soapbox/reducers/relationships.js | 90 ++-- app/soapbox/reducers/reports.js | 96 ++--- app/soapbox/reducers/rules.ts | 12 +- app/soapbox/reducers/scheduled_statuses.js | 22 +- app/soapbox/reducers/search.js | 46 +- app/soapbox/reducers/security.js | 24 +- app/soapbox/reducers/settings.js | 32 +- app/soapbox/reducers/sidebar.ts | 12 +- app/soapbox/reducers/soapbox.js | 24 +- app/soapbox/reducers/status_lists.js | 118 ++--- app/soapbox/reducers/statuses.ts | 112 ++--- app/soapbox/reducers/suggestions.js | 38 +- app/soapbox/reducers/timelines.js | 86 ++-- app/soapbox/reducers/trending_statuses.js | 12 +- app/soapbox/reducers/trends.js | 22 +- app/soapbox/reducers/user_lists.js | 114 ++--- app/soapbox/reducers/verification.js | 48 +-- app/soapbox/selectors/index.ts | 22 +- app/soapbox/utils/resize_image.ts | 52 +-- babel.config.js | 72 ++-- webpack.config.js | 14 +- webpack/translationRunner.js | 34 +- 86 files changed, 1782 insertions(+), 1781 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 766aae53a..2a2c14f68 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -72,6 +72,7 @@ module.exports = { 'dot-notation': 'error', eqeqeq: 'error', indent: ['error', 2, { + SwitchCase: 1, // https://stackoverflow.com/a/53055584/8811886 ignoredNodes: ['TemplateLiteral'], }], 'jsx-quotes': ['error', 'prefer-single'], diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index f733ef3d4..607fe9481 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -515,15 +515,15 @@ const fetchComposeSuggestionsTags = (dispatch, getState, token) => { export function fetchComposeSuggestions(token) { return (dispatch, getState) => { switch (token[0]) { - case ':': - fetchComposeSuggestionsEmojis(dispatch, getState, token); - break; - case '#': - fetchComposeSuggestionsTags(dispatch, getState, token); - break; - default: - fetchComposeSuggestionsAccounts(dispatch, getState, token); - break; + case ':': + fetchComposeSuggestionsEmojis(dispatch, getState, token); + break; + case '#': + fetchComposeSuggestionsTags(dispatch, getState, token); + break; + default: + fetchComposeSuggestionsAccounts(dispatch, getState, token); + break; } }; } diff --git a/app/soapbox/actions/streaming.js b/app/soapbox/actions/streaming.js index ece6dee64..51b09fca8 100644 --- a/app/soapbox/actions/streaming.js +++ b/app/soapbox/actions/streaming.js @@ -52,46 +52,46 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a onReceive(data) { switch (data.event) { - case 'update': - dispatch(processTimelineUpdate(timelineId, JSON.parse(data.payload), accept)); - break; - case 'status.update': - dispatch(updateStatus(JSON.parse(data.payload))); - break; - case 'delete': - dispatch(deleteFromTimelines(data.payload)); - break; - case 'notification': - messages[locale]().then(messages => { - dispatch(updateNotificationsQueue(JSON.parse(data.payload), messages, locale, window.location.pathname)); - }).catch(error => { - console.error(error); - }); - break; - case 'conversation': - dispatch(updateConversations(JSON.parse(data.payload))); - break; - case 'filters_changed': - dispatch(fetchFilters()); - break; - case 'pleroma:chat_update': - dispatch((dispatch, getState) => { - const chat = JSON.parse(data.payload); - const me = getState().get('me'); - const messageOwned = !(chat.last_message && chat.last_message.account_id !== me); - - dispatch({ - type: STREAMING_CHAT_UPDATE, - chat, - me, - // Only play sounds for recipient messages - meta: !messageOwned && getSettings(getState()).getIn(['chats', 'sound']) && { sound: 'chat' }, + case 'update': + dispatch(processTimelineUpdate(timelineId, JSON.parse(data.payload), accept)); + break; + case 'status.update': + dispatch(updateStatus(JSON.parse(data.payload))); + break; + case 'delete': + dispatch(deleteFromTimelines(data.payload)); + break; + case 'notification': + messages[locale]().then(messages => { + dispatch(updateNotificationsQueue(JSON.parse(data.payload), messages, locale, window.location.pathname)); + }).catch(error => { + console.error(error); }); - }); - break; - case 'pleroma:follow_relationships_update': - dispatch(updateFollowRelationships(JSON.parse(data.payload))); - break; + break; + case 'conversation': + dispatch(updateConversations(JSON.parse(data.payload))); + break; + case 'filters_changed': + dispatch(fetchFilters()); + break; + case 'pleroma:chat_update': + dispatch((dispatch, getState) => { + const chat = JSON.parse(data.payload); + const me = getState().get('me'); + const messageOwned = !(chat.last_message && chat.last_message.account_id !== me); + + dispatch({ + type: STREAMING_CHAT_UPDATE, + chat, + me, + // Only play sounds for recipient messages + meta: !messageOwned && getSettings(getState()).getIn(['chats', 'sound']) && { sound: 'chat' }, + }); + }); + break; + case 'pleroma:follow_relationships_update': + dispatch(updateFollowRelationships(JSON.parse(data.payload))); + break; } }, }; diff --git a/app/soapbox/components/autosuggest_input.js b/app/soapbox/components/autosuggest_input.js index ddf926987..1e052f782 100644 --- a/app/soapbox/components/autosuggest_input.js +++ b/app/soapbox/components/autosuggest_input.js @@ -109,46 +109,46 @@ export default class AutosuggestInput extends ImmutablePureComponent { } switch (e.key) { - case 'Escape': - if (suggestions.size === 0 || suggestionsHidden) { - document.querySelector('.ui').parentElement.focus(); - } else { - e.preventDefault(); - this.setState({ suggestionsHidden: true }); - } - - break; - case 'ArrowDown': - if (!suggestionsHidden && (suggestions.size > 0 || menu)) { - e.preventDefault(); - this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, lastIndex) }); - } - - break; - case 'ArrowUp': - if (!suggestionsHidden && (suggestions.size > 0 || menu)) { - e.preventDefault(); - this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, firstIndex) }); - } - - break; - case 'Enter': - case 'Tab': - // Select suggestion - if (!suggestionsHidden && selectedSuggestion > -1 && (suggestions.size > 0 || menu)) { - e.preventDefault(); - e.stopPropagation(); - this.setState({ selectedSuggestion: firstIndex }); - - if (selectedSuggestion < suggestions.size) { - this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestions.get(selectedSuggestion)); + case 'Escape': + if (suggestions.size === 0 || suggestionsHidden) { + document.querySelector('.ui').parentElement.focus(); } else { - const item = menu[selectedSuggestion - suggestions.size]; - this.handleMenuItemAction(item); + e.preventDefault(); + this.setState({ suggestionsHidden: true }); } - } - break; + break; + case 'ArrowDown': + if (!suggestionsHidden && (suggestions.size > 0 || menu)) { + e.preventDefault(); + this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, lastIndex) }); + } + + break; + case 'ArrowUp': + if (!suggestionsHidden && (suggestions.size > 0 || menu)) { + e.preventDefault(); + this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, firstIndex) }); + } + + break; + case 'Enter': + case 'Tab': + // Select suggestion + if (!suggestionsHidden && selectedSuggestion > -1 && (suggestions.size > 0 || menu)) { + e.preventDefault(); + e.stopPropagation(); + this.setState({ selectedSuggestion: firstIndex }); + + if (selectedSuggestion < suggestions.size) { + this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestions.get(selectedSuggestion)); + } else { + const item = menu[selectedSuggestion - suggestions.size]; + this.handleMenuItemAction(item); + } + } + + break; } if (e.defaultPrevented || !this.props.onKeyDown) { diff --git a/app/soapbox/components/autosuggest_textarea.js b/app/soapbox/components/autosuggest_textarea.js index 03e3465da..ac3a35e2d 100644 --- a/app/soapbox/components/autosuggest_textarea.js +++ b/app/soapbox/components/autosuggest_textarea.js @@ -98,39 +98,39 @@ export default class AutosuggestTextarea extends ImmutablePureComponent { } switch (e.key) { - case 'Escape': - if (suggestions.size === 0 || suggestionsHidden) { - document.querySelector('.ui').parentElement.focus(); - } else { - e.preventDefault(); - this.setState({ suggestionsHidden: true }); - } + case 'Escape': + if (suggestions.size === 0 || suggestionsHidden) { + document.querySelector('.ui').parentElement.focus(); + } else { + e.preventDefault(); + this.setState({ suggestionsHidden: true }); + } - break; - case 'ArrowDown': - if (suggestions.size > 0 && !suggestionsHidden) { - e.preventDefault(); - this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, suggestions.size - 1) }); - } + break; + case 'ArrowDown': + if (suggestions.size > 0 && !suggestionsHidden) { + e.preventDefault(); + this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, suggestions.size - 1) }); + } - break; - case 'ArrowUp': - if (suggestions.size > 0 && !suggestionsHidden) { - e.preventDefault(); - this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, 0) }); - } + break; + case 'ArrowUp': + if (suggestions.size > 0 && !suggestionsHidden) { + e.preventDefault(); + this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, 0) }); + } - break; - case 'Enter': - case 'Tab': + break; + case 'Enter': + case 'Tab': // Select suggestion - if (this.state.lastToken !== null && suggestions.size > 0 && !suggestionsHidden) { - e.preventDefault(); - e.stopPropagation(); - this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestions.get(selectedSuggestion)); - } + if (this.state.lastToken !== null && suggestions.size > 0 && !suggestionsHidden) { + e.preventDefault(); + e.stopPropagation(); + this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestions.get(selectedSuggestion)); + } - break; + break; } if (e.defaultPrevented || !this.props.onKeyDown) { diff --git a/app/soapbox/components/dropdown_menu.tsx b/app/soapbox/components/dropdown_menu.tsx index 6cbc3e678..cf4b09b7c 100644 --- a/app/soapbox/components/dropdown_menu.tsx +++ b/app/soapbox/components/dropdown_menu.tsx @@ -96,28 +96,28 @@ class DropdownMenu extends React.PureComponent { handleButtonKeyDown: React.EventHandler = (e) => { switch (e.key) { - case ' ': - case 'Enter': - this.handleMouseDown(e); - break; + case ' ': + case 'Enter': + this.handleMouseDown(e); + break; } } handleKeyPress: React.EventHandler> = (e) => { switch (e.key) { - case ' ': - case 'Enter': - this.handleClick(e); - e.stopPropagation(); - e.preventDefault(); - break; + case ' ': + case 'Enter': + this.handleClick(e); + e.stopPropagation(); + e.preventDefault(); + break; } } diff --git a/app/soapbox/components/emoji_selector.tsx b/app/soapbox/components/emoji_selector.tsx index 0533f6a69..da8249fa9 100644 --- a/app/soapbox/components/emoji_selector.tsx +++ b/app/soapbox/components/emoji_selector.tsx @@ -68,22 +68,22 @@ class EmojiSelector extends ImmutablePureComponent { const { onUnfocus } = this.props; switch (e.key) { - case 'Tab': - e.preventDefault(); - if (e.shiftKey) this._selectPreviousEmoji(i); - else this._selectNextEmoji(i); - break; - case 'Left': - case 'ArrowLeft': - this._selectPreviousEmoji(i); - break; - case 'Right': - case 'ArrowRight': - this._selectNextEmoji(i); - break; - case 'Escape': - onUnfocus(); - break; + case 'Tab': + e.preventDefault(); + if (e.shiftKey) this._selectPreviousEmoji(i); + else this._selectNextEmoji(i); + break; + case 'Left': + case 'ArrowLeft': + this._selectPreviousEmoji(i); + break; + case 'Right': + case 'ArrowRight': + this._selectNextEmoji(i); + break; + case 'Escape': + onUnfocus(); + break; } } diff --git a/app/soapbox/components/filter_bar.js b/app/soapbox/components/filter_bar.js index 003a35908..46a7dc748 100644 --- a/app/soapbox/components/filter_bar.js +++ b/app/soapbox/components/filter_bar.js @@ -57,12 +57,12 @@ class FilterBar extends React.PureComponent { let element = null; switch (e.key) { - case 'ArrowRight': - element = items[index + 1] || items[0]; - break; - case 'ArrowLeft': - element = items[index - 1] || items[items.length - 1]; - break; + case 'ArrowRight': + element = items[index + 1] || items[0]; + break; + case 'ArrowLeft': + element = items[index - 1] || items[items.length - 1]; + break; } if (element) { diff --git a/app/soapbox/components/relative_timestamp.js b/app/soapbox/components/relative_timestamp.js index dd4dbc1fd..576de4e63 100644 --- a/app/soapbox/components/relative_timestamp.js +++ b/app/soapbox/components/relative_timestamp.js @@ -54,16 +54,16 @@ const selectUnits = delta => { const getUnitDelay = units => { switch (units) { - case 'second': - return SECOND; - case 'minute': - return MINUTE; - case 'hour': - return HOUR; - case 'day': - return DAY; - default: - return MAX_DELAY; + case 'second': + return SECOND; + case 'minute': + return MINUTE; + case 'hour': + return HOUR; + case 'day': + return DAY; + default: + return MAX_DELAY; } }; diff --git a/app/soapbox/features/audio/index.js b/app/soapbox/features/audio/index.js index 566f489b9..d73b7208c 100644 --- a/app/soapbox/features/audio/index.js +++ b/app/soapbox/features/audio/index.js @@ -413,26 +413,26 @@ class Audio extends React.PureComponent { handleKeyDown = e => { switch (e.key) { - case 'k': - e.preventDefault(); - e.stopPropagation(); - this.togglePlay(); - break; - case 'm': - e.preventDefault(); - e.stopPropagation(); - this.toggleMute(); - break; - case 'j': - e.preventDefault(); - e.stopPropagation(); - this.seekBy(-10); - break; - case 'l': - e.preventDefault(); - e.stopPropagation(); - this.seekBy(10); - break; + case 'k': + e.preventDefault(); + e.stopPropagation(); + this.togglePlay(); + break; + case 'm': + e.preventDefault(); + e.stopPropagation(); + this.toggleMute(); + break; + case 'j': + e.preventDefault(); + e.stopPropagation(); + this.seekBy(-10); + break; + case 'l': + e.preventDefault(); + e.stopPropagation(); + this.seekBy(10); + break; } } diff --git a/app/soapbox/features/auth_login/components/captcha.tsx b/app/soapbox/features/auth_login/components/captcha.tsx index 73acc26cc..465ddc4fd 100644 --- a/app/soapbox/features/auth_login/components/captcha.tsx +++ b/app/soapbox/features/auth_login/components/captcha.tsx @@ -72,25 +72,25 @@ const CaptchaField: React.FC = ({ }, [idempotencyKey]); switch (captcha.get('type')) { - case 'native': - return ( -
- - - + case 'native': + return ( +
+ + + - -
- ); - case 'none': - default: - return null; + +
+ ); + case 'none': + default: + return null; } }; diff --git a/app/soapbox/features/chats/components/chat_message_list.js b/app/soapbox/features/chats/components/chat_message_list.js index 929201b3d..7090d7074 100644 --- a/app/soapbox/features/chats/components/chat_message_list.js +++ b/app/soapbox/features/chats/components/chat_message_list.js @@ -319,12 +319,12 @@ class ChatMessageList extends ImmutablePureComponent { if (lastMessage) { const key = `${curr.get('id')}_divider`; switch (timeChange(lastMessage, curr)) { - case 'today': - acc.push(this.renderDivider(key, intl.formatMessage(messages.today))); - break; - case 'date': - acc.push(this.renderDivider(key, new Date(curr.get('created_at')).toDateString())); - break; + case 'today': + acc.push(this.renderDivider(key, intl.formatMessage(messages.today))); + break; + case 'date': + acc.push(this.renderDivider(key, new Date(curr.get('created_at')).toDateString())); + break; } } diff --git a/app/soapbox/features/compose/components/compose_form.js b/app/soapbox/features/compose/components/compose_form.js index cb1c8791f..eb1fb1557 100644 --- a/app/soapbox/features/compose/components/compose_form.js +++ b/app/soapbox/features/compose/components/compose_form.js @@ -229,8 +229,8 @@ class ComposeForm extends ImmutablePureComponent { const spoilerUpdated = this.props.spoiler !== prevProps.spoiler; if (spoilerUpdated) { switch (this.props.spoiler) { - case true: this.focusSpoilerInput(); break; - case false: this.focusTextarea(); break; + case true: this.focusSpoilerInput(); break; + case false: this.focusTextarea(); break; } } } diff --git a/app/soapbox/features/compose/components/privacy_dropdown.js b/app/soapbox/features/compose/components/privacy_dropdown.js index 87c83903f..9edbd58dc 100644 --- a/app/soapbox/features/compose/components/privacy_dropdown.js +++ b/app/soapbox/features/compose/components/privacy_dropdown.js @@ -56,31 +56,31 @@ class PrivacyDropdownMenu extends React.PureComponent { let element = null; switch (e.key) { - case 'Escape': - this.props.onClose(); - break; - case 'Enter': - this.handleClick(e); - break; - case 'ArrowDown': - element = this.node.childNodes[index + 1] || this.node.firstChild; - break; - case 'ArrowUp': - element = this.node.childNodes[index - 1] || this.node.lastChild; - break; - case 'Tab': - if (e.shiftKey) { - element = this.node.childNodes[index - 1] || this.node.lastChild; - } else { + case 'Escape': + this.props.onClose(); + break; + case 'Enter': + this.handleClick(e); + break; + case 'ArrowDown': element = this.node.childNodes[index + 1] || this.node.firstChild; - } - break; - case 'Home': - element = this.node.firstChild; - break; - case 'End': - element = this.node.lastChild; - break; + break; + case 'ArrowUp': + element = this.node.childNodes[index - 1] || this.node.lastChild; + break; + case 'Tab': + if (e.shiftKey) { + element = this.node.childNodes[index - 1] || this.node.lastChild; + } else { + element = this.node.childNodes[index + 1] || this.node.firstChild; + } + break; + case 'Home': + element = this.node.firstChild; + break; + case 'End': + element = this.node.lastChild; + break; } if (element) { @@ -212,9 +212,9 @@ class PrivacyDropdown extends React.PureComponent { handleKeyDown = e => { switch (e.key) { - case 'Escape': - this.handleClose(); - break; + case 'Escape': + this.handleClose(); + break; } } @@ -226,10 +226,10 @@ class PrivacyDropdown extends React.PureComponent { handleButtonKeyDown = (e) => { switch (e.key) { - case ' ': - case 'Enter': - this.handleMouseDown(); - break; + case ' ': + case 'Enter': + this.handleMouseDown(); + break; } } diff --git a/app/soapbox/features/introduction/index.js b/app/soapbox/features/introduction/index.js index 45af64e0c..34b868847 100644 --- a/app/soapbox/features/introduction/index.js +++ b/app/soapbox/features/introduction/index.js @@ -132,12 +132,12 @@ class Introduction extends React.PureComponent { handleKeyUp = ({ key }) => { switch (key) { - case 'ArrowLeft': - this.handlePrev(); - break; - case 'ArrowRight': - this.handleNext(); - break; + case 'ArrowLeft': + this.handlePrev(); + break; + case 'ArrowRight': + this.handleNext(); + break; } } diff --git a/app/soapbox/features/notifications/components/notification.tsx b/app/soapbox/features/notifications/components/notification.tsx index 26f56025f..c4bd4add6 100644 --- a/app/soapbox/features/notifications/components/notification.tsx +++ b/app/soapbox/features/notifications/components/notification.tsx @@ -214,46 +214,46 @@ const Notification: React.FC = (props) => { const renderContent = () => { switch (type) { - case 'follow': - case 'follow_request': - return account && typeof account === 'object' ? ( -