From 57fcb211e373cf54da2ba83c37b6ba14532a441e Mon Sep 17 00:00:00 2001 From: Sebastian Jeltsch Date: Sun, 2 Mar 2025 21:12:23 +0100 Subject: [PATCH] Add eslint to docs. --- docs/.prettierrc.mjs | 6 +-- docs/eslint.config.mjs | 43 +++++++++++++++++++ .../record_api_dart/analysis_options.yaml | 1 - docs/examples/record_api_ts/src/update.ts | 7 ++- .../record_api_ts/tests/basic.test.ts | 7 ++- docs/examples/record_api_ts/tsconfig.json | 5 +-- docs/package.json | 14 ++++-- docs/src/components/BarChart.tsx | 8 ++-- docs/src/components/LineChart.tsx | 4 +- docs/src/components/ScatterChart.tsx | 4 +- docs/src/components/SplitCard.astro | 3 +- .../docs/documentation/APIs/_record_apis.ts | 2 +- .../docs/reference/_benchmarks/benchmarks.tsx | 11 ++++- docs/tsconfig.json | 6 +-- pnpm-lock.yaml | 24 +++++++++++ 15 files changed, 111 insertions(+), 34 deletions(-) create mode 100644 docs/eslint.config.mjs diff --git a/docs/.prettierrc.mjs b/docs/.prettierrc.mjs index 85ccfb56..83e385b0 100644 --- a/docs/.prettierrc.mjs +++ b/docs/.prettierrc.mjs @@ -1,12 +1,12 @@ // .prettierrc.mjs /** @type {import("prettier").Config} */ export default { - plugins: ['prettier-plugin-astro'], + plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss"], overrides: [ { - files: '*.astro', + files: "*.astro", options: { - parser: 'astro', + parser: "astro", }, }, ], diff --git a/docs/eslint.config.mjs b/docs/eslint.config.mjs new file mode 100644 index 00000000..eb54ba58 --- /dev/null +++ b/docs/eslint.config.mjs @@ -0,0 +1,43 @@ +import globals from "globals"; +import pluginJs from "@eslint/js"; +import tseslint from "typescript-eslint"; +import tailwind from "eslint-plugin-tailwindcss"; +import solid from "eslint-plugin-solid/configs/recommended"; +import astro from "eslint-plugin-astro"; + +export default [ + pluginJs.configs.recommended, + ...tseslint.configs.recommended, + solid, + ...tailwind.configs["flat/recommended"], + ...astro.configs.recommended, + { + ignores: ["dist/", "node_modules/", ".astro/", "src/env.d.ts"], + }, + { + files: ["**/*.{js,mjs,cjs,mts,ts,tsx,jsx,astro}"], + rules: { + // https://typescript-eslint.io/rules/no-explicit-any/ + "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-wrapper-object-types": "warn", + // http://eslint.org/docs/rules/no-unused-vars + "@typescript-eslint/no-unused-vars": [ + "error", + { + vars: "all", + args: "after-used", + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], + // Collides with astro, we'd have to configure the solid plugin to ignore astro files. + "solid/no-unknown-namespaces": "off", + }, + languageOptions: { globals: globals.browser }, + settings: { + tailwindcss: { + whitelist: ["hide-scrollbars", "collapsible.*"], + }, + }, + }, +]; diff --git a/docs/examples/record_api_dart/analysis_options.yaml b/docs/examples/record_api_dart/analysis_options.yaml index 32774075..03a9f26e 100644 --- a/docs/examples/record_api_dart/analysis_options.yaml +++ b/docs/examples/record_api_dart/analysis_options.yaml @@ -6,7 +6,6 @@ linter: unnecessary_brace_in_string_interps: false unawaited_futures: true sort_child_properties_last: false - # analyzer: # exclude: # - path/to/excluded/files/** diff --git a/docs/examples/record_api_ts/src/update.ts b/docs/examples/record_api_ts/src/update.ts index d46b4c19..fde99436 100644 --- a/docs/examples/record_api_ts/src/update.ts +++ b/docs/examples/record_api_ts/src/update.ts @@ -1,4 +1,7 @@ import { Client } from "trailbase"; -export const update = async (client: Client, id: string | number, record: object) => - await client.records("simple_strict_table").update(id, record); +export const update = async ( + client: Client, + id: string | number, + record: object, +) => await client.records("simple_strict_table").update(id, record); diff --git a/docs/examples/record_api_ts/tests/basic.test.ts b/docs/examples/record_api_ts/tests/basic.test.ts index 6b8fa4b2..53647958 100644 --- a/docs/examples/record_api_ts/tests/basic.test.ts +++ b/docs/examples/record_api_ts/tests/basic.test.ts @@ -25,13 +25,13 @@ test("Test code examples", async () => { { const record = await read(client, id); - expect(record).toMatchObject({ "text_not_null": "test" }); + expect(record).toMatchObject({ text_not_null: "test" }); } { - await update(client, id, { "text_not_null": "updated" }); + await update(client, id, { text_not_null: "updated" }); const record = await read(client, id); - expect(record).toMatchObject({ "text_not_null": "updated" }); + expect(record).toMatchObject({ text_not_null: "updated" }); } await remove(client, id); @@ -57,7 +57,6 @@ test("Test code examples", async () => { } recordStream.cancel(); } - }); test("Test list examples", async () => { diff --git a/docs/examples/record_api_ts/tsconfig.json b/docs/examples/record_api_ts/tsconfig.json index d88d4043..4e9bb2de 100644 --- a/docs/examples/record_api_ts/tsconfig.json +++ b/docs/examples/record_api_ts/tsconfig.json @@ -14,8 +14,5 @@ } }, "include": ["src/**/*"], - "exclude": [ - "dist", - "node_modules" - ] + "exclude": ["dist", "node_modules"] } diff --git a/docs/package.json b/docs/package.json index 16e4f5d7..7cdea91e 100644 --- a/docs/package.json +++ b/docs/package.json @@ -8,8 +8,8 @@ "build": "astro check && astro build", "preview": "astro preview", "astro": "astro", - "check": "astro check", - "format": "prettier -w tailwind.config.ts astro.config.mjs src " + "check": "astro check && eslint", + "format": "prettier -w ." }, "dependencies": { "@astrojs/check": "^0.9.4", @@ -31,8 +31,16 @@ "devDependencies": { "@astrojs/sitemap": "^3.2.1", "@astrojs/solid-js": "^5.0.4", + "@eslint/js": "^9.21.0", "astro-robots-txt": "^1.0.0", + "eslint": "^9.21.0", + "eslint-plugin-astro": "^1.3.1", + "eslint-plugin-solid": "^0.14.5", + "eslint-plugin-tailwindcss": "^3.18.0", + "globals": "^15.15.0", "prettier": "^3.5.2", - "prettier-plugin-astro": "^0.14.1" + "prettier-plugin-astro": "^0.14.1", + "prettier-plugin-tailwindcss": "^0.6.11", + "typescript-eslint": "^8.25.0" } } diff --git a/docs/src/components/BarChart.tsx b/docs/src/components/BarChart.tsx index b9e8c506..7ddfdd5c 100644 --- a/docs/src/components/BarChart.tsx +++ b/docs/src/components/BarChart.tsx @@ -63,8 +63,8 @@ export function BarChart(props: BarChartProps) { onCleanup(() => chart?.destroy()); return ( -
- +
+
); } @@ -161,8 +161,8 @@ export function BarChartWithErrors(props: BarChartWithErrorsProps) { onCleanup(() => chart?.destroy()); return ( -
- +
+
); } diff --git a/docs/src/components/LineChart.tsx b/docs/src/components/LineChart.tsx index 6254db85..3ad2b554 100644 --- a/docs/src/components/LineChart.tsx +++ b/docs/src/components/LineChart.tsx @@ -57,8 +57,8 @@ export function LineChart(props: LineChartProps) { onCleanup(() => chart?.destroy()); return ( -
- +
+
); } diff --git a/docs/src/components/ScatterChart.tsx b/docs/src/components/ScatterChart.tsx index dcbceea5..d1d61457 100644 --- a/docs/src/components/ScatterChart.tsx +++ b/docs/src/components/ScatterChart.tsx @@ -57,8 +57,8 @@ export function ScatterChart(props: ScatterChartProps) { onCleanup(() => chart?.destroy()); return ( -
- +
+
); } diff --git a/docs/src/components/SplitCard.astro b/docs/src/components/SplitCard.astro index 3b1f4981..46c28710 100644 --- a/docs/src/components/SplitCard.astro +++ b/docs/src/components/SplitCard.astro @@ -1,9 +1,10 @@ --- import { Card } from "@astrojs/starlight/components"; +import { type StarlightIcon } from "@astrojs/starlight/types"; export interface Props { title: string; - icon?: any; + icon?: StarlightIcon; reverse?: boolean; } diff --git a/docs/src/content/docs/documentation/APIs/_record_apis.ts b/docs/src/content/docs/documentation/APIs/_record_apis.ts index c96310be..c52d4c8c 100644 --- a/docs/src/content/docs/documentation/APIs/_record_apis.ts +++ b/docs/src/content/docs/documentation/APIs/_record_apis.ts @@ -9,6 +9,6 @@ export const recordApiIdPlaceholder = ""; export function apiPath(opts: ApiOptions): string { const apiBase = "/api/records/v1"; - let suffix = opts.suffix ? `/${opts.suffix}` : ""; + const suffix = opts.suffix ? `/${opts.suffix}` : ""; return `${opts.prefix ?? ""}${apiBase}/${opts.name}${suffix}`; } diff --git a/docs/src/content/docs/reference/_benchmarks/benchmarks.tsx b/docs/src/content/docs/reference/_benchmarks/benchmarks.tsx index 462877a7..eb97e366 100644 --- a/docs/src/content/docs/reference/_benchmarks/benchmarks.tsx +++ b/docs/src/content/docs/reference/_benchmarks/benchmarks.tsx @@ -148,6 +148,13 @@ export function Duration100kInsertsChart() { ); } +type Percentiles = { + p50: number; + p75: number; + p90: number; + p95: number; +}; + export function PocketBaseAndTrailBaseReadLatencies() { // 2024-10-12 // TB: Read 1 000 000 messages, took 0:00:57.952120 (limit=64) (Dart JIT) @@ -202,7 +209,7 @@ export function PocketBaseAndTrailBaseReadLatencies() { p95: 20503, }; - const latenciesMs = (d: any) => + const latenciesMs = (d: Percentiles) => [d.p50, d.p75, d.p90, d.p95].map((p) => p / 1000); const data: ChartData<"bar"> = { @@ -300,7 +307,7 @@ export function PocketBaseAndTrailBaseInsertLatencies() { p95: 61512, }; - const latenciesMs = (d: any) => + const latenciesMs = (d: Percentiles) => [d.p50, d.p75, d.p90, d.p95].map((p) => p / 1000); const data: ChartData<"bar"> = { diff --git a/docs/tsconfig.json b/docs/tsconfig.json index b8cf914b..0442692c 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -11,9 +11,5 @@ "@root/*": ["../*"] } }, - "exclude": [ - "dist", - "node_modules", - "public" - ] + "exclude": ["dist", "node_modules", "public"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9f59a013..98dc9835 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,15 +60,39 @@ importers: '@astrojs/solid-js': specifier: ^5.0.4 version: 5.0.4(@testing-library/jest-dom@6.6.3)(@types/node@22.13.5)(jiti@2.4.2)(lightningcss@1.29.1)(solid-devtools@0.30.1(solid-js@1.9.5)(vite@6.2.0(@types/node@22.13.5)(jiti@2.4.2)(lightningcss@1.29.1)(yaml@2.7.0)))(solid-js@1.9.5)(yaml@2.7.0) + '@eslint/js': + specifier: ^9.21.0 + version: 9.21.0 astro-robots-txt: specifier: ^1.0.0 version: 1.0.0 + eslint: + specifier: ^9.21.0 + version: 9.21.0(jiti@2.4.2) + eslint-plugin-astro: + specifier: ^1.3.1 + version: 1.3.1(eslint@9.21.0(jiti@2.4.2)) + eslint-plugin-solid: + specifier: ^0.14.5 + version: 0.14.5(eslint@9.21.0(jiti@2.4.2))(typescript@5.7.3) + eslint-plugin-tailwindcss: + specifier: ^3.18.0 + version: 3.18.0(tailwindcss@3.4.17(ts-node@10.9.2(@types/node@22.13.5)(typescript@5.7.3))) + globals: + specifier: ^15.15.0 + version: 15.15.0 prettier: specifier: ^3.5.2 version: 3.5.2 prettier-plugin-astro: specifier: ^0.14.1 version: 0.14.1 + prettier-plugin-tailwindcss: + specifier: ^0.6.11 + version: 0.6.11(prettier-plugin-astro@0.14.1)(prettier@3.5.2) + typescript-eslint: + specifier: ^8.25.0 + version: 8.25.0(eslint@9.21.0(jiti@2.4.2))(typescript@5.7.3) docs/examples/record_api_ts: dependencies: