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

fix: lint errors and wrong type mappings #2486

Merged
merged 2 commits into from
Nov 4, 2024
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
2 changes: 1 addition & 1 deletion frontend/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Linter } from 'eslint';
import { getBaseConfig, getTSVueConfig, getNodeFiles, unocss, getWorkerFiles } from '@jellyfin-vue/configs/eslint';
import { getBaseConfig, getTSVueConfig, getNodeFiles, unocss, getWorkerFiles } from '@jellyfin-vue/configs/lint';

// TODO: Add missing rules for i18n and json
export default [
Expand Down
2 changes: 1 addition & 1 deletion frontend/scripts/virtual-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const vuetifyExports = localeNames
* Get commit hash
*/
const commit_available = !Number(process.env.IS_STABLE) && Boolean(process.env.COMMIT_HASH);
const commit_hash = commit_available && `'${process.env.COMMIT_HASH}'` || undefined;
const commit_hash = (commit_available && `'${process.env.COMMIT_HASH}'`) || undefined;

/**
* Date-fns exports all english locales with variants, so we need to add the match manually
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const validationRules = [
* Chromium ranges:
* https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/media/html_media_element.cc
*/
return num_val >= 0.0625 && num_val <= 16 || t('mustBeInRange', { min: 0.0625, max: 16 });
return (num_val >= 0.0625 && num_val <= 16) || t('mustBeInRange', { min: 0.0625, max: 16 });
}
];

Expand Down
10 changes: 4 additions & 6 deletions frontend/src/components/Dialogs/ConfirmDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<VDivider />
<VCardText
class="text-center d-flex align-center justify-center">
<JSafeHtml :html="innerHtml" />
<JSafeHtml :html="state.text" />
</VCardText>
<VCardActions class="align-center justify-center">
<VBtn
Expand All @@ -33,7 +33,7 @@
variant="elevated"
:color="state.confirmColor ?? 'error'"
@click="confirm">
{{ state.confirmText }}
{{ state.confirmText ?? t('accept') }}
</VBtn>
</VCardActions>
</VCard>
Expand Down Expand Up @@ -89,9 +89,9 @@ export async function useConfirmDialog<T>(
params: ConfirmDialogState,
raiseError = false
): Promise<T | undefined> {
state.title = params.title || '';
state.title = params.title;
state.text = params.text;
state.subtitle = params.subtitle;
state.text = params.text || '';
state.confirmText = params.confirmText;
state.confirmColor = params.confirmColor;

Expand All @@ -109,6 +109,4 @@ export async function useConfirmDialog<T>(

<script setup lang="ts">
const { t } = useI18n();

const innerHtml = computed(() => state.text ?? t('accept'));
</script>
3 changes: 0 additions & 3 deletions frontend/src/components/Forms/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import IconEye from 'virtual:icons/mdi/eye';
import IconEyeOff from 'virtual:icons/mdi/eye-off';
import { ref, shallowRef } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { fetchIndexPage } from '@/utils/items';
import { remote } from '@/plugins/remote';
import { jsonConfig } from '@/utils/external-config';
Expand All @@ -85,8 +84,6 @@ defineEmits<{

const { t } = useI18n();

const router = useRouter();

const valid = shallowRef(false);
const login = ref({ username: '', password: '', rememberMe: true });
const showPassword = shallowRef(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Item/MediaStreamSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
if (
(type === 'Video' || type === 'Audio')
&& trackIndex.value === null
&& selectItems.value[0] !== undefined
&& selectItems.value?.[0]

Check failure on line 126 in frontend/src/components/Item/MediaStreamSelector.vue

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unnecessary conditional, value is always truthy

Check failure on line 126 in frontend/src/components/Item/MediaStreamSelector.vue

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unnecessary optional chain on a non-nullish value
) {
// eslint-disable-next-line unicorn/no-null
trackIndex.value = selectItems.value[0].value ?? null;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/composables/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { apiStore } from '@/store/api';
import { isArray, isNil } from '@/utils/validation';
import { JView_isRouting } from '@/store/keys';

/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-explicit-any */
type OmittedKeys = 'fields' | 'userId' | 'enableImages' | 'enableTotalRecordCount' | 'enableImageTypes';
type ParametersAsGetters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any
? { [K in keyof P]: () => BetterOmit<Mutable<P[K]>, OmittedKeys> }
Expand Down Expand Up @@ -470,4 +470,4 @@ export function methodsAsObject<T extends Record<K, (...args: any[]) => any>, K
};
}

/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return */
/* eslint-enable @typescript-eslint/no-explicit-any */
4 changes: 2 additions & 2 deletions frontend/src/composables/use-datefns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as datefnslocales from 'virtual:locales/date-fns';
import { i18n } from '@/plugins/i18n';
import { isObj } from '@/utils/validation';

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-explicit-any */

/**
* Use any date fns function with proper localization, based on the current locale.
Expand Down Expand Up @@ -35,4 +35,4 @@ export function useDateFns<T extends (...a: any[]) => any>(
return func(...params);
}

/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
/* eslint-enable @typescript-eslint/no-explicit-any */
2 changes: 1 addition & 1 deletion frontend/src/pages/genre/[itemId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const route = useRoute('/genre/[itemId]');
const { itemId } = route.params;

const includeItemTypes = computed<BaseItemKind[]>(() => {
const typesQuery = route.query.type as BaseItemKind ?? [];
const typesQuery = route.query.type ?? [] as BaseItemKind;

return isStr(typesQuery)
? [typesQuery]
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/server/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ meta:
import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
import { ref, shallowRef, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { remote } from '@/plugins/remote';
import { jsonConfig } from '@/utils/external-config';
import { usePageTitle } from '@/composables/page-title';
import { useSnackbar } from '@/composables/use-snackbar';
import { isConnectedToServer } from '@/store';

const { t } = useI18n();
const router = useRouter();

usePageTitle(() => t('login'));

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/plugins/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { DirectiveBinding } from 'vue';
* Toggles the CSS 'visibility' property of an element.
*/
export function hideDirective(
element: HTMLElement,
element: HTMLElement | undefined,
binding: DirectiveBinding<boolean>
): void {
if (element) {
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/store/playback-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,6 @@ class PlaybackManagerStore extends CommonStore<PlaybackManagerState> {
itemId
}));

if (!items.value) {
throw new Error('No items found');
}

for (const item of items.value) {
await this.addToQueue(item);
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export function getImageTag(
case ImageType.Primary: {
return (
item.AlbumPrimaryImageTag
|| item.ChannelPrimaryImageTag
|| item.ParentPrimaryImageTag
|| undefined
?? item.ChannelPrimaryImageTag
?? item.ParentPrimaryImageTag
?? undefined
);
}
case ImageType.Art: {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/utils/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ export function canPlay(item: BaseItemDto | undefined): boolean {
'Series',
'Trailer',
'Video'
].includes(item.Type || '')
|| ['Video', 'Audio'].includes(item.MediaType || '')
].includes(item.Type ?? '')
|| ['Video', 'Audio'].includes(item.MediaType ?? '')
|| item.IsFolder
);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ export function canMarkWatched(item: BaseItemDto): boolean {
*/
export function canInstantMix(item: BaseItemDto): boolean {
return ['Audio', 'MusicAlbum', 'MusicArtist', 'MusicGenre'].includes(
item.Type || ''
item.Type ?? ''
);
}

Expand Down Expand Up @@ -328,7 +328,7 @@ export function getItemDetailsLink(
if (!isPerson(item) && isLibrary(item)) {
routeName = '/library/[itemId]';
} else {
const type = overrideType || item.Type;
const type = overrideType ?? item.Type;

switch (type) {
case 'Series': {
Expand Down
2 changes: 1 addition & 1 deletion packages/configs/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Linter } from 'eslint';
import { getBaseConfig, getTSVueConfig, getNodeFiles, tsFiles } from './eslint/';
import { getBaseConfig, getTSVueConfig, getNodeFiles, tsFiles } from './lint/';

export default [
...getBaseConfig('@jellyfin-vue/configs'),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export function getBaseConfig(packageName: string, forceCache = !CI_environment,
const cacheLocation = join(findUpSync('node_modules', { type: 'directory' }) ?? '', '.cache/eslint', packageName.replace('/', '_'));

newArgs.push('--cache', '--cache-location', cacheLocation);
console.log('[@jellyfin-vue/configs/eslint] Force enabling caching for this run');
console.log('[@jellyfin-vue/configs/lint] Force enabling caching for this run');
}

if (warningAsErrors && !newArgs.some(arg => arg.includes('--max-warnings'))) {
newArgs.push('--max-warnings=0');
console.log('[@jellyfin-vue/configs/eslint] Force enabling warnings for this run');
console.log('[@jellyfin-vue/configs/lint] Force enabling warnings for this run');
}

const argsHaveChanged = new Set(newArgs).difference(new Set(process.argv.slice(1))).size > 0;
Expand All @@ -64,15 +64,15 @@ export function getBaseConfig(packageName: string, forceCache = !CI_environment,

return [
{ ...js.configs.recommended,
name: '(@jellyfin-vue/configs/eslint/base - eslint) Extended config from plugin'
name: '(@jellyfin-vue/configs/lint/base - eslint) Extended config from plugin'
},
{
...unicorn.configs['flat/recommended'],
name: '(@jellyfin-vue/configs/eslint/base - unicorn) Extended config from plugin'
name: '(@jellyfin-vue/configs/lint/base - unicorn) Extended config from plugin'
},
{
...dependConfigs['flat/recommended'],
name: '(@jellyfin-vue/configs/eslint/base - depend) Extended config from plugin'
name: '(@jellyfin-vue/configs/lint/base - depend) Extended config from plugin'
},
{
...stylistic.configs.customize({
Expand All @@ -83,10 +83,10 @@ export function getBaseConfig(packageName: string, forceCache = !CI_environment,
arrowParens: false,
blockSpacing: true
}),
name: '(@jellyfin-vue/configs/eslint/base - @stylistic) Extended config from plugin'
name: '(@jellyfin-vue/configs/lint/base - @stylistic) Extended config from plugin'
},
{
name: '(@jellyfin-vue/configs/eslint/base) Common settings',
name: '(@jellyfin-vue/configs/lint/base) Common settings',
rules: {
'no-empty': ['error', { allowEmptyCatch: true }],
'no-extend-native': 'error',
Expand Down Expand Up @@ -150,21 +150,21 @@ export function getBaseConfig(packageName: string, forceCache = !CI_environment,
},
{
...stylistic.configs['disable-legacy'],
name: '(@jellyfin-vue/configs/eslint/base) Disable stylistic legacy rules'
name: '(@jellyfin-vue/configs/lint/base) Disable stylistic legacy rules'
},
/**
* Extra files to include and ignores that should override all the others
*/
{
name: '(@jellyfin-vue/configs/eslint/base) Ignored files',
name: '(@jellyfin-vue/configs/lint/base) Ignored files',
ignores: [
'**/.git',
...gitignore().ignores
]
},
/** File progress plugin */
{
name: '(@jellyfin-vue/configs/eslint/base) Linting progress report',
name: '(@jellyfin-vue/configs/lint/base) Linting progress report',
settings: {
progress: {
successMessage: 'Linting done!'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import globals from 'globals';
*/
export function getNodeFiles(files = ['*.config.*', 'scripts/**/*.ts']): Linter.Config[] {
return [{
name: '(@jellyfin-vue/configs/eslint/env) Node.js and development-related files',
name: '(@jellyfin-vue/configs/lint/env) Node.js and development-related files',
files,
languageOptions: {
globals: {
Expand Down Expand Up @@ -35,7 +35,7 @@ export function getNodeFiles(files = ['*.config.*', 'scripts/**/*.ts']): Linter.
*/
export function getWorkerFiles(files = ['**/*.worker.ts']): Linter.Config[] {
return [{
name: '(@jellyfin-vue/configs/eslint/env) WebWorkers',
name: '(@jellyfin-vue/configs/lint/env) WebWorkers',
files,
languageOptions: {
globals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const json = [
/* First index is just the plugin definition */
...jsoncRecommended.at(0),
...jsoncRecommended.at(1),
name: '(@jellyfin-vue/configs/eslint/json) - Custom config',
name: '(@jellyfin-vue/configs/lint/json) - Custom config',
rules: {
...jsoncRecommended.at(1).rules,
...jsoncRecommended.at(2).rules,
Expand Down
Loading
Loading