Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce braces for if-else and switch-case #3474

Merged
merged 9 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions automations/js/src/project_thread_updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/VAudioTrack/VAudioControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
55 changes: 39 additions & 16 deletions frontend/src/components/VAudioTrack/VAudioTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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]) =>
/**
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
Expand Down Expand Up @@ -351,26 +360,32 @@ 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
if (playPromise !== undefined) {
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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/components/VAudioTrack/VGlobalAudioTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export default defineComponent({
const status = ref<AudioStatus>("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
})

Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/components/VAudioTrack/VWaveform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/components/VCollectionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,40 @@ 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 })
}

watch(
activeAudio.obj,
(audio, _, onInvalidate) => {
if (!audio) return
if (!audio) {
return
}
audio.addEventListener("error", handleError)

onInvalidate(() => {
Expand Down
Loading
Loading