diff --git a/.eslintrc.yml b/.eslintrc.yml index f6c7519..b8f72ef 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,16 +1,21 @@ +root: true env: browser: true es2020: true node: true -extends: - - eslint:recommended +parser: '@typescript-eslint/parser' parserOptions: sourceType: module ecmaVersion: 2020 -plugins: [svelte3] +plugins: [svelte3, '@typescript-eslint'] +extends: + - eslint:recommended + - plugin:@typescript-eslint/recommended overrides: - files: ['*.svelte'] processor: svelte3/svelte3 +settings: + svelte3/typescript: true rules: indent: [error, 2, SwitchCase: 1] quotes: [error, backtick, avoidEscape: true] @@ -18,4 +23,7 @@ rules: linebreak-style: [error, unix] no-console: [error, allow: [warn, error]] no-var: error - spaced-comment: [error, always] + # allow triple slash for typescript file referencing https://git.io/JCeqO + spaced-comment: [error, always, { markers: [/] }] +globals: + $$props: false # declare the Svelte $$props object as a non-writable global variable diff --git a/package.json b/package.json index 63a660d..a5aa5d0 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,8 @@ "devDependencies": { "@sveltejs/adapter-static": "^1.0.0-next.13", "@sveltejs/kit": "^1.0.0-next.118", + "@typescript-eslint/eslint-plugin": "^4.28.2", + "@typescript-eslint/parser": "^4.28.2", "ava": "^3.15.0", "dotenv": "^10.0.0", "eslint": "^7.29.0", @@ -44,10 +46,14 @@ "rehype-autolink-headings": "^5.1.0", "rehype-slug": "^4.0.1", "svelte": "^3.38.3", + "svelte-check": "^2.2.2", + "svelte-preprocess": "^4.7.4", "svelte-toc": "^0.1.5", + "svelte2tsx": "^0.4.1", + "typescript": "^4.3.5", "vite": "^2.3.8" }, "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..63908c6 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1 @@ +/// diff --git a/src/hooks.js b/src/hooks.js deleted file mode 100644 index 83dde88..0000000 --- a/src/hooks.js +++ /dev/null @@ -1,9 +0,0 @@ -// https://kit.svelte.dev/docs#hooks-getsession -/** @type {import('@sveltejs/kit').GetSession} */ -export function getSession() { - const keys = [`ALGOLIA_APP_ID`, `ALGOLIA_SEARCH_KEY`] - - const session = Object.fromEntries(keys.map((key) => [key, process.env[key]])) - - return session -} diff --git a/src/hooks.ts b/src/hooks.ts new file mode 100644 index 0000000..3f04bb8 --- /dev/null +++ b/src/hooks.ts @@ -0,0 +1,15 @@ +// https://kit.svelte.dev/docs#hooks-getsession +export function getSession(): Record { + const keys = [`ALGOLIA_APP_ID`, `ALGOLIA_SEARCH_KEY`] + + for (const key of keys) { + if (!process.env[key]) { + // eslint-disable-next-line no-console + console.error(`missing secret key: ${key}`) + } + } + + const session = Object.fromEntries(keys.map((key) => [key, process.env[key] as string])) + + return session +} diff --git a/src/lib/Search.svelte b/src/lib/Search.svelte index c01f8b4..0091343 100644 --- a/src/lib/Search.svelte +++ b/src/lib/Search.svelte @@ -1,13 +1,19 @@ - - - - -