Skip to content

Commit

Permalink
chore: enforce explicit return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-w151 committed Feb 21, 2025
1 parent ada7ca4 commit 1b9d54d
Show file tree
Hide file tree
Showing 46 changed files with 183 additions and 133 deletions.
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ export default [
ignores: ['build/', '.svelte-kit/', '.vercel', 'dist/', 'playwright-report/', 'test-results/'],
},
{
files: ['**/*.{ts,svelte}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/backend/db/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function searchStory(url: string, options?: SearchStoryOptions): Pr
}
}

function buildQuery({ textFilter, dateFilter, sources }: SearchRequestParameters) {
function buildQuery({ textFilter, dateFilter, sources }: SearchRequestParameters): any {
const textFilters = textFilter
?.split(/\s+/)
.filter((text) => !!text)
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/news/News.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
clearTimeout(checkUpdatesTimeout);
});
async function fetchNews(searchRequestParameters: SearchRequestParameters) {
async function fetchNews(searchRequestParameters: SearchRequestParameters): Promise<void> {
await news.taskWithLoading(async () => {
const foundNews = await searchNews(searchRequestParameters);
if (!foundNews?.prevKey) {
Expand All @@ -60,7 +60,7 @@
setCheckUpdatesTimeout(true);
}
async function fetchNewNews() {
async function fetchNewNews(): Promise<void> {
await news.taskWithLoading(async () => {
const currSearchRequestParameters = get(searchRequestParameters);
const prevKey = get(news).prevKey;
Expand All @@ -74,7 +74,7 @@
setCheckUpdatesTimeout(true);
}
async function fetchMoreNews() {
async function fetchMoreNews(): Promise<void> {
await news.taskWithLoading(async () => {
const currSearchRequestParameters = get(searchRequestParameters);
const nextKey = get(news).nextKey;
Expand All @@ -86,7 +86,7 @@
});
}
async function fetchNewsUpdates() {
async function fetchNewsUpdates(): Promise<void> {
const currSearchRequestParameters = get(searchRequestParameters);
const prevKey = get(news).prevKey;
if (!prevKey) {
Expand Down Expand Up @@ -119,7 +119,7 @@
cancelCheckNewsUpdates();
}
function setCheckUpdatesTimeout(initial: boolean) {
function setCheckUpdatesTimeout(initial: boolean): void {
if (!$settings.checkNewsUpdates) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/news/filter/BookmarkActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
unsubscribeAll(subscriptions);
});
function handleStartSearch() {
function handleStartSearch(): void {
textFilterInputRef?.focus();
}
function handleTextFilterChange(textFilter?: string) {
function handleTextFilterChange(textFilter?: string): void {
bookmarks.setTextFilter(textFilter ?? '');
}
function handleDeleteAllBookmarks() {
function handleDeleteAllBookmarks(): void {
bookmarks.removeAll();
}
function handleDeleteAllViewedBookmarks() {
function handleDeleteAllViewedBookmarks(): void {
bookmarks.removeAllViewed();
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/news/filter/BookmarkDeletePopover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
transition
`;
function handleRemoveAllBookmarksButtonClick() {
function handleRemoveAllBookmarksButtonClick(): void {
onRemoveAllBookmarks?.();
}
function handleRemoveAllViewedBookmarksButtonClick() {
function handleRemoveAllViewedBookmarksButtonClick(): void {
onRemoveAllViewedBookmarks?.();
}
</script>
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/news/filter/NewsFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
unsubscribeAll(subscriptions);
});
function handleStartSearch() {
function handleStartSearch(): void {
textFilterInputRef?.focus();
}
function handleTextFilterChange(textFilter?: string) {
function handleTextFilterChange(textFilter?: string): void {
searchFilter.setTextFilter(textFilter);
}
function handleDateFilterFromChange(from?: string) {
function handleDateFilterFromChange(from?: string): void {
searchFilter.setFrom(from);
}
function handleDateFilterToChange(to?: string) {
function handleDateFilterToChange(to?: string): void {
searchFilter.setTo(to);
}
</script>
Expand Down
16 changes: 8 additions & 8 deletions src/lib/components/news/filter/NewsFilterPopover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@
const menuActionsClass = `grid grid-cols-2 gap-x-3 gap-y-2 w-full`;
const menuButtonClass = `!w-full`;
function handleFromChange(from?: DateTime) {
function handleFromChange(from?: DateTime): void {
onFromChange?.(from?.startOf('day').toISO() ?? undefined);
}
function handleToChange(to?: DateTime) {
function handleToChange(to?: DateTime): void {
onToChange?.(to?.endOf('day').toISO() ?? undefined);
}
function handleApplyClick() {
function handleApplyClick(): void {
onApply?.();
}
function handleResetClick() {
function handleResetClick(): void {
onReset?.();
}
function handleSelectTodayClick() {
function handleSelectTodayClick(): void {
onSelectToday?.();
}
function handleSelectLastWeekClick() {
function handleSelectLastWeekClick(): void {
onSelectLastWeek?.();
}
function handleSelectLastMonthClick() {
function handleSelectLastMonthClick(): void {
onSelectLastMonth?.();
}
function handleSelectLastYearClick() {
function handleSelectLastYearClick(): void {
onSelectLastYear?.();
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let { story, class: clazz, onClose }: Props = $props();
function handleAddToBookmarksClick() {
function handleAddToBookmarksClick(): void {
bookmarks.add(story);
notifications.notify('Lesezeichen hinzugefügt', 'Der Artikel wurde zu deinen Lesezeichen hinzugefügt.', {
forceAppNotification: true,
Expand All @@ -24,7 +24,7 @@
onClose?.();
}
function handleRemoveFromBookmarksClick() {
function handleRemoveFromBookmarksClick(): void {
bookmarks.remove(story);
notifications.notify('Lesezeichen entfernt', 'Der Artikel wurde von deinen Lesezeichen entfernt.', {
forceAppNotification: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let { story, class: clazz, onClose }: Props = $props();
function handleOpenArticleClick() {
function handleOpenArticleClick(): void {
onClose?.();
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let { class: clazz, onClose }: Props = $props();
function handleOpenSupportClick() {
function handleOpenSupportClick(): void {
onClose?.();
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
return !!navigator.clipboard?.writeText;
}
async function handleShareArticleClick() {
async function handleShareArticleClick(): Promise<void> {
try {
await navigator.share(shareData);
} catch (error) {
Expand All @@ -38,7 +38,7 @@
onClose?.();
}
async function handleCopyToClipboardClick() {
async function handleCopyToClipboardClick(): Promise<void> {
const text = new Blob([story.url], { type: 'text/plain' });
const html = new Blob(
[`<a id="${story.id}" data-timestamp="${story.timestamp}" href="${story.url}">${story.title}</a>`],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/settings/appearance/Appearance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let colorScheme: ColorScheme = $state($styles.colorScheme);
function handleColorSchemeRadioChange() {
function handleColorSchemeRadioChange(): void {
if (colorScheme) {
styles.setColorScheme(colorScheme);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/settings/developer/Developer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
return estimate.usage;
}
function handleResetIndexedDbButtonClick() {
function handleResetIndexedDbButtonClick(): void {
indexedDB.deleteDatabase(BOOKMARKS_STORE_NAME);
location.reload();
}
function handleResetLocalStorageButtonClick() {
function handleResetLocalStorageButtonClick(): void {
localStorage.clear();
location.reload();
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/shared/app/EnableAnalytics.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { browser } from '$app/environment';
import { PUBLIC_ENABLE_ANALYTICS } from '$env/static/public';
function isAnalyticsEnabled() {
function isAnalyticsEnabled(): boolean {
return PUBLIC_ENABLE_ANALYTICS === 'true';
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/shared/app/EnableDarkMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
});
function applyColorScheme(colorScheme: ColorScheme, prefersDarkColorScheme?: boolean) {
function applyColorScheme(colorScheme: ColorScheme, prefersDarkColorScheme?: boolean): void {
if (colorScheme === 'system') {
if (prefersDarkColorScheme ?? getPrefersDarkColorSchemeQuery()?.matches) {
setDarkClass();
Expand All @@ -37,22 +37,22 @@
}
}
function changeColorScheme({ matches: prefersDarkColorScheme }: { matches: boolean }) {
function changeColorScheme({ matches: prefersDarkColorScheme }: { matches: boolean }): void {
const colorScheme = $styles.colorScheme;
if (colorScheme === 'system') {
applyColorScheme(colorScheme, prefersDarkColorScheme);
}
}
function getPrefersDarkColorSchemeQuery() {
function getPrefersDarkColorSchemeQuery(): MediaQueryList {
return window.matchMedia('(prefers-color-scheme: dark)');
}
function setLightClass() {
function setLightClass(): void {
document.documentElement.classList.remove('dark');
}
function setDarkClass() {
function setDarkClass(): void {
document.documentElement.classList.add('dark');
}
</script>
4 changes: 2 additions & 2 deletions src/lib/components/shared/app/EnableGlobalKeybindings.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import { startSearch } from '$lib/stores/newsEvents';
function handleKeydown(event: KeyboardEvent) {
function handleKeydown(event: KeyboardEvent): void {
if (isSearchShortcut(event)) {
event.preventDefault();
startSearch.notify();
}
}
function isSearchShortcut(event: KeyboardEvent) {
function isSearchShortcut(event: KeyboardEvent): boolean {
const { key, metaKey, ctrlKey } = event;
return (metaKey || ctrlKey) && ['f', 'k'].includes(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
warnIfOffline($online);
});
function warnIfOffline(online: boolean) {
function warnIfOffline(online: boolean): void {
if (!online) {
notifications.notify(
'Verbindung unterbrochen',
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/shared/content/AudioPlayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
const metadataClass = ['flex flex-wrap items-center gap-x-1 text-sm text-gray-600 dark:text-gray-300'];
const controlsClass = ['flex justify-center gap-2'];
function handleToggleMinimized() {
function handleToggleMinimized(): void {
minimized = !minimized;
}
function handleClose() {
function handleClose(): void {
audioStore.end();
minimized = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/shared/content/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
let isNewsPage = $derived($page.url.pathname === '/');
function handleRefreshButtonClick() {
function handleRefreshButtonClick(): void {
refreshNews.notify();
}
async function handleCacheForOfflineUseClick() {
async function handleCacheForOfflineUseClick(): Promise<void> {
notifications.notify('Download gestartet', 'Die neuesten Artikel werden für später geladen.', {
uniqueCategory: NOTIFICATION_OFFLINE_CACHE_DOWNLOADED,
replaceInCategory: true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/shared/content/Popover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
let popoverButtonClass = $derived(buttonClassFn({ btnType, size, iconOnly, round }));
export function setOpen(newOpen: boolean) {
export function setOpen(newOpen: boolean): void {
open = newOpen;
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/shared/controls/DateInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
onchange?.(value);
});
export function focus() {
export function focus(): void {
inputRef?.focus();
}
function handleKeydown(event: KeyboardEvent) {
function handleKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
inputRef?.blur();
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/shared/controls/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
onValueChange?.(value);
});
export function focus() {
export function focus(): void {
inputRef?.focus();
}
function handleClearButtonClick() {
function handleClearButtonClick(): void {
value = '';
onclear?.();
inputRef?.focus();
}
function handleKeydown(event: KeyboardEvent) {
function handleKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
inputRef?.blur();
Expand Down
Loading

0 comments on commit 1b9d54d

Please sign in to comment.