From 005af7ea56e36be6855d04092dc1957e9d1c65a6 Mon Sep 17 00:00:00 2001 From: bhavik001 <95668553+bhavik001@users.noreply.github.com> Date: Wed, 6 Dec 2023 23:57:46 -0500 Subject: [PATCH] Enforce braces for `if`-`else` and `switch`-`case` (#3474) Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Co-authored-by: Olga Bulat --- automations/js/src/project_thread_updates.js | 7 +- .../components/VAudioTrack/VAudioControl.vue | 5 +- .../components/VAudioTrack/VAudioTrack.vue | 55 ++++++++++----- .../VAudioTrack/VGlobalAudioTrack.vue | 23 +++++-- .../src/components/VAudioTrack/VWaveform.vue | 13 +++- .../VCollectionHeader/VCollectionHeader.vue | 4 +- frontend/src/components/VCollectionPage.vue | 12 ++-- .../VGlobalAudioSection.vue | 23 +++++-- .../VHeader/VHeaderMobile/VHeaderMobile.vue | 14 ++-- .../VHeader/VSearchBar/VSearchBar.vue | 11 ++- .../src/components/VImageCell/VImageCell.vue | 4 +- frontend/src/components/VItemGroup/VItem.vue | 15 ++-- .../src/components/VItemGroup/VItemGroup.vue | 21 ++++-- frontend/src/components/VLink.vue | 4 +- frontend/src/components/VLoadMore.vue | 4 +- .../components/VMediaInfo/VByLine/VByLine.vue | 16 +++-- .../components/VMediaInfo/VCopyLicense.vue | 4 +- .../components/VMediaInfo/VMediaDetails.vue | 4 +- .../src/components/VMediaInfo/VMetadata.vue | 4 +- .../VSearchResultsGrid/VAudioResult.vue | 4 +- .../components/VSkeleton/VGridSkeleton.vue | 12 +++- frontend/src/components/VSourcesTable.vue | 8 ++- frontend/src/components/VTabs/VTab.vue | 23 +++++-- frontend/src/components/VTabs/VTabs.vue | 20 ++++-- frontend/src/composables/default-ref.ts | 4 +- .../src/composables/use-body-scroll-lock.ts | 4 +- .../src/composables/use-dialog-content.ts | 12 +++- .../src/composables/use-dialog-control.ts | 8 ++- .../composables/use-event-listener-outside.ts | 19 ++++-- frontend/src/composables/use-floating-ui.ts | 8 ++- frontend/src/composables/use-focus-on-blur.ts | 16 +++-- frontend/src/composables/use-focus-on-hide.ts | 28 ++++++-- frontend/src/composables/use-focus-on-show.ts | 8 ++- frontend/src/composables/use-focus-trap.ts | 16 +++-- .../composables/use-hide-on-click-outside.ts | 4 +- frontend/src/composables/use-i18n-sync.ts | 4 +- .../src/composables/use-image-cell-size.ts | 8 ++- frontend/src/composables/use-match-routes.ts | 4 +- frontend/src/composables/use-search-type.ts | 4 +- frontend/src/composables/use-search.ts | 16 +++-- frontend/src/composables/use-seekable.ts | 15 ++-- .../src/composables/use-sensitive-media.ts | 4 +- .../use-single-result-page-meta.ts | 8 ++- frontend/src/locales/scripts/json-helpers.js | 4 +- .../src/locales/scripts/json-pot-helpers.js | 20 ++++-- frontend/src/locales/scripts/read-i18n.js | 33 ++++++--- frontend/src/locales/scripts/utils.js | 8 ++- frontend/src/middleware/search.ts | 4 +- frontend/src/pages/image/_id/index.vue | 4 +- frontend/src/pages/search.vue | 4 +- frontend/src/stores/feature-flag.ts | 32 ++++++--- frontend/src/stores/media/index.ts | 20 ++++-- frontend/src/stores/media/single-result.ts | 4 +- frontend/src/stores/search.ts | 8 ++- frontend/src/stores/ui.ts | 3 +- frontend/src/utils/attribution-html.ts | 36 +++++++--- frontend/src/utils/case.ts | 16 +++-- frontend/src/utils/decode-data.ts | 4 +- frontend/src/utils/decode-media-data.ts | 4 +- frontend/src/utils/dom.ts | 8 ++- frontend/src/utils/errors.ts | 4 +- frontend/src/utils/focus-management.ts | 68 ++++++++++++++----- frontend/src/utils/metadata.ts | 3 +- frontend/src/utils/reakit-utils/dom.ts | 4 +- frontend/src/utils/reakit-utils/focus.ts | 44 +++++++++--- frontend/src/utils/search-query-transform.ts | 4 +- frontend/src/utils/string-to-boolean.ts | 17 +++-- frontend/src/utils/translation-banner.ts | 4 +- .../playwright/e2e/recent-searches.spec.ts | 4 +- frontend/test/playwright/utils/breakpoints.ts | 3 +- frontend/test/playwright/utils/navigation.ts | 8 ++- frontend/test/proxy.js | 3 +- .../specs/stores/feature-flag-store.spec.js | 3 +- .../test/unit/test-utils/api-service-mock.ts | 4 +- packages/eslint-plugin/src/configs/index.ts | 2 + .../src/rules/analytics-configuration.ts | 15 ++-- 76 files changed, 660 insertions(+), 242 deletions(-) diff --git a/automations/js/src/project_thread_updates.js b/automations/js/src/project_thread_updates.js index 1ad54e9db24..5ffc944d236 100644 --- a/automations/js/src/project_thread_updates.js +++ b/automations/js/src/project_thread_updates.js @@ -86,12 +86,15 @@ module.exports = async ({ github, core }) => { issue.__typename !== 'Issue' || issue.state !== 'OPEN' || new Date(issue.createdAt) > requiredUpdatedByDate - ) + ) { continue + } // Check the status of the card to make sure the project is in active development const status = node.fieldValueByName.name - if (!activeDevelopmentStatuses.includes(status)) continue + if (!activeDevelopmentStatuses.includes(status)) { + continue + } const comments = issue.comments.nodes diff --git a/frontend/src/components/VAudioTrack/VAudioControl.vue b/frontend/src/components/VAudioTrack/VAudioControl.vue index e74d01b6f17..1decd3f6b4a 100644 --- a/frontend/src/components/VAudioTrack/VAudioControl.vue +++ b/frontend/src/components/VAudioTrack/VAudioControl.vue @@ -148,7 +148,10 @@ export default defineComponent({ const iSize = computed(() => sizes[props.size].icon) const handleMouseDown = (event: MouseEvent) => { - if (!props.isTabbable) event.preventDefault() // to prevent focus + if (!props.isTabbable) { + // to prevent focus + event.preventDefault() + } } const handleClick = () => { emit("toggle", isPlaying.value || isLoading.value ? "paused" : "playing") diff --git a/frontend/src/components/VAudioTrack/VAudioTrack.vue b/frontend/src/components/VAudioTrack/VAudioTrack.vue index 14663256080..340d5ac9c2f 100644 --- a/frontend/src/components/VAudioTrack/VAudioTrack.vue +++ b/frontend/src/components/VAudioTrack/VAudioTrack.vue @@ -166,7 +166,9 @@ export default defineComponent({ const initLocalAudio = () => { // Preserve existing local audio if we plucked it from the global active audio - if (!localAudio) localAudio = new Audio(props.audio.url) + if (!localAudio) { + localAudio = new Audio(props.audio.url) + } Object.entries(eventMap).forEach(([name, fn]) => /** @@ -279,12 +281,15 @@ export default defineComponent({ if (localAudio) { return localAudio.duration } - if (typeof props.audio?.duration === "number") + if (typeof props.audio?.duration === "number") { return props.audio.duration / 1e3 + } return 0 }) const setDuration = () => { - if (localAudio) duration.value = localAudio.duration + if (localAudio) { + duration.value = localAudio.duration + } } const eventMap = { @@ -309,10 +314,14 @@ export default defineComponent({ * `localAudio` variable. This is the earliest in * `setup` that this can be called. */ - if (localAudio) initLocalAudio() + if (localAudio) { + initLocalAudio() + } onUnmounted(() => { - if (!localAudio) return + if (!localAudio) { + return + } Object.entries(eventMap).forEach(([name, fn]) => localAudio?.removeEventListener(name, fn) @@ -351,7 +360,9 @@ export default defineComponent({ const play = () => { // Delay initializing the local audio element until playback is requested - if (!localAudio) initLocalAudio() + if (!localAudio) { + initLocalAudio() + } const playPromise = localAudio?.play() // Check if the audio can be played successfully @@ -359,18 +370,22 @@ export default defineComponent({ playPromise.catch((err) => { let message: string switch (err.name) { - case "NotAllowedError": + case "NotAllowedError": { message = "err_unallowed" break - case "NotSupportedError": + } + case "NotSupportedError": { message = "err_unsupported" break - case "AbortError": + } + case "AbortError": { message = "err_aborted" break - default: + } + default: { message = "err_unknown" $sentry.captureException(err) + } } activeMediaStore.setMessage({ message }) localAudio?.pause() @@ -410,31 +425,37 @@ export default defineComponent({ let event: AudioInteraction | undefined = undefined if (!state) { switch (status.value) { - case "playing": + case "playing": { state = "paused" break + } case "paused": - case "played": + case "played": { state = "playing" break + } } } switch (state) { - case "playing": + case "playing": { play() event = "play" break - case "paused": + } + case "paused": { pause() event = "pause" break + } } emitInteracted(event) } const emitInteracted = (event?: AudioInteraction) => { - if (!event) return + if (!event) { + return + } snackbar.dismiss() emit("interacted", { event, @@ -446,7 +467,9 @@ export default defineComponent({ /* Interface with VWaveform */ const handleSeeked = (frac: number) => { - if (!localAudio) initLocalAudio() + if (!localAudio) { + initLocalAudio() + } /** * Calling initLocalAudio will guarantee localAudio * to be an HTMLAudioElement, but we can't prove that diff --git a/frontend/src/components/VAudioTrack/VGlobalAudioTrack.vue b/frontend/src/components/VAudioTrack/VGlobalAudioTrack.vue index fb9321524e0..12ea0fdc6fa 100644 --- a/frontend/src/components/VAudioTrack/VGlobalAudioTrack.vue +++ b/frontend/src/components/VAudioTrack/VGlobalAudioTrack.vue @@ -82,8 +82,9 @@ export default defineComponent({ const status = ref("paused") const currentTime = ref(0) const duration = defaultRef(() => { - if (typeof props.audio?.duration === "number") + if (typeof props.audio?.duration === "number") { return props.audio.duration / 1e3 + } return 0 }) @@ -108,7 +109,9 @@ export default defineComponent({ } } const setDuration = () => { - if (activeAudio.obj.value) duration.value = activeAudio.obj.value.duration + if (activeAudio.obj.value) { + duration.value = activeAudio.obj.value.duration + } } const updateTimeLoop = () => { @@ -145,7 +148,9 @@ export default defineComponent({ watch( activeAudio.obj, (audio, _, onInvalidate) => { - if (!audio) return + if (!audio) { + return + } Object.entries(eventMap).forEach(([name, fn]) => audio.addEventListener(name, fn) @@ -211,25 +216,29 @@ export default defineComponent({ ) => { if (!state) { switch (status.value) { - case "playing": + case "playing": { state = "paused" break + } case "paused": - case "played": + case "played": { state = "playing" break + } } } let event: AudioInteraction | undefined = undefined switch (state) { - case "playing": + case "playing": { play() event = "play" break - case "paused": + } + case "paused": { pause() event = "pause" break + } } if (event) { sendAudioInteractionEvent(event) diff --git a/frontend/src/components/VAudioTrack/VWaveform.vue b/frontend/src/components/VAudioTrack/VWaveform.vue index fcd7bcafb96..c37e4777bc1 100644 --- a/frontend/src/components/VAudioTrack/VWaveform.vue +++ b/frontend/src/components/VAudioTrack/VWaveform.vue @@ -368,7 +368,9 @@ export default defineComponent({ isDragging.value ? seekTimestamp.value : props.currentTime ) const isProgressTimestampCutoff = computed(() => { - if (!progressTimestampEl.value) return false + if (!progressTimestampEl.value) { + return false + } const barWidth = progressBarWidth.value const timestampWidth = progressTimestampEl.value.offsetWidth return barWidth < timestampWidth + 2 @@ -399,7 +401,9 @@ export default defineComponent({ seekFrac.value ? seekFrac.value * props.duration : props.duration ) const isSeekTimestampCutoff = computed(() => { - if (!seekTimestampEl.value) return false + if (!seekTimestampEl.value) { + return false + } const barWidth = seekBarWidth.value const timestampWidth = seekTimestampEl.value.offsetWidth return barWidth < timestampWidth + 2 @@ -443,7 +447,10 @@ export default defineComponent({ let startPos: null | number = null const isDragging = ref(false) const handleMouseDown = (event: MouseEvent) => { - if (!props.isTabbable) event.preventDefault() // to prevent focus + if (!props.isTabbable) { + // to prevent focus + event.preventDefault() + } isDragging.value = false startPos = getPosition(event) setSeekProgress(event) diff --git a/frontend/src/components/VCollectionHeader/VCollectionHeader.vue b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue index 1edca9bd328..8ae307d215b 100644 --- a/frontend/src/components/VCollectionHeader/VCollectionHeader.vue +++ b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue @@ -139,7 +139,9 @@ export default defineComponent({ const { sendCustomEvent } = useAnalytics() const sendAnalyticsEvent = () => { - if (props.collectionParams.collection === "tag") return + if (props.collectionParams.collection === "tag") { + return + } const eventName = props.collectionParams.collection === "creator" diff --git a/frontend/src/components/VCollectionPage.vue b/frontend/src/components/VCollectionPage.vue index 3fff6d953d2..3bca3fa7923 100644 --- a/frontend/src/components/VCollectionPage.vue +++ b/frontend/src/components/VCollectionPage.vue @@ -70,27 +70,31 @@ export default defineComponent({ const collectionLabel = computed(() => { const collection = collectionParams.value?.collection switch (collection) { - case "tag": + case "tag": { return i18n .t(`collection.ariaLabel.tag.${props.mediaType}`, { tag: collectionParams.value?.tag, }) .toString() - case "source": + } + case "source": { return i18n .t(`collection.ariaLabel.source.${props.mediaType}`, { source: collectionParams.value?.source, }) .toString() - case "creator": + } + case "creator": { return i18n .t(`collection.ariaLabel.creator.${props.mediaType}`, { creator: collectionParams.value?.creator, source: collectionParams.value?.source, }) .toString() - default: + } + default: { return "" + } } }) diff --git a/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue b/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue index 8a8e0bc5f48..b55edf5c70e 100644 --- a/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue +++ b/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue @@ -77,23 +77,30 @@ export default defineComponent({ return } const error = event.target.error - if (!error) return + if (!error) { + return + } let errorMsg switch (error.code) { - case error.MEDIA_ERR_ABORTED: + case error.MEDIA_ERR_ABORTED: { errorMsg = "err_aborted" break - case error.MEDIA_ERR_NETWORK: + } + case error.MEDIA_ERR_NETWORK: { errorMsg = "err_network" break - case error.MEDIA_ERR_DECODE: + } + case error.MEDIA_ERR_DECODE: { errorMsg = "err_decode" break - case error.MEDIA_ERR_SRC_NOT_SUPPORTED: + } + case error.MEDIA_ERR_SRC_NOT_SUPPORTED: { errorMsg = "err_unsupported" break - default: + } + default: { errorMsg = "err_unknown" + } } activeMediaStore.setMessage({ message: errorMsg }) } @@ -101,7 +108,9 @@ export default defineComponent({ watch( activeAudio.obj, (audio, _, onInvalidate) => { - if (!audio) return + if (!audio) { + return + } audio.addEventListener("error", handleError) onInvalidate(() => { diff --git a/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue b/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue index 06bade0a8c4..7d09ff887b8 100644 --- a/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue +++ b/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue @@ -182,7 +182,9 @@ export default defineComponent({ * Without `nextTick`, the search bar is not focused on click in Firefox */ nextTick(() => { - if (searchInputRef.value) ensureFocus(searchInputRef.value) + if (searchInputRef.value) { + ensureFocus(searchInputRef.value) + } }) } else { isRecentSearchesModalOpen.value = false @@ -220,7 +222,9 @@ export default defineComponent({ const { key, altKey } = event // Show the recent searches. isRecentSearchesModalOpen.value = true - if (altKey) return + if (altKey) { + return + } // Shift selection (if Alt was not pressed with arrow keys) let defaultValue: number let offset: number @@ -240,12 +244,14 @@ export default defineComponent({ } const handleOtherKeys = (event: KeyboardEvent) => { const { key } = event - if (key === keycodes.Enter && selectedIdx.value) + if (key === keycodes.Enter && selectedIdx.value) { // If a recent search is selected, populate its value into the input. searchTerm.value = entries.value[selectedIdx.value] - if (([keycodes.Escape] as string[]).includes(key)) + } + if (([keycodes.Escape] as string[]).includes(key)) { // Hide the recent searches. isRecentSearchesModalOpen.value = false + } selectedIdx.value = undefined // Lose visual focus from entries. } const handleKeydown = (event: KeyboardEvent) => { diff --git a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue index 02b562e5ae9..54fcba7dc9a 100644 --- a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue +++ b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue @@ -147,7 +147,9 @@ export default defineComponent({ * Hide recent searches on blur and click outside. */ const handleSearchBlur = () => { - if (!entries.value.length) hideRecentSearches() + if (!entries.value.length) { + hideRecentSearches() + } } onClickOutside(searchBarEl, hideRecentSearches) @@ -164,7 +166,9 @@ export default defineComponent({ const { key, altKey } = event showRecentSearches() - if (altKey) return + if (altKey) { + return + } // Shift selection (if Alt was not pressed with arrow keys) let defaultValue: number @@ -187,9 +191,10 @@ export default defineComponent({ const handleOtherKeys = (event: KeyboardEvent) => { const { key } = event - if (key === keycodes.Enter && selectedIdx.value) + if (key === keycodes.Enter && selectedIdx.value) { // If a recent search is selected, populate its value into the input. modelMedium.value = entries.value[selectedIdx.value] + } // Hide the recent searches popover when the user presses Enter, Escape or Shift+Tab on the input. if ( diff --git a/frontend/src/components/VImageCell/VImageCell.vue b/frontend/src/components/VImageCell/VImageCell.vue index 8997123026e..a25f3379259 100644 --- a/frontend/src/components/VImageCell/VImageCell.vue +++ b/frontend/src/components/VImageCell/VImageCell.vue @@ -166,7 +166,9 @@ export default defineComponent({ * @param event - the load event. */ const getImgDimension = (event: Event) => { - if (props.aspectRatio === "square") return + if (props.aspectRatio === "square") { + return + } const element = event.target as HTMLImageElement imgHeight.value = element.naturalHeight imgWidth.value = element.naturalWidth diff --git a/frontend/src/components/VItemGroup/VItem.vue b/frontend/src/components/VItemGroup/VItem.vue index 74b05230ea6..7124d77cb03 100644 --- a/frontend/src/components/VItemGroup/VItem.vue +++ b/frontend/src/components/VItemGroup/VItem.vue @@ -139,18 +139,25 @@ export default defineComponent({ const tabIndex = computed(() => { // If outside a radiogroup then everything can be tabbable in order - if (contextProps.type !== "radiogroup") return 0 + if (contextProps.type !== "radiogroup") { + return 0 + } // If no items are selected then all can be tabbable to ensure it is possible to enter into the group if ( focusContext.selectedCount.value === 0 && props.isFirst && !focusContext.isGroupFocused.value - ) + ) { return 0 + } // If this one is focused then it should be the tabbable item - if (isFocused.value) return 0 + if (isFocused.value) { + return 0 + } // If the group is not focused but this is the selected item, then this should be the focusable item when focusing into the group - if (!focusContext.isGroupFocused.value && props.selected) return 0 + if (!focusContext.isGroupFocused.value && props.selected) { + return 0 + } // Otherwise, the item should not be tabbable. The logic above guarantees that at least one other item in the group will be tabbable. return -1 diff --git a/frontend/src/components/VItemGroup/VItemGroup.vue b/frontend/src/components/VItemGroup/VItemGroup.vue index 613993c10f9..015023d5a1e 100644 --- a/frontend/src/components/VItemGroup/VItemGroup.vue +++ b/frontend/src/components/VItemGroup/VItemGroup.vue @@ -134,7 +134,9 @@ export default defineComponent({ } const onItemKeyPress = (event: KeyboardEvent): undefined | number => { - if (!(arrows as string[]).includes(event.key) || !nodeRef.value) return + if (!(arrows as string[]).includes(event.key) || !nodeRef.value) { + return + } event.preventDefault() @@ -149,19 +151,22 @@ export default defineComponent({ switch (event.key) { case keycodes.ArrowUp: - case resolveArrow(keycodes.ArrowLeft, keycodes.ArrowRight): + case resolveArrow(keycodes.ArrowLeft, keycodes.ArrowRight): { if (targetIndex === 0) { return ensureFocus(items[items.length - 1]) } return ensureFocus(items[targetIndex - 1]) + } case keycodes.ArrowDown: - case resolveArrow(keycodes.ArrowRight, keycodes.ArrowLeft): + case resolveArrow(keycodes.ArrowRight, keycodes.ArrowLeft): { if (targetIndex === items.length - 1) { return ensureFocus(items[0]) } return ensureFocus(items[targetIndex + 1]) - default: + } + default: { return + } } } @@ -172,8 +177,12 @@ export default defineComponent({ * @param previousSelected */ const setSelected = (selected: boolean, previousSelected: boolean) => { - if (previousSelected && !selected) selectedCount.value -= 1 - if (!previousSelected && selected) selectedCount.value += 1 + if (previousSelected && !selected) { + selectedCount.value -= 1 + } + if (!previousSelected && selected) { + selectedCount.value += 1 + } } const focusContext = { diff --git a/frontend/src/components/VLink.vue b/frontend/src/components/VLink.vue index 2fbd6e55955..0c811ea84d7 100644 --- a/frontend/src/components/VLink.vue +++ b/frontend/src/components/VLink.vue @@ -138,7 +138,9 @@ export default defineComponent({ const { sendCustomEvent } = useAnalytics() const handleExternalClick = () => { - if (!checkHref(props) || !props.sendExternalLinkClickEvent) return + if (!checkHref(props) || !props.sendExternalLinkClickEvent) { + return + } sendCustomEvent("EXTERNAL_LINK_CLICK", { url: props.href, }) diff --git a/frontend/src/components/VLoadMore.vue b/frontend/src/components/VLoadMore.vue index da9cadce49d..2d17512136a 100644 --- a/frontend/src/components/VLoadMore.vue +++ b/frontend/src/components/VLoadMore.vue @@ -75,7 +75,9 @@ export default defineComponent({ * */ const onLoadMore = async () => { - if (fetchState.value.isFetching) return + if (fetchState.value.isFetching) { + return + } reachResultEndEventSent.value = false diff --git a/frontend/src/components/VMediaInfo/VByLine/VByLine.vue b/frontend/src/components/VMediaInfo/VByLine/VByLine.vue index cb5c7709f80..46e9209597c 100644 --- a/frontend/src/components/VMediaInfo/VByLine/VByLine.vue +++ b/frontend/src/components/VMediaInfo/VByLine/VByLine.vue @@ -147,7 +147,9 @@ export default defineComponent({ ) onMounted(() => { - if (!buttonsRef.value || !containerRef.value) return + if (!buttonsRef.value || !containerRef.value) { + return + } if (buttonsRef.value?.scrollWidth > containerRef.value.scrollWidth) { setScrollable() } @@ -173,7 +175,9 @@ export default defineComponent({ } const scroll = (to: "start" | "end") => { - if (!buttonsRef.value) return + if (!buttonsRef.value) { + return + } const buttons = buttonsRef.value showScrollButton[to === "start" ? "end" : "start"] = true @@ -203,7 +207,9 @@ export default defineComponent({ watchDebounced( x, (xValue) => { - if (!buttonsRef.value) return + if (!buttonsRef.value) { + return + } // This is necessary for handling both RTL and LTR. const distFromStart = Math.abs(xValue) const distFromEnd = @@ -219,7 +225,9 @@ export default defineComponent({ const searchStore = useSearchStore() const creatorHref = computed(() => { - if (!props.creator) return undefined + if (!props.creator) { + return undefined + } return searchStore.getCollectionPath({ type: props.mediaType, collectionParams: { diff --git a/frontend/src/components/VMediaInfo/VCopyLicense.vue b/frontend/src/components/VMediaInfo/VCopyLicense.vue index a6244acaf6e..7c7acd59a2b 100644 --- a/frontend/src/components/VMediaInfo/VCopyLicense.vue +++ b/frontend/src/components/VMediaInfo/VCopyLicense.vue @@ -76,7 +76,9 @@ export default defineComponent({ const { sendCustomEvent } = useAnalytics() const sendAnalyticsEvent = (event: MouseEvent) => { - if (!event.currentTarget) return + if (!event.currentTarget) { + return + } const url = (event.currentTarget as HTMLAnchorElement).href sendCustomEvent("EXTERNAL_LINK_CLICK", { url }) diff --git a/frontend/src/components/VMediaInfo/VMediaDetails.vue b/frontend/src/components/VMediaInfo/VMediaDetails.vue index c4a319e3f5f..e75de6ce483 100644 --- a/frontend/src/components/VMediaInfo/VMediaDetails.vue +++ b/frontend/src/components/VMediaInfo/VMediaDetails.vue @@ -55,7 +55,9 @@ export default defineComponent({ const i18n = useI18n() const metadata = computed(() => { - if (!props.media) return null + if (!props.media) { + return null + } return getMediaMetadata(props.media, i18n, { width: props.imageWidth, height: props.imageHeight, diff --git a/frontend/src/components/VMediaInfo/VMetadata.vue b/frontend/src/components/VMediaInfo/VMetadata.vue index f072b0fccc2..191642c00cd 100644 --- a/frontend/src/components/VMediaInfo/VMetadata.vue +++ b/frontend/src/components/VMediaInfo/VMetadata.vue @@ -52,7 +52,9 @@ export default defineComponent({ const { sendCustomEvent } = useAnalytics() const sendVisitSourceLinkEvent = (source?: string) => { - if (!source) return + if (!source) { + return + } sendCustomEvent("VISIT_SOURCE_LINK", { id: route.value.params.id, source, diff --git a/frontend/src/components/VSearchResultsGrid/VAudioResult.vue b/frontend/src/components/VSearchResultsGrid/VAudioResult.vue index a3413afbbb3..2c7361639b6 100644 --- a/frontend/src/components/VSearchResultsGrid/VAudioResult.vue +++ b/frontend/src/components/VSearchResultsGrid/VAudioResult.vue @@ -66,7 +66,9 @@ export default defineComponent({ ) => { // Only send the event when the click navigates to the single result page. // If the click is in waveform or audio-control button, it controls the audio player. - if (inWaveform) return + if (inWaveform) { + return + } useAudioSnackbar().hide() sendCustomEvent("SELECT_SEARCH_RESULT", { id: audio.id, diff --git a/frontend/src/components/VSkeleton/VGridSkeleton.vue b/frontend/src/components/VSkeleton/VGridSkeleton.vue index 578a798f2cb..58c4bd3b19e 100644 --- a/frontend/src/components/VSkeleton/VGridSkeleton.vue +++ b/frontend/src/components/VSkeleton/VGridSkeleton.vue @@ -53,9 +53,15 @@ export default defineComponent({ const elementCount = computed(() => { // Calculate the default element count based on isForTab - if (props.numElems) return props.numElems - if (props.isForTab === "all") return 20 - if (props.isForTab === "image") return 30 + if (props.numElems) { + return props.numElems + } + if (props.isForTab === "all") { + return 20 + } + if (props.isForTab === "image") { + return 30 + } return 8 }) diff --git a/frontend/src/components/VSourcesTable.vue b/frontend/src/components/VSourcesTable.vue index 719488bf31a..9b2274b7503 100644 --- a/frontend/src/components/VSourcesTable.vue +++ b/frontend/src/components/VSourcesTable.vue @@ -120,8 +120,12 @@ export default defineComponent({ field1 = cleanSourceUrlForPresentation(field1 as string) field2 = cleanSourceUrlForPresentation(field2 as string) } - if (field1 > field2) return 1 - if (field1 < field2) return -1 + if (field1 > field2) { + return 1 + } + if (field1 < field2) { + return -1 + } return 0 } diff --git a/frontend/src/components/VTabs/VTab.vue b/frontend/src/components/VTabs/VTab.vue index ece0a5da0b8..9b80969d926 100644 --- a/frontend/src/components/VTabs/VTab.vue +++ b/frontend/src/components/VTabs/VTab.vue @@ -78,7 +78,9 @@ export default defineComponent({ const isSelected = computed(() => tabContext.selectedId.value === props.id) const handleFocus = () => { - if (props.disabled) return + if (props.disabled) { + return + } if (tabContext.activation.value === "auto") { tabContext.setSelectedId(props.id) } @@ -86,7 +88,9 @@ export default defineComponent({ } const handleSelection = () => { - if (props.disabled) return + if (props.disabled) { + return + } getDomElement(internalTabRef)?.focus() tabContext.setSelectedId(props.id) } @@ -141,33 +145,38 @@ export default defineComponent({ switch (event.key) { case keycodes.Spacebar: - case keycodes.Enter: + case keycodes.Enter: { tabContext.setSelectedId(props.id) break + } case keycodes.Home: - case keycodes.PageUp: + case keycodes.PageUp: { focusIn(list, Focus.First) break + } case keycodes.End: - case keycodes.PageDown: + case keycodes.PageDown: { focusIn(list, Focus.Last) break - case keycodes.ArrowLeft: + } + case keycodes.ArrowLeft: { focusIn( list, getFocusDirection(keycodes.ArrowLeft, document.dir) | Focus.WrapAround ) break + } - case keycodes.ArrowRight: + case keycodes.ArrowRight: { focusIn( list, getFocusDirection(keycodes.ArrowRight, document.dir) | Focus.WrapAround ) break + } } } diff --git a/frontend/src/components/VTabs/VTabs.vue b/frontend/src/components/VTabs/VTabs.vue index d40ced2f9c2..6e8ab1a13fa 100644 --- a/frontend/src/components/VTabs/VTabs.vue +++ b/frontend/src/components/VTabs/VTabs.vue @@ -97,23 +97,33 @@ export default defineComponent({ tabs, panels, setSelectedId(id: string) { - if (selectedId.value === id) return + if (selectedId.value === id) { + return + } selectedId.value = id emit("change", id) }, registerTab(tab: (typeof tabs)["value"][number]) { - if (!tabs.value.includes(tab)) tabs.value.push(tab) + if (!tabs.value.includes(tab)) { + tabs.value.push(tab) + } }, unregisterTab(tab: (typeof tabs)["value"][number]) { let idx = tabs.value.indexOf(tab) - if (idx !== -1) tabs.value.splice(idx, 1) + if (idx !== -1) { + tabs.value.splice(idx, 1) + } }, registerPanel(panel: (typeof panels)["value"][number]) { - if (!panels.value.includes(panel)) panels.value.push(panel) + if (!panels.value.includes(panel)) { + panels.value.push(panel) + } }, unregisterPanel(panel: (typeof panels)["value"][number]) { let idx = panels.value.indexOf(panel) - if (idx !== -1) panels.value.splice(idx, 1) + if (idx !== -1) { + panels.value.splice(idx, 1) + } }, } provide(tabsContextKey, tabGroupContext) diff --git a/frontend/src/composables/default-ref.ts b/frontend/src/composables/default-ref.ts index d4a97e68096..707c0c38701 100644 --- a/frontend/src/composables/default-ref.ts +++ b/frontend/src/composables/default-ref.ts @@ -12,7 +12,9 @@ export const defaultRef = (getDefault: () => T) => { const explicitlySet = ref(NotSet) return computed({ get() { - if (explicitlySet.value === NotSet) return getDefault() + if (explicitlySet.value === NotSet) { + return getDefault() + } return explicitlySet.value as T }, set(v) { diff --git a/frontend/src/composables/use-body-scroll-lock.ts b/frontend/src/composables/use-body-scroll-lock.ts index 0429eedb56e..94a558c84e1 100644 --- a/frontend/src/composables/use-body-scroll-lock.ts +++ b/frontend/src/composables/use-body-scroll-lock.ts @@ -18,7 +18,9 @@ export function useBodyScrollLock({ watch( nodeRef, (node) => { - if (node && locked.value) lock() + if (node && locked.value) { + lock() + } }, { immediate: true, diff --git a/frontend/src/composables/use-dialog-content.ts b/frontend/src/composables/use-dialog-content.ts index 1b5e7502798..355f1592e3b 100644 --- a/frontend/src/composables/use-dialog-content.ts +++ b/frontend/src/composables/use-dialog-content.ts @@ -78,9 +78,15 @@ export function useDialogContent({ const onKeyDown = (event: KeyboardEvent) => { emit("keydown", event) - if (event.defaultPrevented) return - if (event.key !== "Escape") return - if (!hideOnEscRef.value) return + if (event.defaultPrevented) { + return + } + if (event.key !== "Escape") { + return + } + if (!hideOnEscRef.value) { + return + } event.stopPropagation() hideRef.value() diff --git a/frontend/src/composables/use-dialog-control.ts b/frontend/src/composables/use-dialog-control.ts index ec74ffd8ad1..a880605c40c 100644 --- a/frontend/src/composables/use-dialog-control.ts +++ b/frontend/src/composables/use-dialog-control.ts @@ -62,7 +62,9 @@ export function useDialogControl({ const shouldLockBodyScroll = computed(() => unref(lockBodyScroll) ?? false) watch(shouldLockBodyScroll, (shouldLock) => { if (shouldLock) { - if (internalVisibleRef.value) lock() + if (internalVisibleRef.value) { + lock() + } } else { unlock() } @@ -72,7 +74,9 @@ export function useDialogControl({ const close = () => { const fn = toValue(deactivateFocusTrap) - if (fn) fn() + if (fn) { + fn() + } internalVisibleRef.value = false } diff --git a/frontend/src/composables/use-event-listener-outside.ts b/frontend/src/composables/use-event-listener-outside.ts index a1a1f36e69c..dcdaf13a1dd 100644 --- a/frontend/src/composables/use-event-listener-outside.ts +++ b/frontend/src/composables/use-event-listener-outside.ts @@ -43,21 +43,30 @@ export const useEventListenerOutside = ({ document.removeEventListener(eventType, boundEventRef.value) } - if (!shouldListen) return + if (!shouldListen) { + return + } boundEventRef.value = (event: Event) => { - if (!listener || !container || !(event.target instanceof Element)) + if (!listener || !container || !(event.target instanceof Element)) { return + } const target = event.target // When an element is unmounted right after it receives focus, the focus // event is triggered after that, when the element isn't part of the // current document anymore. So we ignore it. - if (!isInDocument(target)) return + if (!isInDocument(target)) { + return + } // Event inside the container - if (contains(container, target)) return + if (contains(container, target)) { + return + } // Event on the trigger - if (trigger && contains(trigger, target)) return + if (trigger && contains(trigger, target)) { + return + } listener(event) } diff --git a/frontend/src/composables/use-floating-ui.ts b/frontend/src/composables/use-floating-ui.ts index f04b25bdc65..3c4c5811309 100644 --- a/frontend/src/composables/use-floating-ui.ts +++ b/frontend/src/composables/use-floating-ui.ts @@ -74,7 +74,9 @@ export function useFloatingUi({ floatingElRef, floatingPropsRefs }: Props) { cleanup.value?.() return } - if (!visible) return + if (!visible) { + return + } cleanup.value = buildAutoUpdate(triggerElement, floatingElement) @@ -92,7 +94,9 @@ export function useFloatingUi({ floatingElRef, floatingPropsRefs }: Props) { const detectMaxHeight = { name: "detectMaxHeight", async fn(state: MiddlewareState) { - if (!floatingPropsRefs.clippable.value) return {} + if (!floatingPropsRefs.clippable.value) { + return {} + } const overflow = await detectOverflow(state, { padding: FloatingOffset }) const verticalOverflow = Math.max(overflow.top, overflow.bottom) diff --git a/frontend/src/composables/use-focus-on-blur.ts b/frontend/src/composables/use-focus-on-blur.ts index ab16ed70062..d3766206f64 100644 --- a/frontend/src/composables/use-focus-on-blur.ts +++ b/frontend/src/composables/use-focus-on-blur.ts @@ -10,7 +10,9 @@ type Props = { function isActualElement( element: EventTarget | Element | null ): element is Element { - if (!element) return false + if (!element) { + return false + } const elementAsElement = element as Element return !!( elementAsElement.tagName && @@ -31,15 +33,21 @@ export function useFocusOnBlur({ dialogRef, visibleRef }: Props) { const [blurredRef, scheduleFocus] = useBlurTracker() watch([blurredRef], ([blurred]) => { - if (!visibleRef.value) return - if (!blurred) return + if (!visibleRef.value) { + return + } + if (!blurred) { + return + } if (!isActualElement(getActiveElement(dialogRef.value))) { dialogRef.value?.focus() } }) return (event: FocusEvent) => { - if (visibleRef.value) return + if (visibleRef.value) { + return + } const nextActiveElement = event.relatedTarget if (!isActualElement(nextActiveElement as Element)) { scheduleFocus() diff --git a/frontend/src/composables/use-focus-on-hide.ts b/frontend/src/composables/use-focus-on-hide.ts index 6e44fb28f7a..a0cdd5df2e7 100644 --- a/frontend/src/composables/use-focus-on-hide.ts +++ b/frontend/src/composables/use-focus-on-hide.ts @@ -11,13 +11,21 @@ type Props = { } function hidByFocusingAnotherElement(popover: HTMLElement) { - if (!popover) return false + if (!popover) { + return false + } const activeElement = getActiveElement(popover) - if (!activeElement) return false - if (contains(popover, activeElement)) return false - if (isTabbable(activeElement)) return true + if (!activeElement) { + return false + } + if (contains(popover, activeElement)) { + return false + } + if (isTabbable(activeElement)) { + return true + } return activeElement.getAttribute("data-popover") === "true" } @@ -38,11 +46,17 @@ export const useFocusOnHide = ({ const shouldFocus = autoFocusOnHide && !visible && visible !== previousVisible - if (!shouldFocus) return + if (!shouldFocus) { + return + } - if (!dialog || hidByFocusingAnotherElement(dialog)) return + if (!dialog || hidByFocusingAnotherElement(dialog)) { + return + } - if (triggerElement) ensureFocus(triggerElement) + if (triggerElement) { + ensureFocus(triggerElement) + } } ) } diff --git a/frontend/src/composables/use-focus-on-show.ts b/frontend/src/composables/use-focus-on-show.ts index c7e13f4d129..41efabb2625 100644 --- a/frontend/src/composables/use-focus-on-show.ts +++ b/frontend/src/composables/use-focus-on-show.ts @@ -72,10 +72,14 @@ export const useFocusOnShow = ({ ] as const, ([dialog, visible, autoFocusOnShow, initialFocusElement], _, onCleanup) => { if (!dialog || !visible) { - if (trap?.hasFocus) deactivateFocusTrap() + if (trap?.hasFocus) { + deactivateFocusTrap() + } + return + } + if (!autoFocusOnShow) { return } - if (!autoFocusOnShow) return nextTick(() => { const isActive = () => hasFocusWithin(dialog) diff --git a/frontend/src/composables/use-focus-trap.ts b/frontend/src/composables/use-focus-trap.ts index d6ba2db1dab..16659a219d9 100644 --- a/frontend/src/composables/use-focus-trap.ts +++ b/frontend/src/composables/use-focus-trap.ts @@ -101,7 +101,9 @@ export function useFocusTrap( const stopWatcher = watch( () => unrefElement(target), (el) => { - if (!el) return + if (!el) { + return + } trap = createFocusTrap(el, { ...focusTrapOptions, @@ -109,18 +111,24 @@ export function useFocusTrap( hasFocus.value = true // Apply if user provided onActivate option - if (options.onActivate) options.onActivate() + if (options.onActivate) { + options.onActivate() + } }, onDeactivate() { hasFocus.value = false // Apply if user provided onDeactivate option - if (options.onDeactivate) options.onDeactivate() + if (options.onDeactivate) { + options.onDeactivate() + } }, }) // Focus if immediate is set to true - if (immediate) activate() + if (immediate) { + activate() + } }, { flush: "post" } ) diff --git a/frontend/src/composables/use-hide-on-click-outside.ts b/frontend/src/composables/use-hide-on-click-outside.ts index 6aeb1d99a21..dfd67f405f9 100644 --- a/frontend/src/composables/use-hide-on-click-outside.ts +++ b/frontend/src/composables/use-hide-on-click-outside.ts @@ -25,7 +25,9 @@ function useMouseDownTargetRef({ watch( [visibleRef, hideOnClickOutsideRef, dialogRef] as const, ([visible, hideOnClickOutside, popover], _, onInvalidate) => { - if (!(visible && hideOnClickOutside)) return + if (!(visible && hideOnClickOutside)) { + return + } const document = getDocument(popover) const onMouseDown = (event: MouseEvent) => diff --git a/frontend/src/composables/use-i18n-sync.ts b/frontend/src/composables/use-i18n-sync.ts index 0da61ab0ad3..0b7cce6422c 100644 --- a/frontend/src/composables/use-i18n-sync.ts +++ b/frontend/src/composables/use-i18n-sync.ts @@ -14,7 +14,9 @@ export function useI18nSync() { }) const needsTranslationBanner = computed(() => { - if (!currentLocale.value || currentLocale.value.code === "en") return false + if (!currentLocale.value || currentLocale.value.code === "en") { + return false + } return (currentLocale.value?.translated ?? 100) <= 90 }) diff --git a/frontend/src/composables/use-image-cell-size.ts b/frontend/src/composables/use-image-cell-size.ts index 2e16a4c7882..8ee996e2146 100644 --- a/frontend/src/composables/use-image-cell-size.ts +++ b/frontend/src/composables/use-image-cell-size.ts @@ -11,8 +11,12 @@ const squareSize = 250 const defaultImgSize = 100 const getImgAspectRatio = (aspect: number) => { - if (aspect > maxAspect) return maxAspect - if (aspect < minAspect) return minAspect + if (aspect > maxAspect) { + return maxAspect + } + if (aspect < minAspect) { + return minAspect + } return aspect } diff --git a/frontend/src/composables/use-match-routes.ts b/frontend/src/composables/use-match-routes.ts index 6539f3d0d20..3a40af858e7 100644 --- a/frontend/src/composables/use-match-routes.ts +++ b/frontend/src/composables/use-match-routes.ts @@ -23,7 +23,9 @@ export const useMatchRoute = ( * @param route - the localized route name (e.g. `search__en`) */ const routeNameMatches = (route: string | null | undefined) => { - if (!route) return false + if (!route) { + return false + } return routes.includes(route.split("__")[0]) } diff --git a/frontend/src/composables/use-search-type.ts b/frontend/src/composables/use-search-type.ts index ff9ad26e7a3..970b888a0c5 100644 --- a/frontend/src/composables/use-search-type.ts +++ b/frontend/src/composables/use-search-type.ts @@ -56,7 +56,9 @@ export default function useSearchType() { const searchTypes = [...supportedSearchTypes] const setActiveType = (searchType: SearchType) => { - if (previousSearchType.value === searchType) return + if (previousSearchType.value === searchType) { + return + } analytics.sendCustomEvent("CHANGE_CONTENT_TYPE", { previous: previousSearchType.value, diff --git a/frontend/src/composables/use-search.ts b/frontend/src/composables/use-search.ts index 3e3617d44ea..2c8c27aa431 100644 --- a/frontend/src/composables/use-search.ts +++ b/frontend/src/composables/use-search.ts @@ -57,8 +57,12 @@ export const useSearch = ( * to run and fetch new media. */ const updateSearchState = () => { - if (searchTerm.value === "") return - if (!searchTermChanged.value && isSearchRoute.value) return + if (searchTerm.value === "") { + return + } + if (!searchTermChanged.value && isSearchRoute.value) { + return + } sendCustomEvent("SUBMIT_SEARCH", { searchType: searchStore.searchType, @@ -80,8 +84,12 @@ export const useSearch = ( * Shows the loading state or result count. */ const searchStatus = computed(() => { - if (searchStore.searchTerm === "") return "" - if (isFetching.value) return getLoading() + if (searchStore.searchTerm === "") { + return "" + } + if (isFetching.value) { + return getLoading() + } return getI18nCount(resultsCount.value) }) diff --git a/frontend/src/composables/use-seekable.ts b/frontend/src/composables/use-seekable.ts index 307629f9ba8..b42e83cd7d4 100644 --- a/frontend/src/composables/use-seekable.ts +++ b/frontend/src/composables/use-seekable.ts @@ -78,16 +78,23 @@ export const useSeekable = ({ } const handleKeys = (event: KeyboardEvent) => { - if (!willBeHandled(event)) return + if (!willBeHandled(event)) { + return + } event.preventDefault() isSeeking.value = (seekingKeys as string[]).includes(event.key) - if ((arrowKeys as string[]).includes(event.key)) + if ((arrowKeys as string[]).includes(event.key)) { return handleArrowKeys(event) - if (event.key === keycodes.Home) return onSeek(0) - if (event.key === keycodes.End) return onSeek(1) + } + if (event.key === keycodes.Home) { + return onSeek(0) + } + if (event.key === keycodes.End) { + return onSeek(1) + } if (event.key === keycodes.Spacebar) { return onTogglePlayback() } diff --git a/frontend/src/composables/use-sensitive-media.ts b/frontend/src/composables/use-sensitive-media.ts index 9d42900780b..97d4fa2eb76 100644 --- a/frontend/src/composables/use-sensitive-media.ts +++ b/frontend/src/composables/use-sensitive-media.ts @@ -55,7 +55,9 @@ export function useSensitiveMedia( function hide() { const media = unref(rawMedia) - if (!media) return + if (!media) { + return + } const index = uiStore.revealedSensitiveResults.indexOf(media.id) if (index > -1) { uiStore.revealedSensitiveResults.splice(index, 1) diff --git a/frontend/src/composables/use-single-result-page-meta.ts b/frontend/src/composables/use-single-result-page-meta.ts index b80191020e7..3503539ecf3 100644 --- a/frontend/src/composables/use-single-result-page-meta.ts +++ b/frontend/src/composables/use-single-result-page-meta.ts @@ -15,7 +15,9 @@ export const useSingleResultPageMeta = ( const i18n = useI18n() const titles = () => { - if (!media.value) return { genericTitle: "", sensitiveTitle: "" } + if (!media.value) { + return { genericTitle: "", sensitiveTitle: "" } + } return { genericTitle: `${i18n.t( `mediaDetails.reuse.${media.value.frontendMediaType}` @@ -30,7 +32,9 @@ export const useSingleResultPageMeta = ( // Do not show sensitive content title in the social preview cards. const getMediaTitle = () => { - if (!media.value) return "" + if (!media.value) { + return "" + } return isSensitive.value ? titles().sensitiveTitle : media.value.title ?? titles().genericTitle diff --git a/frontend/src/locales/scripts/json-helpers.js b/frontend/src/locales/scripts/json-helpers.js index 8ebec335c1c..7f8ba2703ab 100644 --- a/frontend/src/locales/scripts/json-helpers.js +++ b/frontend/src/locales/scripts/json-helpers.js @@ -35,7 +35,9 @@ function readPaths(obj, path = "") { result.push(fullPath) continue } - if (value === obj) continue + if (value === obj) { + continue + } stack.push([fullPath, value]) } return [result, stack] diff --git a/frontend/src/locales/scripts/json-pot-helpers.js b/frontend/src/locales/scripts/json-pot-helpers.js index fc0f9517a9b..9ad28899de8 100644 --- a/frontend/src/locales/scripts/json-pot-helpers.js +++ b/frontend/src/locales/scripts/json-pot-helpers.js @@ -37,7 +37,9 @@ const checkStringForVars = (str) => * @return {string} the translation string with all placeholders marked */ const replaceVarsPlaceholders = (str) => { - if (!containsCurlyWord(str)) return str + if (!containsCurlyWord(str)) { + return str + } const variable = /\{(?[a-zA-Z-]*)}/g return str.replace(variable, `###$###`) @@ -93,15 +95,21 @@ const getComment = (entry) => { const comment = [] // comments given by the programmer, directed at the translator (#.) - if (entry.doc) comment.push(`#. ${entry.doc}`) + if (entry.doc) { + comment.push(`#. ${entry.doc}`) + } // comments given by the programmer, directed at the translator (#.) let vars = checkStringForVars(entry.value) - if (vars) comment.push(vars) + if (vars) { + comment.push(vars) + } // comments containing references to the program’s source code (#:) let refComments = getRefComments(entry.lineage) - if (refComments.length) comment.push(...refComments) + if (refComments.length) { + comment.push(...refComments) + } return comment.map((item) => `${item}`).join("\n") } @@ -122,7 +130,9 @@ const toPot = (entry) => { // string-string type mapping let poEntry = [] let comment = getComment(entry) - if (comment) poEntry.push(comment) + if (comment) { + poEntry.push(comment) + } poEntry.push(`msgctxt "${entry.lineage}"`) if (entry.value.includes("|") && /(count|time)/i.test(entry.value)) { const pluralizedValues = entry.value.split("|") diff --git a/frontend/src/locales/scripts/read-i18n.js b/frontend/src/locales/scripts/read-i18n.js index d688b4c5b80..f453deac27d 100644 --- a/frontend/src/locales/scripts/read-i18n.js +++ b/frontend/src/locales/scripts/read-i18n.js @@ -79,13 +79,18 @@ class Entry { */ toJSON() { // This is a string-string entry, will be handled by parent. - if (this.value) return {} + if (this.value) { + return {} + } /** @type {SimJson} */ const pojo = {} for (const child of this.children) { - if (child.value) pojo[child.key] = child.value - else pojo[child.key] = child.toJSON() + if (child.value) { + pojo[child.key] = child.value + } else { + pojo[child.key] = child.toJSON() + } } return pojo } @@ -99,12 +104,16 @@ class Entry { * @return {string} the text content of the key */ const parseKey = (keyNode) => { - if (keyNode === undefined) return "" + if (keyNode === undefined) { + return "" + } switch (keyNode.type) { - case "StringLiteral": + case "StringLiteral": { return keyNode.value - case "Identifier": + } + case "Identifier": { return keyNode.name + } } } @@ -117,13 +126,15 @@ const parseKey = (keyNode) => { */ const parseComment = (commentNode) => { switch (commentNode.type) { - case "CommentLine": + case "CommentLine": { return commentNode.value.trim() - case "CommentBlock": + } + case "CommentBlock": { return commentNode.value .replace(/\n|\*+/g, "") .replace(/\s+/, " ") .trim() + } } } @@ -136,14 +147,16 @@ const parseComment = (commentNode) => { */ const parseValue = (entry, valueNode) => { switch (valueNode.type) { - case "StringLiteral": + case "StringLiteral": { entry.value = valueNode.value break - case "ObjectExpression": + } + case "ObjectExpression": { valueNode.properties.map(parseObjProperty).forEach((child) => { entry.addChild(child) }) break + } } } diff --git a/frontend/src/locales/scripts/utils.js b/frontend/src/locales/scripts/utils.js index 94bbafdd63c..6fd237037fa 100644 --- a/frontend/src/locales/scripts/utils.js +++ b/frontend/src/locales/scripts/utils.js @@ -6,7 +6,9 @@ const os = require("os") */ function kebabToCamel(input) { const split = input.split("-") - if (split.length === 1) return input + if (split.length === 1) { + return input + } for (let i = 1; i < split.length; i++) { split[i] = split[i][0].toUpperCase() + split[i].slice(1) @@ -30,7 +32,9 @@ exports.setToValue = function setValue(obj, path, value) { var o = obj while (a.length - 1) { var n = a.shift() - if (!(n in o)) o[n] = {} + if (!(n in o)) { + o[n] = {} + } o = o[n] } o[a[0]] = value diff --git a/frontend/src/middleware/search.ts b/frontend/src/middleware/search.ts index 93a19c545b6..ba337051ee9 100644 --- a/frontend/src/middleware/search.ts +++ b/frontend/src/middleware/search.ts @@ -28,7 +28,9 @@ export const searchMiddleware: Middleware = async ({ * `prepare-search-query-params`. * Note that the search by creator is not displayed in the UI. */ - if (!q) return redirect("/") + if (!q) { + return redirect("/") + } const searchStore = useSearchStore($pinia) diff --git a/frontend/src/pages/image/_id/index.vue b/frontend/src/pages/image/_id/index.vue index 06efb567355..d8713cd8245 100644 --- a/frontend/src/pages/image/_id/index.vue +++ b/frontend/src/pages/image/_id/index.vue @@ -227,7 +227,9 @@ export default defineComponent({ * @param event - the image load event. */ const onImageLoaded = (event: Event) => { - if (!(event.target instanceof HTMLImageElement) || !image.value) return + if (!(event.target instanceof HTMLImageElement) || !image.value) { + return + } isLoadingThumbnail.value = false diff --git a/frontend/src/pages/search.vue b/frontend/src/pages/search.vue index 403e97bf7b1..b95cb25f87c 100644 --- a/frontend/src/pages/search.vue +++ b/frontend/src/pages/search.vue @@ -136,7 +136,9 @@ export default defineComponent({ mediaStore.fetchState.hasStarted && fetchingError.value !== null && !isRetriable(fetchingError.value) - if (shouldNotRefetch) return + if (shouldNotRefetch) { + return + } await mediaStore.fetchMedia(payload) diff --git a/frontend/src/stores/feature-flag.ts b/frontend/src/stores/feature-flag.ts index cf2fad22e5c..1e266c9db89 100644 --- a/frontend/src/stores/feature-flag.ts +++ b/frontend/src/stores/feature-flag.ts @@ -43,11 +43,14 @@ const FEATURE_FLAG = "feature_flag" */ export const getFlagStatus = (flag: FeatureFlag): FlagStatus => { const deployEnv = (process.env.DEPLOYMENT_ENV ?? LOCAL) as DeployEnv - if (typeof flag.status === "string") return flag.status - else { + if (typeof flag.status === "string") { + return flag.status + } else { const envIndex = DEPLOY_ENVS.indexOf(deployEnv) for (let i = envIndex; i < DEPLOY_ENVS.length; i += 1) { - if (DEPLOY_ENVS[i] in flag.status) return flag.status[DEPLOY_ENVS[i]] + if (DEPLOY_ENVS[i] in flag.status) { + return flag.status[DEPLOY_ENVS[i]] + } } } return DISABLED @@ -61,9 +64,12 @@ export const getFlagStatus = (flag: FeatureFlag): FlagStatus => { */ const getFeatureState = (flag: FeatureFlag): FeatureState => { const status = getFlagStatus(flag) - if (status === SWITCHABLE) + if (status === SWITCHABLE) { return flag.preferredState ?? flag.defaultState ?? OFF - if (status === ENABLED) return ON + } + if (status === ENABLED) { + return ON + } return OFF } @@ -81,8 +87,9 @@ export const useFeatureFlagStore = defineStore(FEATURE_FLAG, { featureState: (state: FeatureFlagState) => (name: FlagName): FeatureState => { - if (name in state.flags) return getFeatureState(state.flags[name]) - else { + if (name in state.flags) { + return getFeatureState(state.flags[name]) + } else { warn(`Invalid feature flag accessed: ${name}`) return ON } @@ -105,8 +112,9 @@ export const useFeatureFlagStore = defineStore(FEATURE_FLAG, { (dest: string): Record => { const featureMap: Record = {} Object.entries(state.flags).forEach(([name, flag]) => { - if (getFlagStatus(flag) === SWITCHABLE && flag.storage === dest) + if (getFlagStatus(flag) === SWITCHABLE && flag.storage === dest) { featureMap[name] = getFeatureState(flag) + } }) return featureMap }, @@ -199,8 +207,12 @@ export const useFeatureFlagStore = defineStore(FEATURE_FLAG, { flag.preferredState = targetState this.writeToCookie() this.writeToSession() - if (name === "analytics") this.syncAnalyticsWithLocalStorage() - } else warn(`Cannot set preferred state for non-switchable flag: ${name}`) + if (name === "analytics") { + this.syncAnalyticsWithLocalStorage() + } + } else { + warn(`Cannot set preferred state for non-switchable flag: ${name}`) + } }, /** * For Plausible to stop tracking `plausible_ignore` must be set in diff --git a/frontend/src/stores/media/index.ts b/frontend/src/stores/media/index.ts index 4e9ba59a2de..67278640a8e 100644 --- a/frontend/src/stores/media/index.ts +++ b/frontend/src/stores/media/index.ts @@ -94,7 +94,9 @@ export const useMediaStore = defineStore("media", { getItemById: (state) => { return (mediaType: SupportedMediaType, id: string): Media | undefined => { const itemFromSearchResults = state.results[mediaType].items[id] - if (itemFromSearchResults) return itemFromSearchResults + if (itemFromSearchResults) { + return itemFromSearchResults + } return useRelatedMediaStore().getItemById(id) } }, @@ -264,7 +266,9 @@ export const useMediaStore = defineStore("media", { ) // Prevent the bunching of audio results at the end. - if (nonImageIndex > newResults.length) break + if (nonImageIndex > newResults.length) { + break + } } } @@ -330,18 +334,22 @@ export const useMediaStore = defineStore("media", { error?: FetchingError ) { switch (action) { - case "reset": + case "reset": { this._resetFetchState() break - case "start": + } + case "start": { this._startFetching(mediaType) break - case "end": + } + case "end": { this._endFetching(mediaType, error) break - case "finish": + } + case "finish": { this._finishFetchingForQuery(mediaType) break + } } }, diff --git a/frontend/src/stores/media/single-result.ts b/frontend/src/stores/media/single-result.ts index c4971a90166..0a85aa5cc4d 100644 --- a/frontend/src/stores/media/single-result.ts +++ b/frontend/src/stores/media/single-result.ts @@ -108,7 +108,9 @@ export const useSingleResultStore = defineStore("single-result", { * itself later. */ setMediaById(type: SupportedMediaType, id: string) { - if (this.mediaId === id && isMediaDetail(this.mediaItem, type)) return + if (this.mediaId === id && isMediaDetail(this.mediaItem, type)) { + return + } const existingItem = useMediaStore().getItemById(type, id) if (existingItem) { this.setMediaItem(existingItem) diff --git a/frontend/src/stores/search.ts b/frontend/src/stores/search.ts index 301daeb82f4..6c15534fb10 100644 --- a/frontend/src/stores/search.ts +++ b/frontend/src/stores/search.ts @@ -291,7 +291,9 @@ export const useSearchStore = defineStore("search", { */ setSearchTerm(q: string | undefined | null) { const formattedTerm = q ? q.trim() : "" - if (this.searchTerm === formattedTerm) return + if (this.searchTerm === formattedTerm) { + return + } this.searchTerm = formattedTerm this.localSearchTerm = formattedTerm this.collectionParams = null @@ -516,7 +518,9 @@ export const useSearchStore = defineStore("search", { this.setSearchTerm(query.q) this.searchType = pathToSearchType(path) - if (!isSearchTypeSupported(this.searchType)) return + if (!isSearchTypeSupported(this.searchType)) { + return + } const newFilterData = queryToFilterData({ query, diff --git a/frontend/src/stores/ui.ts b/frontend/src/stores/ui.ts index 0a123c63a7f..4a87c675c90 100644 --- a/frontend/src/stores/ui.ts +++ b/frontend/src/stores/ui.ts @@ -153,8 +153,9 @@ export const useUiStore = defineStore("ui", { if ( cookies.uiBreakpoint && Object.keys(ALL_SCREEN_SIZES).includes(cookies.uiBreakpoint) - ) + ) { breakpoint = cookies.uiBreakpoint + } this.updateBreakpoint(breakpoint) if (typeof cookies.uiIsFilterDismissed === "boolean") { diff --git a/frontend/src/utils/attribution-html.ts b/frontend/src/utils/attribution-html.ts index 4c0222bd798..d40f72e4bd3 100644 --- a/frontend/src/utils/attribution-html.ts +++ b/frontend/src/utils/attribution-html.ts @@ -90,8 +90,11 @@ const fakeT = ( let text: string | undefined = undefined segments.forEach((segment) => { const piece = fraction[segment] - if (typeof piece === "string") text = piece - else fraction = piece + if (typeof piece === "string") { + text = piece + } else { + fraction = piece + } }) return text ? fmt(text, replacements) : "" } @@ -165,7 +168,9 @@ export const getAttribution = ( includeIcons: true, } ): string => { - if (!mediaItem) return "" + if (!mediaItem) { + return "" + } const isPd = isPublicDomain(mediaItem.license) @@ -178,10 +183,15 @@ export const getAttribution = ( /* Title */ let title = mediaItem.originalTitle || tFn("genericTitle") - if (!isPlaintext) title = escapeHtml(title) - if (!isPlaintext && mediaItem.foreign_landing_url) + if (!isPlaintext) { + title = escapeHtml(title) + } + if (!isPlaintext && mediaItem.foreign_landing_url) { title = extLink(mediaItem.foreign_landing_url, title) - if (mediaItem.originalTitle) title = tFn("actualTitle", { title }) + } + if (mediaItem.originalTitle) { + title = tFn("actualTitle", { title }) + } /* License */ @@ -195,11 +205,14 @@ export const getAttribution = ( const elements = getElements(mediaItem.license) const icons = elements.map((element) => licenseElementImg(element)) // Icons are only rendered if present for every element - if (!icons.includes("")) licenseIcons = icons.join("") + if (!icons.includes("")) { + licenseIcons = icons.join("") + } } let license = `${fullLicenseName} ${licenseIcons}`.trim() - if (!isPlaintext && mediaItem.license_url) + if (!isPlaintext && mediaItem.license_url) { license = extLink(`${mediaItem.license_url}?ref=openverse`, license) + } /* Attribution */ @@ -220,9 +233,12 @@ export const getAttribution = ( if (mediaItem.creator) { let creator = mediaItem.creator - if (!isPlaintext) creator = escapeHtml(creator) - if (!isPlaintext && mediaItem.creator_url) + if (!isPlaintext) { + creator = escapeHtml(creator) + } + if (!isPlaintext && mediaItem.creator_url) { creator = extLink(mediaItem.creator_url, creator) + } attributionParts.creator = tFn("creatorText", { creatorName: creator, }) diff --git a/frontend/src/utils/case.ts b/frontend/src/utils/case.ts index 08420232418..baaaf37a9db 100644 --- a/frontend/src/utils/case.ts +++ b/frontend/src/utils/case.ts @@ -27,9 +27,15 @@ function split(input: string) { let end = result.length // Trim the delimiter from around the output string. - while (result.charAt(start) === "\0") start++ - if (start === end) return [] - while (result.charAt(end - 1) === "\0") end-- + while (result.charAt(start) === "\0") { + start++ + } + if (start === end) { + return [] + } + while (result.charAt(end - 1) === "\0") { + end-- + } return result.slice(start, end).split(/\0/g) } @@ -57,7 +63,9 @@ export function camelCase(input: string) { const transform = pascalCaseTransformFactory() return split(input) .map((word, index) => { - if (index === 0) return word.toLowerCase() + if (index === 0) { + return word.toLowerCase() + } return transform(word, index) }) .join("") diff --git a/frontend/src/utils/decode-data.ts b/frontend/src/utils/decode-data.ts index 3bb27f71a5c..f6d48cf8af8 100644 --- a/frontend/src/utils/decode-data.ts +++ b/frontend/src/utils/decode-data.ts @@ -6,7 +6,9 @@ * @param data - the string to unescape so that it can be rendered */ export const decodeData = (data = ""): string => { - if (!data) return "" + if (!data) { + return "" + } try { const regexes = [ diff --git a/frontend/src/utils/decode-media-data.ts b/frontend/src/utils/decode-media-data.ts index 6dec35088e4..a1ebf4e663d 100644 --- a/frontend/src/utils/decode-media-data.ts +++ b/frontend/src/utils/decode-media-data.ts @@ -26,7 +26,9 @@ const isFiletypeMatching = (extension: string, filetype?: string) => { if (filetype === extension) { return true } - if (!filetype) return false + if (!filetype) { + return false + } return matchers.some((matcher) => Boolean(filetype.match(matcher) && extension.match(matcher)) ) diff --git a/frontend/src/utils/dom.ts b/frontend/src/utils/dom.ts index 85f80c757c5..ab71ca00441 100644 --- a/frontend/src/utils/dom.ts +++ b/frontend/src/utils/dom.ts @@ -4,8 +4,12 @@ import type { Ref, ComponentPublicInstance } from "vue" export function getDomElement( ref?: Ref ): T | null { - if (ref == null) return null - if (ref.value == null) return null + if (ref == null) { + return null + } + if (ref.value == null) { + return null + } return "$el" in ref.value ? (ref.value.$el as T | null) : ref.value } diff --git a/frontend/src/utils/errors.ts b/frontend/src/utils/errors.ts index 64e3aa5a308..0d4c3fe5f9e 100644 --- a/frontend/src/utils/errors.ts +++ b/frontend/src/utils/errors.ts @@ -65,7 +65,9 @@ const isNonRetryableErrorStatusCode = (statusCode: number | undefined) => { const isValidErrorCode = ( code: string | undefined | null ): code is ErrorCode => { - if (!code) return false + if (!code) { + return false + } return (errorCodes as readonly string[]).includes(code) } diff --git a/frontend/src/utils/focus-management.ts b/frontend/src/utils/focus-management.ts index d5d418d16e0..b9db344ea18 100644 --- a/frontend/src/utils/focus-management.ts +++ b/frontend/src/utils/focus-management.ts @@ -6,11 +6,17 @@ import type { Ref } from "vue" function getOwnerDocument>( element: T | null | undefined ) { - if (typeof window === "undefined") return null - if (element instanceof Node) return element.ownerDocument + if (typeof window === "undefined") { + return null + } + if (element instanceof Node) { + return element.ownerDocument + } if (element && Object.prototype.hasOwnProperty.call(element, "value")) { const domElement = getDomElement(element) - if (domElement) return domElement.ownerDocument + if (domElement) { + return domElement.ownerDocument + } } return document @@ -69,12 +75,16 @@ export const Direction = Object.freeze({ Next: 1, Previous: -1 }) export function getFocusableElements( container: HTMLElement | null = document.body ) { - if (container == null) return [] + if (container == null) { + return [] + } return Array.from(container.querySelectorAll(focusableSelector)) } export function isFocusableElement(element: HTMLElement) { - if (element === getOwnerDocument(element)?.body) return false + if (element === getOwnerDocument(element)?.body) { + return false + } return element.matches(focusableSelector) } @@ -99,12 +109,18 @@ export function sortByDomNode( const a = resolveKey(aItem) const z = resolveKey(zItem) - if (a === null || z === null) return 0 + if (a === null || z === null) { + return 0 + } const position = a.compareDocumentPosition(z) - if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1 - if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1 + if (position & Node.DOCUMENT_POSITION_FOLLOWING) { + return -1 + } + if (position & Node.DOCUMENT_POSITION_PRECEDING) { + return 1 + } return 0 }) } @@ -123,8 +139,12 @@ export function focusIn(container: HTMLElement | HTMLElement[], focus: number) { const active = ownerDocument.activeElement as HTMLElement const direction = (() => { - if (focus & (Focus.First | Focus.Next)) return Direction.Next - if (focus & (Focus.Previous | Focus.Last)) return Direction.Previous + if (focus & (Focus.First | Focus.Next)) { + return Direction.Next + } + if (focus & (Focus.Previous | Focus.Last)) { + return Direction.Previous + } throw new Error( "Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last" @@ -132,10 +152,18 @@ export function focusIn(container: HTMLElement | HTMLElement[], focus: number) { })() const startIndex = (() => { - if (focus & Focus.First) return 0 - if (focus & Focus.Previous) return Math.max(0, elements.indexOf(active)) - 1 - if (focus & Focus.Next) return Math.max(0, elements.indexOf(active)) + 1 - if (focus & Focus.Last) return elements.length - 1 + if (focus & Focus.First) { + return 0 + } + if (focus & Focus.Previous) { + return Math.max(0, elements.indexOf(active)) - 1 + } + if (focus & Focus.Next) { + return Math.max(0, elements.indexOf(active)) + 1 + } + if (focus & Focus.Last) { + return elements.length - 1 + } throw new Error( "Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last" @@ -147,15 +175,21 @@ export function focusIn(container: HTMLElement | HTMLElement[], focus: number) { let next = undefined do { // Guard against infinite loops - if (offset >= total || offset + total <= 0) return FocusResult.Error + if (offset >= total || offset + total <= 0) { + return FocusResult.Error + } let nextIdx = startIndex + offset if (focus & Focus.WrapAround) { nextIdx = (nextIdx + total) % total } else { - if (nextIdx < 0) return FocusResult.Underflow - if (nextIdx >= total) return FocusResult.Overflow + if (nextIdx < 0) { + return FocusResult.Underflow + } + if (nextIdx >= total) { + return FocusResult.Overflow + } } next = elements[nextIdx] diff --git a/frontend/src/utils/metadata.ts b/frontend/src/utils/metadata.ts index 70466eab139..acc9e869f48 100644 --- a/frontend/src/utils/metadata.ts +++ b/frontend/src/utils/metadata.ts @@ -20,8 +20,9 @@ const getImageType = ( } const getAudioType = (audio: AudioDetail, i18n: NuxtI18nInstance) => { - if (!audio.alt_files) + if (!audio.alt_files) { return audio.filetype ?? i18n.t("mediaDetails.information.unknown") + } const altFormats = audio.alt_files .map((altFile) => altFile.filetype) .filter((filetype) => filetype !== audio.filetype) diff --git a/frontend/src/utils/reakit-utils/dom.ts b/frontend/src/utils/reakit-utils/dom.ts index 42adda2143c..790e3b19517 100644 --- a/frontend/src/utils/reakit-utils/dom.ts +++ b/frontend/src/utils/reakit-utils/dom.ts @@ -67,6 +67,8 @@ export function isVisible(element: Element) { export function isInDocument(target: Element) { const document = getDocument(target) - if (target.tagName === "HTML") return true + if (target.tagName === "HTML") { + return true + } return contains(document.body, target) } diff --git a/frontend/src/utils/reakit-utils/focus.ts b/frontend/src/utils/reakit-utils/focus.ts index c5a104f7a5c..2407d619fd7 100644 --- a/frontend/src/utils/reakit-utils/focus.ts +++ b/frontend/src/utils/reakit-utils/focus.ts @@ -124,10 +124,16 @@ export function getFirstTabbableIn( */ export function hasFocus(element: Element) { const activeElement = getActiveElement(element) - if (!activeElement) return false - if (activeElement === element) return true + if (!activeElement) { + return false + } + if (activeElement === element) { + return true + } const activeDescendant = activeElement.getAttribute("aria-activedescendant") - if (!activeDescendant) return false + if (!activeDescendant) { + return false + } return activeDescendant === element.id } @@ -139,12 +145,22 @@ export function hasFocus(element: Element) { */ export function hasFocusWithin(element: Node | Element) { const activeElement = getActiveElement(element) - if (!activeElement) return false - if (contains(element, activeElement)) return true + if (!activeElement) { + return false + } + if (contains(element, activeElement)) { + return true + } const activeDescendant = activeElement.getAttribute("aria-activedescendant") - if (!activeDescendant) return false - if (!("id" in element)) return false - if (activeDescendant === element.id) return true + if (!activeDescendant) { + return false + } + if (!("id" in element)) { + return false + } + if (activeDescendant === element.id) { + return true + } return !!element.querySelector(`#${CSS.escape(activeDescendant)}`) } @@ -173,11 +189,17 @@ export function ensureFocus( const element = el as HTMLElement // TODO: Try to use queueMicrotask before requestAnimationFrame and dispatch // focus events if the element is not focusable? - if (isActive(element)) return -1 + if (isActive(element)) { + return -1 + } element.focus({ preventScroll }) - if (isActive(element)) return -1 + if (isActive(element)) { + return -1 + } return requestAnimationFrame(() => { - if (isActive(element)) return + if (isActive(element)) { + return + } element.focus({ preventScroll }) }) } diff --git a/frontend/src/utils/search-query-transform.ts b/frontend/src/utils/search-query-transform.ts index fe85258433e..58fdcf7b88a 100644 --- a/frontend/src/utils/search-query-transform.ts +++ b/frontend/src/utils/search-query-transform.ts @@ -214,7 +214,9 @@ export const areQueriesEqual = ( ) as (keyof PaginatedSearchQuery)[] const oldQueryKeys = queryKeys(oldQuery) const newQueryKeys = queryKeys(newQuery) - if (oldQueryKeys.length !== newQueryKeys.length) return false + if (oldQueryKeys.length !== newQueryKeys.length) { + return false + } for (const key of oldQueryKeys) { if (oldQuery[key] !== newQuery[key]) { diff --git a/frontend/src/utils/string-to-boolean.ts b/frontend/src/utils/string-to-boolean.ts index d6f7e61a7ca..76bdd0ffa31 100644 --- a/frontend/src/utils/string-to-boolean.ts +++ b/frontend/src/utils/string-to-boolean.ts @@ -12,21 +12,28 @@ export const stringToBoolean = (value: string | boolean): boolean => { // In case the string is already a boolean, return as-is. // If `.env` vars are auto-cast to booleans, this will catch that. - if (typeof value === "boolean") return value + if (typeof value === "boolean") { + return value + } - if (!value) return false + if (!value) { + return false + } value = value.toLowerCase().trim() switch (value) { case "true": case "yes": - case "1": + case "1": { return true + } case "false": case "no": - case "0": + case "0": { return false - default: + } + default: { return Boolean(value) + } } } diff --git a/frontend/src/utils/translation-banner.ts b/frontend/src/utils/translation-banner.ts index ae6272ac0fc..b297ce9696b 100644 --- a/frontend/src/utils/translation-banner.ts +++ b/frontend/src/utils/translation-banner.ts @@ -5,7 +5,9 @@ const BASE_URL = "https://translate.wordpress.org/projects/meta/openverse/" const MINIMUM_TRANSLATION_PERCENTAGE = 90 export const needsTranslationBanner = (locale: LocaleObject) => { - if (!locale || locale.code === "en") return false + if (!locale || locale.code === "en") { + return false + } return (locale.translated ?? 100) <= MINIMUM_TRANSLATION_PERCENTAGE } diff --git a/frontend/test/playwright/e2e/recent-searches.spec.ts b/frontend/test/playwright/e2e/recent-searches.spec.ts index 316f3fb1131..e205f501335 100644 --- a/frontend/test/playwright/e2e/recent-searches.spec.ts +++ b/frontend/test/playwright/e2e/recent-searches.spec.ts @@ -12,7 +12,9 @@ test.beforeEach(async ({ page }) => { const executeSearches = async (page: Page) => { const searches = ["honey", "galah"] // in that order - for (const term of searches) await searchFromHeader(page, term) + for (const term of searches) { + await searchFromHeader(page, term) + } return searches } diff --git a/frontend/test/playwright/utils/breakpoints.ts b/frontend/test/playwright/utils/breakpoints.ts index df9b22d11c5..fa3c6e41ee3 100644 --- a/frontend/test/playwright/utils/breakpoints.ts +++ b/frontend/test/playwright/utils/breakpoints.ts @@ -137,8 +137,9 @@ const describeEachBreakpoint = breakpoints.includes( bp.replace("describe", "").toLowerCase() as Breakpoint ) - ) + ) { describe(blockOrOptions, block) + } }) } diff --git a/frontend/test/playwright/utils/navigation.ts b/frontend/test/playwright/utils/navigation.ts index f430841ee7c..3c63402a113 100644 --- a/frontend/test/playwright/utils/navigation.ts +++ b/frontend/test/playwright/utils/navigation.ts @@ -141,7 +141,9 @@ export const setContentSwitcherState = async ( const shouldBePressed = state === "open" if (isDesktop) { - if (isPressed === shouldBePressed) return null + if (isPressed === shouldBePressed) { + return null + } return await buttonLocator.click() } @@ -175,7 +177,9 @@ export const searchTypes = { export const isPageDesktop = (page: Page) => { const pageWidth = page.viewportSize()?.width - if (!pageWidth) return false + if (!pageWidth) { + return false + } const desktopMinWidth = 1024 return pageWidth >= desktopMinWidth } diff --git a/frontend/test/proxy.js b/frontend/test/proxy.js index e0dfdd3ce1e..9beb4897434 100644 --- a/frontend/test/proxy.js +++ b/frontend/test/proxy.js @@ -135,8 +135,9 @@ const getBodyUtil = (tape) => * @type {TalkbackOptions['tapeDecorator']} */ const tapeDecorator = (tape) => { - if (!tape.res || tape.req.url.endsWith("/thumb/") || tape.res.status >= 399) + if (!tape.res || tape.req.url.endsWith("/thumb/") || tape.res.status >= 399) { return tape + } const bodyUtil = getBodyUtil(tape) const responseBody = bodyUtil.read(tape.res.body).toString() diff --git a/frontend/test/unit/specs/stores/feature-flag-store.spec.js b/frontend/test/unit/specs/stores/feature-flag-store.spec.js index 8475b1acd55..bffb8743951 100644 --- a/frontend/test/unit/specs/stores/feature-flag-store.spec.js +++ b/frontend/test/unit/specs/stores/feature-flag-store.spec.js @@ -82,10 +82,11 @@ describe("Feature flag store", () => { ({ doCookieInit, featureState }) => { const flagName = "feat_switchable_optout" const featureFlagStore = useFeatureFlagStore() - if (doCookieInit) + if (doCookieInit) { featureFlagStore.initFromCookies({ feat_switchable_optout: OFF, }) + } expect(featureFlagStore.featureState(flagName)).toEqual(featureState) expect(featureFlagStore.isOn(flagName)).toEqual(featureState === "on") } diff --git a/frontend/test/unit/test-utils/api-service-mock.ts b/frontend/test/unit/test-utils/api-service-mock.ts index 3f4d548efbf..bd1d4fb3956 100644 --- a/frontend/test/unit/test-utils/api-service-mock.ts +++ b/frontend/test/unit/test-utils/api-service-mock.ts @@ -67,7 +67,9 @@ export const mockCreateApiService = ( }) createApiService.mockImplementation((options) => { // Only ever generate the mock once - if (apiService) return apiService + if (apiService) { + return apiService + } apiService = originalApiService.createApiService( options diff --git a/packages/eslint-plugin/src/configs/index.ts b/packages/eslint-plugin/src/configs/index.ts index 13363b2e92a..16c8458d750 100644 --- a/packages/eslint-plugin/src/configs/index.ts +++ b/packages/eslint-plugin/src/configs/index.ts @@ -33,6 +33,8 @@ export const project: TSESLint.Linter.Config = { semi: ["error", "never"], "no-console": "off", "unicorn/filename-case": ["error", { case: "kebabCase" }], + "unicorn/switch-case-braces": ["error"], + curly: ["error", "all"], }, overrides: [ { diff --git a/packages/eslint-plugin/src/rules/analytics-configuration.ts b/packages/eslint-plugin/src/rules/analytics-configuration.ts index 0df9629aff0..d15d93c3e67 100644 --- a/packages/eslint-plugin/src/rules/analytics-configuration.ts +++ b/packages/eslint-plugin/src/rules/analytics-configuration.ts @@ -164,7 +164,9 @@ export const analyticsConfiguration = OpenverseRule({ }) } - if (!customEventNode.typeAnnotation) return + if (!customEventNode.typeAnnotation) { + return + } if (isTypeAnnotationEmpty(customEventNode)) { context.report({ @@ -202,15 +204,20 @@ export const analyticsConfiguration = OpenverseRule({ const isAnalyticsFile = context .getFilename() .endsWith("types/analytics.ts") - if (!isAnalyticsFile) return + if (!isAnalyticsFile) { + return + } if ( node.parent?.type !== "TSTypeAliasDeclaration" || node.parent?.typeAnnotation.type !== "TSTypeLiteral" - ) + ) { return + } node.parent.typeAnnotation.members.forEach((m) => { - if (m.type === "TSPropertySignature") validateCustomEvent(m) + if (m.type === "TSPropertySignature") { + validateCustomEvent(m) + } }) }, }