Skip to content

Commit

Permalink
Enable prefer-nullish-coalescing ts eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Oct 29, 2024
1 parent 1e0571b commit ead13fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default [
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-expressions': 'warn',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
curly: 'error',
'import/newline-after-import': 'error',
Expand Down
4 changes: 2 additions & 2 deletions src/components/documentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export abstract class DocumentManager {
private static setGenres(name: string | null): void {
const element = this.querySelector('.genres');

element.innerHTML = name || '';
element.innerHTML = name ?? '';
}

/**
Expand All @@ -565,7 +565,7 @@ export abstract class DocumentManager {
private static setOverview(name: string | null): void {
const element = this.querySelector('.overview');

element.innerHTML = name || '';
element.innerHTML = name ?? '';
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/components/maincontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,12 @@ export async function changeStream(

// @ts-expect-error is possible here
return await PlaybackManager.playItemInternal(state.item, {
audioStreamIndex:
params.AudioStreamIndex == null
? state.audioStreamIndex
: params.AudioStreamIndex,
audioStreamIndex: params.AudioStreamIndex ?? state.audioStreamIndex,
liveStreamId: state.liveStreamId,
mediaSourceId: state.mediaSourceId,
startPositionTicks: ticks,
subtitleStreamIndex:
params.SubtitleStreamIndex == null
? state.subtitleStreamIndex
: params.SubtitleStreamIndex
params.SubtitleStreamIndex ?? state.subtitleStreamIndex
});
}

Expand Down
20 changes: 10 additions & 10 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function getSenderReportingData(
const nowPlayingItem = state.NowPlayingItem;

nowPlayingItem.ServerId = item.ServerId;
nowPlayingItem.Chapters = item.Chapters || [];
nowPlayingItem.Chapters = item.Chapters ?? [];

const mediaSource = item.MediaSources?.filter((m: MediaSourceInfo) => {
return m.Id == reportingData.MediaSourceId;
Expand All @@ -116,7 +116,7 @@ export function getSenderReportingData(
nowPlayingItem.Album = item.Album;
nowPlayingItem.Artists = item.Artists;

const imageTags = item.ImageTags || {};
const imageTags = item.ImageTags ?? {};

if (item.SeriesPrimaryImageTag) {
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
Expand Down Expand Up @@ -239,7 +239,7 @@ export function getMetadata(item: BaseItemDto): any {
}

// previously: p.PersonType == 'Type'.. wtf?
const composer = (item.People || []).filter(
const composer = (item.People ?? []).filter(
(p: BaseItemPerson) => p.Type == 'Composer'
)[0];

Expand Down Expand Up @@ -326,7 +326,7 @@ export function createStreamInfo(
`videos/${item.Id}/stream.${mediaSource.Container}?mediaSourceId=${mediaSource.Id}&api_key=${JellyfinApi.accessToken}&static=true${seekParam}`
);
isStatic = true;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
} else {
// TODO deal with !TranscodingUrl
mediaUrl = JellyfinApi.createUrl(
Expand All @@ -335,7 +335,7 @@ export function createStreamInfo(

if (isHlsStream(mediaSource)) {
mediaUrl += seekParam;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
contentType = 'application/x-mpegURL';
streamContainer = 'm3u8';
} else {
Expand All @@ -355,13 +355,13 @@ export function createStreamInfo(
if (mediaSource.SupportsDirectPlay) {
mediaUrl = mediaSource.Path;
isStatic = true;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
} else {
const isDirectStream = mediaSource.SupportsDirectStream;

if (isDirectStream) {
const outputContainer = (
mediaSource.Container || ''
mediaSource.Container ?? ''
).toLowerCase();

mediaUrl = JellyfinApi.createUrl(
Expand All @@ -382,7 +382,7 @@ export function createStreamInfo(

// TODO: Remove the second half of the expression by supporting changing the mediaElement src dynamically.
// It is a pain and will require unbinding all event handlers during the operation
const canSeek = (mediaSource.RunTimeTicks || 0) > 0;
const canSeek = (mediaSource.RunTimeTicks ?? 0) > 0;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const info: any = {
Expand Down Expand Up @@ -560,7 +560,7 @@ export async function getItemsForPlayback(
query: ItemQuery
): Promise<BaseItemDtoQueryResult> {
query.UserId = userId;
query.Limit = query.Limit || 100;
query.Limit = query.Limit ?? 100;
query.Fields = requiredItemFields;
query.ExcludeLocationTypes = 'Virtual';

Expand Down Expand Up @@ -720,7 +720,7 @@ export async function translateRequestedItems(
}
);

episodesResult.TotalRecordCount = episodesResult.Items?.length || 0;
episodesResult.TotalRecordCount = episodesResult.Items?.length ?? 0;

return episodesResult;
}
Expand Down

0 comments on commit ead13fe

Please sign in to comment.