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

Enable no unchecked index access rule #6441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thornbill
Copy link
Member

Changes
Enables the no unchecked index access rule for typescript as recommended here and fixes the related errors

Issues
N/A

@thornbill thornbill added typescript PRs or issues relating to TypeScript code cleanup Cleanup of legacy code or code smells labels Jan 12, 2025
@thornbill thornbill added this to the v10.11.0 milestone Jan 12, 2025
@thornbill thornbill requested a review from a team as a code owner January 12, 2025 09:27
@jellyfin-bot
Copy link
Collaborator

jellyfin-bot commented Jan 12, 2025

Cloudflare Pages deployment

Latest commit 422fe86
Status ✅ Deployed!
Preview URL https://77602c8a.jellyfin-web.pages.dev
Type 🔀 Preview

View build logs

if (ratings.length) {
const lastRating = ratings[ratings.length - 1];

if (lastRating.Value === rating.Value) {
if (lastRating && lastRating.Value === rating.Value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a rule to use an optional chain instead of foo && foo.bar?
foo && foo.bar is more portable though.

@@ -79,10 +79,12 @@ const UserParentalControl = () => {
for (let i = 0, length = allParentalRatings.length; i < length; i++) {
rating = allParentalRatings[i];

if (!rating) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we even get allParentalRatings with null|undefined elements?
I'm not a fan of checking everything (following some "pattern"), ignoring the fact that it will never happen. 🤷‍♂️ If this can happen, we silently ignore the invalid argument (the array with the invalid element), which can make it harder to find the error.

if (foundCard || !queue) {
ids.push(items[i].Id);
ids.push(items[i]?.Id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional chain is redundant - items[i] is checked above. But again, can items have invalid elements?

@@ -1,20 +1,20 @@
import type { MediaSegmentDto } from '@jellyfin/sdk/lib/generated-client/models/media-segment-dto';

const isBeforeSegment = (segment: MediaSegmentDto, time: number, direction: number) => {
const isBeforeSegment = (segment: MediaSegmentDto | undefined, time: number, direction: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to force the caller to check that segment is not "null", instead of putting optioal chains everywhere?

@@ -93,6 +93,8 @@ function getPosition(positionTo: Element, options: Options, dlg: HTMLElement) {

const pos = getOffsets([positionTo])[0];

if (!pos) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only case (with [positionTo]) where pos will be invalid is if document is not present. 😐

@@ -250,6 +252,8 @@ export function show(options: Options) {
for (let i = 0; i < options.items.length; i++) {
const item = options.items[i];

if (!item) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can happen?
If can - the error is shadowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Cleanup of legacy code or code smells typescript PRs or issues relating to TypeScript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants