diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..8f7ba0a --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,38 @@ +module.exports = { + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/strict-type-checked", + ], + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], + parserOptions: { + tsconfigRootDir: __dirname, + project: ["./tsconfig.json", "./playground/tsconfig.json"], + }, + root: true, + ignorePatterns: ["*.js", "*.cjs", "*.mjs", "dist"], + reportUnusedDisableDirectives: true, + settings: { + next: { + rootDir: "playground", + }, + }, + rules: { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], + + "@typescript-eslint/no-non-null-assertion": "off", + + "@typescript-eslint/consistent-type-imports": "error", + "@typescript-eslint/consistent-type-exports": "error", + "@typescript-eslint/no-import-type-side-effects": "error", + + "no-console": ["warn", { allow: ["warn", "error", "table"] }], + }, +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 21cd354..9bf4d12 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.formatOnSave": true, - "eslint.experimental.useFlatConfig": true + "editor.formatOnSave": true } diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index fec12e8..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,70 +0,0 @@ -import process from "node:process" -import ts from "@typescript-eslint/eslint-plugin" -import tsParser from "@typescript-eslint/parser" -import eslintConfigPrettier from "eslint-config-prettier" -import eslintPluginUnicorn from "eslint-plugin-unicorn" - -export default [ - // don't lint js files - { - ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"], - }, - { - files: ["src/**/*.{ts,tsx}"], - languageOptions: { - parser: tsParser, - parserOptions: { - project: true, - tsconfigRootDir: process.cwd(), - }, - }, - linterOptions: { - reportUnusedDisableDirectives: true, - }, - plugins: { - "@typescript-eslint": ts, - }, - rules: { - ...ts.configs["eslint-recommended"].overrides[0].rules, - ...ts.configs["strict-type-checked"].rules, - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_", - }, - ], - - "@typescript-eslint/no-non-null-assertion": "off", - - "@typescript-eslint/consistent-type-imports": "error", - "@typescript-eslint/consistent-type-exports": "error", - "@typescript-eslint/no-import-type-side-effects": "error", - - "no-console": ["warn", { allow: ["warn", "error", "table"] }], - - "no-restricted-syntax": [ - "error", - { - selector: "TSEnumDeclaration", - message: "We should not use Enum", - }, - ], - }, - }, - { - ...eslintPluginUnicorn.configs["flat/recommended"], - rules: { - ...eslintPluginUnicorn.configs["flat/recommended"].rules, - "unicorn/prevent-abbreviations": "off", - // https://github.com/sindresorhus/meta/discussions/7 - "unicorn/no-null": "off", - // https://github.com/orgs/web-infra-dev/discussions/10 - "unicorn/prefer-top-level-await": "off", - "unicorn/catch-error-name": "off", - }, - }, - // disable formatting rules, make sure to put this last - eslintConfigPrettier, -] diff --git a/playground/src/app/[[...slug]]/page.tsx b/playground/src/app/[[...slug]]/page.tsx index 04af7e2..4b82c10 100644 --- a/playground/src/app/[[...slug]]/page.tsx +++ b/playground/src/app/[[...slug]]/page.tsx @@ -9,9 +9,11 @@ import { } from "@/components/ui/table" import { kv } from "@/lib/storage" import { cn } from "@/lib/utils" -import { getDependents, ParseResult } from "izon" +import { getDependents } from "izon" import { Suspense } from "react" +import type { ParseResult } from "izon" + const cachePrefix = "dependents-" function DependentTable({ @@ -90,7 +92,7 @@ async function DependentsRealtime({ const dependents = await getDependents(packageName, { resume: cached, }) - kv.setItem(`${cachePrefix}${packageName}`, dependents) + await kv.setItem(`${cachePrefix}${packageName}`, dependents) return ( { @@ -29,12 +30,130 @@ export async function queryRepositoryList( }, }, ) - .then((res) => res.json()) + .then((res) => res.json() as Promise) .then((res) => { - return res.items.map((item: any) => ({ + return res.items.map((item) => ({ name: item.full_name, avatarUrl: item.owner.avatar_url, })) }) return repositoryList } + +interface GitHubQueryResult { + total_count: number + incomplete_results: boolean + items: Item[] +} + +interface Item { + id: number + node_id: string + name: string + full_name: string + private: boolean + owner: Owner + html_url: string + description: string + fork: boolean + url: string + forks_url: string + keys_url: string + collaborators_url: string + teams_url: string + hooks_url: string + issue_events_url: string + events_url: string + assignees_url: string + branches_url: string + tags_url: string + blobs_url: string + git_tags_url: string + git_refs_url: string + trees_url: string + statuses_url: string + languages_url: string + stargazers_url: string + contributors_url: string + subscribers_url: string + subscription_url: string + commits_url: string + git_commits_url: string + comments_url: string + issue_comment_url: string + contents_url: string + compare_url: string + merges_url: string + archive_url: string + downloads_url: string + issues_url: string + pulls_url: string + milestones_url: string + notifications_url: string + labels_url: string + releases_url: string + deployments_url: string + created_at: string + updated_at: string + pushed_at: string + git_url: string + ssh_url: string + clone_url: string + svn_url: string + homepage: string + size: number + stargazers_count: number + watchers_count: number + language: string + has_issues: boolean + has_projects: boolean + has_downloads: boolean + has_wiki: boolean + has_pages: boolean + has_discussions: boolean + forks_count: number + mirror_url: unknown + archived: boolean + disabled: boolean + open_issues_count: number + license: License + allow_forking: boolean + is_template: boolean + web_commit_signoff_required: boolean + topics: string[] + visibility: string + forks: number + open_issues: number + watchers: number + default_branch: string + score: number +} + +interface Owner { + login: string + id: number + node_id: string + avatar_url: string + gravatar_id: string + url: string + html_url: string + followers_url: string + following_url: string + gists_url: string + starred_url: string + subscriptions_url: string + organizations_url: string + repos_url: string + events_url: string + received_events_url: string + type: string + site_admin: boolean +} + +interface License { + key: string + name: string + spdx_id: string + url: string + node_id: string +} diff --git a/playground/src/components/github-repository-selector.tsx b/playground/src/components/github-repository-selector.tsx index e49aed6..6127088 100644 --- a/playground/src/components/github-repository-selector.tsx +++ b/playground/src/components/github-repository-selector.tsx @@ -74,7 +74,7 @@ export function GitHubRepositorySelector() { > {currentRepository ? ( - ) : !!value ? ( + ) : value ? ( value ) : ( "Select GitHub repository" @@ -89,9 +89,9 @@ export function GitHubRepositorySelector() { value={search} onValueChange={setSearch} /> - {repositoryList && repositoryList?.length > 0 && ( + {repositoryList && repositoryList.length > 0 && ( - {repositoryList?.map((repo) => ( + {repositoryList.map((repo) => ( , React.ComponentPropsWithoutRef diff --git a/playground/src/lib/storage.ts b/playground/src/lib/storage.ts index 599fc71..7725130 100644 --- a/playground/src/lib/storage.ts +++ b/playground/src/lib/storage.ts @@ -3,6 +3,7 @@ import { createStorage } from "unstorage" import cloudflareKVHTTPDriver from "unstorage/drivers/cloudflare-kv-http" export const kv = createStorage({ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment driver: cloudflareKVHTTPDriver({ accountId: env.CF_ACCOUNT_ID, namespaceId: env.CF_NAMESPACE_ID,