From 47340c102e63c8317f45c038cf0c129c9e21525c Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Mon, 11 Dec 2023 16:26:10 -0800 Subject: [PATCH] Fixing eslint and types. Cleaning up bandcamp scrape and tests. --- .eslintrc.cjs | 30 ++++++++++++++-------- src/lib/renderImage.ts | 4 ++- src/lib/types/album.ts | 5 +++- src/lib/util/fetchBandcampAlbums.test.ts | 2 -- src/lib/util/fetchBandcampAlbums.ts | 4 +-- src/routes/about/+page.svelte | 3 --- src/routes/articles/+page.ts | 1 - src/routes/articles/[page]/+page.server.ts | 1 + src/routes/og/+server.ts | 9 +++---- 9 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3ccf435..770ef68 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,20 +1,30 @@ module.exports = { root: true, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:svelte/recommended', + 'prettier' + ], parser: '@typescript-eslint/parser', - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], - plugins: ['svelte3', '@typescript-eslint'], - ignorePatterns: ['*.cjs'], - overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], - settings: { - 'svelte3/typescript': () => require('typescript') - }, + plugins: ['@typescript-eslint'], parserOptions: { sourceType: 'module', - ecmaVersion: 2020 + ecmaVersion: 2020, + extraFileExtensions: ['.svelte'] }, env: { browser: true, es2017: true, node: true - } -}; + }, + overrides: [ + { + files: ['*.svelte'], + parser: 'svelte-eslint-parser', + parserOptions: { + parser: '@typescript-eslint/parser' + } + } + ] +}; \ No newline at end of file diff --git a/src/lib/renderImage.ts b/src/lib/renderImage.ts index 87a7f4a..357ff26 100644 --- a/src/lib/renderImage.ts +++ b/src/lib/renderImage.ts @@ -6,7 +6,9 @@ import { html as toReactNode } from 'satori-html'; import firaSansSemiBold from '$lib/fonts/FiraSans-SemiBold.ttf'; import { dev } from '$app/environment'; -export async function componentToPng(component, props, height, width) { +export async function componentToPng(component, + props: Record, + height: number, width: number) { const result = component.render(props); const markup = toReactNode(`${result.html}`); diff --git a/src/lib/types/album.ts b/src/lib/types/album.ts index 83c34ea..07ec0d1 100644 --- a/src/lib/types/album.ts +++ b/src/lib/types/album.ts @@ -1,9 +1,12 @@ +export type BandCampResults = { + collectionItems: Album[]; +} + export type Album = { url: string; artwork: string; title: string; artist: string; - src?: ExternalImageSource[]; }; export type ExternalImageSource = { diff --git a/src/lib/util/fetchBandcampAlbums.test.ts b/src/lib/util/fetchBandcampAlbums.test.ts index e08138a..09ddd5a 100644 --- a/src/lib/util/fetchBandcampAlbums.test.ts +++ b/src/lib/util/fetchBandcampAlbums.test.ts @@ -4,14 +4,12 @@ import { fetchBandcampAlbums } from './fetchBandcampAlbums'; describe('test fetchBandcampAlbums', () => { it('fetches bandcamp albums', async () => { const albums = await fetchBandcampAlbums(); - console.log('albums'); expect(albums).not.toBeNull(); expect(albums).toBeTruthy(); expect(albums?.length).toBeGreaterThan(0); for (const album of albums) { expect(album?.artist).toHaveLength; expect(album?.artwork).toHaveLength; - expect(album?.src).toHaveLength; expect(album?.title).toHaveLength; expect(album?.url).toHaveLength; } diff --git a/src/lib/util/fetchBandcampAlbums.ts b/src/lib/util/fetchBandcampAlbums.ts index 3aa06d1..9c01bd1 100644 --- a/src/lib/util/fetchBandcampAlbums.ts +++ b/src/lib/util/fetchBandcampAlbums.ts @@ -2,7 +2,7 @@ import { BANDCAMP_USERNAME, USE_REDIS_CACHE } from '$env/static/private'; import scrapeIt from 'scrape-it'; import type { ScrapeResult } from 'scrape-it'; import { redis } from '$lib/server/redis'; -import type { Album } from '../types/album'; +import type { Album, BandCampResults } from '../types/album'; export async function fetchBandcampAlbums() { try { @@ -18,7 +18,7 @@ export async function fetchBandcampAlbums() { } } - const { data }: ScrapeResult = await scrapeIt( + const { data }: ScrapeResult = await scrapeIt( `https://bandcamp.com/${BANDCAMP_USERNAME}`, { collectionItems: { diff --git a/src/routes/about/+page.svelte b/src/routes/about/+page.svelte index c9f824a..a09c104 100644 --- a/src/routes/about/+page.svelte +++ b/src/routes/about/+page.svelte @@ -1,5 +1,4 @@