Skip to content

Commit bc856ac

Browse files
committed
chore: fix all sonarcloud's code smells (#2072)
1 parent 1cec325 commit bc856ac

33 files changed

+90
-103
lines changed

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"dbaeumer.vscode-eslint",
1111
"lokalise.i18n-ally",
1212
"ryanluker.vscode-coverage-gutters",
13-
"yoavbls.pretty-ts-errors"
13+
"yoavbls.pretty-ts-errors",
14+
"SonarSource.sonarlint-vscode"
1415
],
1516
"unwantedRecommendations": [
1617
"octref.vetur",

.vscode/settings.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@
3838
"vue": "html"
3939
},
4040
"vue.autoInsert.dotValue": true,
41-
"vue.server.fullCompletionList": true
41+
"vue.server.fullCompletionList": true,
42+
"sonarlint.output.showAnalyzerLogs": true,
43+
"sonarlint.output.showVerboseLogs": true,
44+
"sonarlint.connectedMode.project": {
45+
"connectionId": "jellyfin-vue",
46+
"projectKey": "jellyfin_jellyfin-vue"
47+
}
4248
}

frontend/src/components/Buttons/MarkPlayedButton.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ async function togglePlayed(): Promise<void> {
3737
if (isPlayed.value) {
3838
isPlayed.value = false;
3939
await remote.sdk.newUserApi(getPlaystateApi).markUnplayedItem({
40-
userId: remote.auth.currentUserId || '',
40+
userId: remote.auth.currentUserId ?? '',
4141
itemId: props.item.Id
4242
});
4343
} else {
4444
isPlayed.value = true;
4545
await remote.sdk.newUserApi(getPlaystateApi).markPlayedItem({
46-
userId: remote.auth.currentUserId || '',
46+
userId: remote.auth.currentUserId ?? '',
4747
itemId: props.item.Id
4848
});
4949
}

frontend/src/components/Buttons/SubtitleSelectionButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const tracks = computed(() => {
5757
srcIndex: -1,
5858
type: SubtitleDeliveryMethod.External
5959
},
60-
...(subs || [])
60+
...(subs ?? [])
6161
];
6262
});
6363
</script>

frontend/src/components/Item/MediaDetail/MediaDetailContent.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const properties = computed(() => {
3636
props.stream.Width && props.stream.Height
3737
? `${props.stream.Width}x${props.stream.Height}`
3838
: undefined;
39-
const framerate = props.stream.AverageFrameRate || props.stream.RealFrameRate;
39+
const framerate = props.stream.AverageFrameRate ?? props.stream.RealFrameRate;
4040
const language = props.stream.Language
4141
? getLocaleName(props.stream.Language, locale.value)
4242
: undefined;

frontend/src/components/Item/Metadata/MetadataEditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ async function getGenres(parentId: string): Promise<void> {
340340
* Save metadata for the current item
341341
*/
342342
async function saveMetadata(): Promise<void> {
343-
if (!metadata.value || !metadata.value.Id) {
343+
if (!metadata.value?.Id) {
344344
return;
345345
}
346346

frontend/src/components/Item/Metadata/RefreshMetadataDialog.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async function refreshMetadata(): Promise<void> {
140140
taskManager.startTask({
141141
type: TaskType.LibraryRefresh,
142142
id: props.item.Id || '',
143-
data: props.item.Name || 'ID ' + props.item.Id,
143+
data: props.item.Name ?? `ID ${props.item.Id}`,
144144
progress: 0
145145
});
146146

frontend/src/components/Layout/AppBar/SearchField.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const router = useRouter();
2020
2121
const searchQuery = computed({
2222
get(): string {
23-
return route.query.q?.toString() || '';
23+
return route.query.q?.toString() ?? '';
2424
},
2525
async set(value) {
2626
await router.replace({

frontend/src/components/Layout/Carousel/Carousel.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function setControlledSwiper (instance: SwiperType): void {
9696
* See https://github.com/nolimits4web/swiper/issues/2629 and https://github.com/surmon-china/vue-awesome-swiper/issues/483
9797
*/
9898
function onSlideChange(): void {
99-
currentIndex.value = swiperInstance.value?.realIndex || 0;
99+
currentIndex.value = swiperInstance.value?.realIndex ?? 0;
100100
101101
if (swiperInstance.value?.isBeginning || swiperInstance.value?.isEnd) {
102102
swiperInstance.value?.updateSlides();

frontend/src/components/Layout/Carousel/Item/ItemsCarousel.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ watch(
134134
135135
const itemData = (
136136
await remote.sdk.newUserApi(getUserLibraryApi).getItem({
137-
userId: remote.auth.currentUserId || '',
137+
userId: remote.auth.currentUserId ?? '',
138138
itemId: id
139139
})
140140
).data;

frontend/src/components/Layout/Navigation/NavigationDrawer.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ const { t } = useI18n();
5555
const drawer = inject<Ref<boolean>>('NavigationDrawer');
5656
5757
const transparentLayout = computed(() => {
58-
return route.meta.transparentLayout || false;
58+
return route.meta.transparentLayout ?? false;
5959
});
6060
6161
const drawerItems = computed(() => {
6262
return userLibraries.libraries.map((view: BaseItemDto) => {
6363
if (view.Id) {
6464
return {
6565
icon: getLibraryIcon(view.CollectionType),
66-
title: view.Name || '',
66+
title: view.Name ?? '',
6767
to: `/library/${view.Id}`
6868
};
6969
}

frontend/src/components/Layout/VirtualGrid/VirtualGrid.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const contentSize = computed(() => {
136136
});
137137
const rootStyles = computed<StyleValue>(() =>
138138
Object.fromEntries([
139-
...Object.entries(contentSize.value || {}).map(([property, value]) => [
139+
...Object.entries(contentSize.value ?? {}).map(([property, value]) => [
140140
property,
141141
`${value}px`
142142
]),

frontend/src/components/Layout/VirtualGrid/pipeline.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ export function getScrollParents(
9393
/**
9494
* Parent.assignedSlot.parentElement find the correct parent if the grid is inside a native web component
9595
*/
96-
parent = parent.assignedSlot?.parentElement || parent.parentElement;
96+
parent = parent.assignedSlot?.parentElement ?? parent.parentElement;
9797
}
9898

99-
const fallback = document.scrollingElement || document.documentElement;
99+
const fallback = document.scrollingElement ?? document.documentElement;
100100

101101
return {
102-
vertical: vertical || fallback,
103-
horizontal: horizontal || fallback
102+
vertical: vertical ?? fallback,
103+
horizontal: horizontal ?? fallback
104104
};
105105
}
106106

frontend/src/components/Playback/DraggableQueue.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ onMounted(() => {
6969
if (typeof oldIndex === 'number') {
7070
const item = playbackManager.queue[oldIndex];
7171
72-
if (item && item.Id && typeof e.newIndex === 'number') {
72+
if (item?.Id && typeof e.newIndex === 'number') {
7373
playbackManager.changeItemPosition(item.Id, e.newIndex);
7474
}
7575
}

frontend/src/components/Playback/PlayerElement.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:is="mediaElementType"
88
v-show="mediaElementType === 'video' && teleportTarget"
99
ref="mediaElementRef"
10-
:poster="posterUrl"
10+
:poster="String(posterUrl)"
1111
autoplay
1212
crossorigin="anonymous"
1313
playsinline
@@ -99,13 +99,13 @@ const teleportTarget = computed<
9999
}
100100
});
101101
102-
const posterUrl = computed<string>(() =>
102+
const posterUrl = computed(() =>
103103
!isNil(playbackManager.currentItem) &&
104104
playbackManager.currentlyPlayingMediaType === 'Video'
105105
? getImageInfo(playbackManager.currentItem, {
106106
preferBackdrop: true
107-
}).url || ''
108-
: ''
107+
}).url
108+
: undefined
109109
);
110110
111111
/**

frontend/src/components/Playback/TrackList.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const tracks = ref<BaseItemDto[] | null | undefined>();
141141
async function fetch(): Promise<void> {
142142
tracks.value = (
143143
await remote.sdk.newUserApi(getItemsApi).getItems({
144-
userId: remote.auth.currentUserId || '',
144+
userId: remote.auth.currentUserId ?? '',
145145
parentId: props.item.Id,
146146
sortBy: ['SortName'],
147147
sortOrder: [SortOrder.Ascending],

frontend/src/pages/genre/_itemId/index.vue

+5-9
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,11 @@ const genres = ref<BaseItemDto[]>([]);
8585
8686
onMounted(async () => {
8787
const { itemId } = route.params as { itemId: string };
88-
const typesQuery = route.query.type;
89-
90-
const includeItemTypes = (
91-
typesQuery == undefined
92-
? []
93-
: (typeof typesQuery === 'string'
94-
? [typesQuery]
95-
: typesQuery)
96-
) as BaseItemKind[];
88+
const typesQuery = route.query.type as BaseItemKind ?? [];
89+
90+
const includeItemTypes: BaseItemKind[] = typeof typesQuery === 'string'
91+
? [typesQuery]
92+
: typesQuery;
9793
9894
loading.value = true;
9995

frontend/src/pages/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const homeSections = computed<HomeSection[]>(() => {
9696
latestMediaSections.push({
9797
name: 'latestLibrary',
9898
libraryName: userView.Name,
99-
libraryId: userView.Id || '',
99+
libraryId: userView.Id ?? '',
100100
shape: getShapeFromCollectionType(userView.CollectionType),
101101
type: 'latestmedia'
102102
});

frontend/src/pages/playback/music/index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ watch(
166166
() => {
167167
if (swiperInstance.value && !isNil(playbackManager.currentItemIndex)) {
168168
swiperInstance.value.slideTo(playbackManager.currentItemIndex);
169-
route.meta.title = playbackManager.currentItem?.Name || '';
169+
route.meta.title = playbackManager.currentItem?.Name ?? '';
170170
}
171171
},
172172
{ immediate: true }
@@ -183,7 +183,7 @@ watch(isVisualizing, async () => {
183183
* Handle slide changes
184184
*/
185185
function onSlideChange(): void {
186-
const index = swiperInstance.value?.activeIndex || 0;
186+
const index = swiperInstance.value?.activeIndex ?? 0;
187187
188188
playbackManager.currentItemIndex = index;
189189
}

frontend/src/pages/search.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const memo = reactive(
9696
])
9797
);
9898
99-
const searchQuery = computed(() => route.query?.q?.toString() || '');
99+
const searchQuery = computed(() => route.query?.q?.toString() ?? '');
100100
const items = computed(() => memo.get(searchQuery.value)?.items ?? []);
101101
const people = computed(() => memo.get(searchQuery.value)?.people ?? []);
102102
const movies = computed(() =>
@@ -123,7 +123,7 @@ const performDebouncedSearch = useDebounceFn(async (searchTerm: string) => {
123123
const itemSearch =
124124
(
125125
await remote.sdk.newUserApi(getItemsApi).getItemsByUserId({
126-
userId: remote.auth.currentUserId || '',
126+
userId: remote.auth.currentUserId ?? '',
127127
searchTerm,
128128
includeItemTypes: [
129129
BaseItemKind.Movie,

frontend/src/pages/server/login.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const route = useRoute();
108108
const router = useRouter();
109109
const remote = useRemote();
110110
const api = remote.sdk.oneTimeSetup(
111-
remote.auth.currentServer?.PublicAddress || ''
111+
remote.auth.currentServer?.PublicAddress ?? ''
112112
);
113113
114114
route.meta.title = t('login.login');

frontend/src/pages/wizard.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const heading = computed(() => {
125125
async function completeWizard(): Promise<void> {
126126
try {
127127
const api = remote.sdk.oneTimeSetup(
128-
remote.auth.currentServer?.PublicAddress || ''
128+
remote.auth.currentServer?.PublicAddress ?? ''
129129
);
130130
131131
await getStartupApi(api).completeWizard();

frontend/src/store/clientSettings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface ClientSettingsState {
2525
*/
2626
const navigatorLanguage = useNavigatorLanguage();
2727
const BROWSER_LANGUAGE = computed<string>(() => {
28-
const rawString = navigatorLanguage.language.value || '';
28+
const rawString = navigatorLanguage.language.value ?? '';
2929
/**
3030
* Removes the culture info from the language string, so 'es-ES' is recognised as 'es'
3131
*/

frontend/src/store/playbackManager.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class PlaybackManagerStore {
303303
srcLang: sub.Language ?? undefined,
304304
type: sub.DeliveryMethod ?? SubtitleDeliveryMethod.Drop,
305305
srcIndex: sub.srcIndex,
306-
codec: sub.Codec || undefined
306+
codec: sub.Codec
307307
}));
308308
}
309309
}
@@ -466,7 +466,7 @@ class PlaybackManagerStore {
466466
public set currentVolume(newVolume: number) {
467467
newVolume = newVolume > 100 ? 100 : newVolume;
468468
newVolume = newVolume < 0 ? 0 : newVolume;
469-
this.isMuted = newVolume === 0 ? true : false;
469+
this.isMuted = newVolume === 0;
470470

471471
if (this._state.isRemotePlayer) {
472472
this._state.remoteCurrentVolume = newVolume;
@@ -747,9 +747,9 @@ class PlaybackManagerStore {
747747
};
748748

749749
public stop = (): void => {
750-
const sessionId = String(this._state.playSessionId || '');
750+
const sessionId = String(this._state.playSessionId ?? '');
751751
const time = Number(this.currentTime);
752-
const itemId = String(this.currentItem?.Id || '');
752+
const itemId = String(this.currentItem?.Id ?? '');
753753
const volume = Number(this.currentVolume);
754754

755755
Object.assign(this._state, this._defaultState);
@@ -860,7 +860,7 @@ class PlaybackManagerStore {
860860
if (item) {
861861
return (
862862
await remote.sdk.newUserApi(getMediaInfoApi).getPostedPlaybackInfo({
863-
itemId: item?.Id || '',
863+
itemId: item?.Id ?? '',
864864
userId: remote.auth.currentUserId,
865865
autoOpenLiveStream: true,
866866
playbackInfoDto: { DeviceProfile: playbackProfile },
@@ -965,8 +965,8 @@ class PlaybackManagerStore {
965965
mediaSourceId: mediaSource.Id,
966966
deviceId: remote.sdk.deviceInfo.id,
967967
api_key: remote.auth.currentUserToken,
968-
Tag: mediaSource.ETag || '',
969-
LiveStreamId: mediaSource.LiveStreamId || ''
968+
Tag: mediaSource.ETag ?? '',
969+
LiveStreamId: mediaSource.LiveStreamId ?? ''
970970
};
971971

972972
const parameters = new URLSearchParams(directOptions).toString();
@@ -1063,42 +1063,42 @@ class PlaybackManagerStore {
10631063
src:
10641064
getImageInfo(this.currentItem, {
10651065
width: 96
1066-
}).url || '',
1066+
}).url ?? '',
10671067
sizes: '96x96'
10681068
},
10691069
{
10701070
src:
10711071
getImageInfo(this.currentItem, {
10721072
width: 128
1073-
}).url || '',
1073+
}).url ?? '',
10741074
sizes: '128x128'
10751075
},
10761076
{
10771077
src:
10781078
getImageInfo(this.currentItem, {
10791079
width: 192
1080-
}).url || '',
1080+
}).url ?? '',
10811081
sizes: '192x192'
10821082
},
10831083
{
10841084
src:
10851085
getImageInfo(this.currentItem, {
10861086
width: 256
1087-
}).url || '',
1087+
}).url ?? '',
10881088
sizes: '256x256'
10891089
},
10901090
{
10911091
src:
10921092
getImageInfo(this.currentItem, {
10931093
width: 384
1094-
}).url || '',
1094+
}).url ?? '',
10951095
sizes: '384x384'
10961096
},
10971097
{
10981098
src:
10991099
getImageInfo(this.currentItem, {
11001100
width: 512
1101-
}).url || '',
1101+
}).url ?? '',
11021102
sizes: '512x512'
11031103
}
11041104
]

frontend/src/store/playerElement.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class PlayerElementStore {
192192
* If VTT found, applying it
193193
*/
194194
mediaElementRef.value.textTracks[vttIdx].mode = 'showing';
195-
} else if (ass !== undefined && ass.src) {
195+
} else if (ass?.src) {
196196
/**
197197
* If SSA, using Subtitle Opctopus
198198
*/

0 commit comments

Comments
 (0)