From b254cf07887c17a3673862cf703e49a2ec758b31 Mon Sep 17 00:00:00 2001 From: Jonas Badalic Date: Fri, 21 Aug 2026 09:30:53 -0700 Subject: [PATCH] refactor: remove unused optional arguments and fields Generated with an experimental CLI that checks every call site of a function and flags optional arguments and object fields that are never provided. Previous defaults are inlined so runtime behavior is unchanged. Findings whose call sites live in Vue SFCs (invisible to the scanner) were verified manually and kept. Co-authored-by: Cursor --- app/composables/npm/useAlgoliaSearch.ts | 12 ++--- app/composables/useFacetSelection.ts | 6 +-- app/composables/useStructuredFilters.ts | 4 +- app/utils/compare-scatter-chart.ts | 4 +- cli/src/npm-client.ts | 3 +- cli/src/npm-process.ts | 10 ++-- server/api/auth/atproto.get.ts | 4 +- shared/utils/constellation.ts | 4 +- shared/utils/git-providers.ts | 70 ++++++++++--------------- shared/utils/repository-meta.ts | 3 +- 10 files changed, 45 insertions(+), 75 deletions(-) diff --git a/app/composables/npm/useAlgoliaSearch.ts b/app/composables/npm/useAlgoliaSearch.ts index b4a56fb79d..77a60e6b75 100644 --- a/app/composables/npm/useAlgoliaSearch.ts +++ b/app/composables/npm/useAlgoliaSearch.ts @@ -107,7 +107,6 @@ function hitToSearchResult(hit: AlgoliaHit): NpmSearchResult { interface AlgoliaSearchOptions { size?: number from?: number - filters?: string } /** Extra checks bundled into a single multi-search request. */ @@ -145,7 +144,7 @@ export function useAlgoliaSearch() { query, offset: options.from, length: options.size, - filters: options.filters || '', + filters: '', analyticsTags: ['npmx.dev'], attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE, attributesToHighlight: [], @@ -167,11 +166,8 @@ export function useAlgoliaSearch() { } /** Fetch all packages for a maintainer using `owners.name` filter with pagination. */ - async function searchByMaintainer( - ownerName: string, - options: { maxResults?: number } = {}, - ): Promise { - const max = options.maxResults ?? 1000 + async function searchByMaintainer(ownerName: string): Promise { + const max = 1000 const allHits: AlgoliaHit[] = [] let offset = 0 @@ -295,7 +291,7 @@ export function useAlgoliaSearch() { query, offset: options.from, length: options.size, - filters: options.filters || '', + filters: '', analyticsTags: ['npmx.dev'], attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE, attributesToHighlight: [], diff --git a/app/composables/useFacetSelection.ts b/app/composables/useFacetSelection.ts index 18b8b9b7f7..24555320c0 100644 --- a/app/composables/useFacetSelection.ts +++ b/app/composables/useFacetSelection.ts @@ -18,10 +18,8 @@ function getFacetsInCategory(category: string): ComparisonFacet[] { /** * Composable for managing comparison facet selection with URL sync. - * - * @param queryParam - The URL query parameter name to use (default: 'facets') */ -export function useFacetSelection(queryParam = 'facets') { +export function useFacetSelection() { const { t } = useI18n() const compactNumberFormatter = useCompactNumberFormatter() const bytesFormatter = useBytesFormatter() @@ -166,7 +164,7 @@ export function useFacetSelection(queryParam = 'facets') { } // Sync with URL query param (stable ref - doesn't change on other query changes) - const facetsParam = useRouteQuery(queryParam, '', { mode: 'replace' }) + const facetsParam = useRouteQuery('facets', '', { mode: 'replace' }) // Parse facet IDs from URL or use defaults const selectedFacetIds = computed({ diff --git a/app/composables/useStructuredFilters.ts b/app/composables/useStructuredFilters.ts index 9e01319eaf..396dea194b 100644 --- a/app/composables/useStructuredFilters.ts +++ b/app/composables/useStructuredFilters.ts @@ -127,7 +127,6 @@ export function removeKeywordFromQuery(query: string, keyword: string): string { interface UseStructuredFiltersOptions { packages: Ref searchQueryModel?: Ref - initialFilters?: Partial initialSort?: SortOption } @@ -153,7 +152,7 @@ function matchesSecurity(pkg: NpmSearchResult, security: SecurityFilter): boolea export function useStructuredFilters(options: UseStructuredFiltersOptions) { const route = useRoute() const router = useRouter() - const { packages, initialFilters, initialSort, searchQueryModel } = options + const { packages, initialSort, searchQueryModel } = options const { t } = useI18n() const searchQuery = shallowRef(normalizeSearchParam(route.query.q)) @@ -161,7 +160,6 @@ export function useStructuredFilters(options: UseStructuredFiltersOptions) { // Filter state - must be declared before the watcher that uses it const filters = ref({ ...DEFAULT_FILTERS, - ...initialFilters, }) // Watch route query changes and sync filter state diff --git a/app/utils/compare-scatter-chart.ts b/app/utils/compare-scatter-chart.ts index d78f53f115..9fab3069c8 100644 --- a/app/utils/compare-scatter-chart.ts +++ b/app/utils/compare-scatter-chart.ts @@ -8,7 +8,7 @@ function isFiniteNumber(value: unknown): value is number { return typeof value === 'number' && Number.isFinite(value) } -function toFreshnessScore(value: unknown, maximumAgeInDays = 365): number | null { +function toFreshnessScore(value: unknown): number | null { if (!value) { return null } @@ -21,7 +21,7 @@ function toFreshnessScore(value: unknown, maximumAgeInDays = 365): number | null const ageInMilliseconds = Date.now() - date.getTime() const ageInDays = ageInMilliseconds / MILLISECONDS_IN_A_DAY - const normalizedFreshness = 1 - ageInDays / maximumAgeInDays + const normalizedFreshness = 1 - ageInDays / 365 if (normalizedFreshness < 0) { return 0 diff --git a/cli/src/npm-client.ts b/cli/src/npm-client.ts index 4764c27e96..b53bd36e04 100644 --- a/cli/src/npm-client.ts +++ b/cli/src/npm-client.ts @@ -13,10 +13,9 @@ import { resolveNpmProcessCommand } from './npm-process.ts' const execFileAsync = promisify(execFile) export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/' -function createNpmEnv(overrides: Record = {}): Record { +function createNpmEnv(): Record { return { ...process.env, - ...overrides, FORCE_COLOR: '0', npm_config_registry: NPM_REGISTRY_URL, } diff --git a/cli/src/npm-process.ts b/cli/src/npm-process.ts index 44cb6ebfb8..dede898590 100644 --- a/cli/src/npm-process.ts +++ b/cli/src/npm-process.ts @@ -5,14 +5,10 @@ interface NpmProcessCommand { args: string[] } -export function resolveNpmProcessCommand( - npmArgs: string[], - platform = process.platform, - comSpec = process.env.ComSpec, -): NpmProcessCommand { - if (platform === 'win32') { +export function resolveNpmProcessCommand(npmArgs: string[]): NpmProcessCommand { + if (process.platform === 'win32') { return { - command: comSpec || 'cmd.exe', + command: process.env.ComSpec || 'cmd.exe', args: ['/d', '/s', '/c', 'npm', ...npmArgs], } } diff --git a/server/api/auth/atproto.get.ts b/server/api/auth/atproto.get.ts index 0b58fcc9a1..7eb221ba4b 100644 --- a/server/api/auth/atproto.get.ts +++ b/server/api/auth/atproto.get.ts @@ -167,8 +167,8 @@ function encodeOAuthState(event: H3Event, data: OAuthStateData): string { return JSON.stringify({ data, id }) } -function generateRandomHexString(byteLength: number = 16): string { - return Array.from(crypto.getRandomValues(new Uint8Array(byteLength)), byte => +function generateRandomHexString(): string { + return Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, '0'), ).join('') } diff --git a/shared/utils/constellation.ts b/shared/utils/constellation.ts index 91993f9fe9..5f7f410662 100644 --- a/shared/utils/constellation.ts +++ b/shared/utils/constellation.ts @@ -105,13 +105,11 @@ export class Constellation { /** * Gets all links from constellation and their counts * @param target - A uri encoded link. did, url, or at-uri - * @param ttl - The ttl to use for the cache */ - async getAllLinks(target: string, ttl: number | undefined = undefined) { + async getAllLinks(target: string) { return await this.cachedFetch( `https://${CONSTELLATION_HOST}/links/all?target=${target}`, { headers: HEADERS }, - ttl, ) } } diff --git a/shared/utils/git-providers.ts b/shared/utils/git-providers.ts index aa92dab98a..d68c9ea5f9 100644 --- a/shared/utils/git-providers.ts +++ b/shared/utils/git-providers.ts @@ -57,9 +57,9 @@ interface ProviderConfig { /** Parse URL path into owner/repo, returns null if invalid */ parsePath(parts: string[]): { owner: string; repo: string } | null /** Get raw file URL base for resolving relative paths */ - getRawBaseUrl(ref: RepoRef, branch?: string): string + getRawBaseUrl(ref: RepoRef): string /** Get blob/rendered URL base for markdown files */ - getBlobBaseUrl(ref: RepoRef, branch?: string): string + getBlobBaseUrl(ref: RepoRef): string /** Convert file URLs to blob URLs (for images) */ fileToRaw?(url: string): string /** Convert blob URLs to raw URLs (for images) */ @@ -79,10 +79,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => - `https://raw.githubusercontent.com/${ref.owner}/${ref.repo}/${branch}`, - getBlobBaseUrl: (ref, branch = 'HEAD') => - `https://github.com/${ref.owner}/${ref.repo}/blob/${branch}`, + getRawBaseUrl: ref => `https://raw.githubusercontent.com/${ref.owner}/${ref.repo}/HEAD`, + getBlobBaseUrl: ref => `https://github.com/${ref.owner}/${ref.repo}/blob/HEAD`, fileToRaw: url => url.replace('/tree/', '/raw/'), blobToRaw: url => url.replace('/blob/', '/raw/'), }, @@ -102,13 +100,13 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => { + getRawBaseUrl: ref => { const host = ref.host ?? 'gitlab.com' - return `https://${host}/${ref.owner}/${ref.repo}/-/raw/${branch}` + return `https://${host}/${ref.owner}/${ref.repo}/-/raw/HEAD` }, - getBlobBaseUrl: (ref, branch = 'HEAD') => { + getBlobBaseUrl: ref => { const host = ref.host ?? 'gitlab.com' - return `https://${host}/${ref.owner}/${ref.repo}/-/blob/${branch}` + return `https://${host}/${ref.owner}/${ref.repo}/-/blob/HEAD` }, blobToRaw: url => url.replace('/-/blob/', '/-/raw/'), }, @@ -124,10 +122,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => - `https://bitbucket.org/${ref.owner}/${ref.repo}/raw/${branch}`, - getBlobBaseUrl: (ref, branch = 'HEAD') => - `https://bitbucket.org/${ref.owner}/${ref.repo}/src/${branch}`, + getRawBaseUrl: ref => `https://bitbucket.org/${ref.owner}/${ref.repo}/raw/HEAD`, + getBlobBaseUrl: ref => `https://bitbucket.org/${ref.owner}/${ref.repo}/src/HEAD`, blobToRaw: url => url.replace('/src/', '/raw/'), }, { @@ -142,10 +138,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => - `https://codeberg.org/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}`, - getBlobBaseUrl: (ref, branch = 'HEAD') => - `https://codeberg.org/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}`, + getRawBaseUrl: ref => `https://codeberg.org/${ref.owner}/${ref.repo}/raw/branch/main`, + getBlobBaseUrl: ref => `https://codeberg.org/${ref.owner}/${ref.repo}/src/branch/main`, blobToRaw: url => url.replace('/src/', '/raw/'), }, { @@ -160,10 +154,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'master') => - `https://gitee.com/${ref.owner}/${ref.repo}/raw/${branch}`, - getBlobBaseUrl: (ref, branch = 'master') => - `https://gitee.com/${ref.owner}/${ref.repo}/blob/${branch}`, + getRawBaseUrl: ref => `https://gitee.com/${ref.owner}/${ref.repo}/raw/master`, + getBlobBaseUrl: ref => `https://gitee.com/${ref.owner}/${ref.repo}/blob/master`, blobToRaw: url => url.replace('/blob/', '/raw/'), }, { @@ -179,10 +171,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => - `https://git.sr.ht/${ref.owner}/${ref.repo}/blob/${branch}`, - getBlobBaseUrl: (ref, branch = 'HEAD') => - `https://git.sr.ht/${ref.owner}/${ref.repo}/tree/${branch}/item`, + getRawBaseUrl: ref => `https://git.sr.ht/${ref.owner}/${ref.repo}/blob/HEAD`, + getBlobBaseUrl: ref => `https://git.sr.ht/${ref.owner}/${ref.repo}/tree/HEAD/item`, }, { id: 'tangled', @@ -201,10 +191,8 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'main') => - `https://tangled.sh/${ref.owner}/${ref.repo}/raw/branch/${branch}`, - getBlobBaseUrl: (ref, branch = 'main') => - `https://tangled.sh/${ref.owner}/${ref.repo}/src/branch/${branch}`, + getRawBaseUrl: ref => `https://tangled.sh/${ref.owner}/${ref.repo}/raw/branch/main`, + getBlobBaseUrl: ref => `https://tangled.sh/${ref.owner}/${ref.repo}/src/branch/main`, blobToRaw: url => url.replace('/blob/', '/raw/branch/'), }, { @@ -220,10 +208,8 @@ const providers: ProviderConfig[] = [ // Use empty owner, store full rad: ID as repo return { owner: '', repo: radMatch[0] } }, - getRawBaseUrl: (ref, branch = 'HEAD') => - `https://seed.radicle.at/api/v1/projects/${ref.repo}/blob/${branch}`, - getBlobBaseUrl: (ref, branch = 'HEAD') => - `https://app.radicle.at/nodes/seed.radicle.at/${ref.repo}/tree/${branch}`, + getRawBaseUrl: ref => `https://seed.radicle.at/api/v1/projects/${ref.repo}/blob/HEAD`, + getBlobBaseUrl: ref => `https://app.radicle.at/nodes/seed.radicle.at/${ref.repo}/tree/HEAD`, }, { id: 'forgejo', @@ -237,13 +223,13 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => { + getRawBaseUrl: ref => { const host = ref.host ?? 'codeberg.org' - return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}` + return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/main` }, - getBlobBaseUrl: (ref, branch = 'HEAD') => { + getBlobBaseUrl: ref => { const host = ref.host ?? 'codeberg.org' - return `https://${host}/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}` + return `https://${host}/${ref.owner}/${ref.repo}/src/branch/main` }, blobToRaw: url => url.replace('/src/', '/raw/'), }, @@ -259,13 +245,13 @@ const providers: ProviderConfig[] = [ if (!owner || !repo) return null return { owner, repo } }, - getRawBaseUrl: (ref, branch = 'HEAD') => { + getRawBaseUrl: ref => { const host = ref.host ?? 'gitea.io' - return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}` + return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/main` }, - getBlobBaseUrl: (ref, branch = 'HEAD') => { + getBlobBaseUrl: ref => { const host = ref.host ?? 'gitea.io' - return `https://${host}/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}` + return `https://${host}/${ref.owner}/${ref.repo}/src/branch/main` }, blobToRaw: url => url.replace('/src/', '/raw/'), }, diff --git a/shared/utils/repository-meta.ts b/shared/utils/repository-meta.ts index 8bcf191e13..d1ff289315 100644 --- a/shared/utils/repository-meta.ts +++ b/shared/utils/repository-meta.ts @@ -521,8 +521,7 @@ export async function getRepoMeta( export async function getRepositoryStars( cachedFetch: CachedFetchFunction, ref: RepoRef, - options: Parameters[1] = {}, ): Promise { - const meta = await getRepoMeta(cachedFetch, ref, options) + const meta = await getRepoMeta(cachedFetch, ref) return meta?.stars ?? null }