From 44091ec85feb60d6609f62fe4c8701c890bb4847 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 17 Nov 2026 14:13:58 +0100 Subject: [PATCH] chore: fix the oxlint violations in src --- oxlint-suppressions.json | 95 ------------------- src/cache-utils.ts | 1 + src/changelog-check.mts | 4 +- src/error-utils.ts | 2 +- src/fs-utils.ts | 2 +- src/get-review-metrics.ts | 7 +- src/github/octokit.ts | 1 + .../cli.ts | 2 +- .../analytics-model.ts | 2 +- src/segment-schema-draft-pr/apply-changes.ts | 9 +- src/segment-schema-draft-pr/cli.ts | 3 +- src/segment-schema-draft-pr/diff-models.ts | 7 +- src/segment-schema-draft-pr/generate.test.ts | 4 +- src/segment-schema-draft-pr/publish.test.ts | 6 +- src/segment-schema-draft-pr/schema-index.ts | 4 +- vitest.config.mts | 2 +- 16 files changed, 34 insertions(+), 117 deletions(-) diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index 61224d9f..9ccb7e4c 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -329,91 +329,9 @@ "count": 1 } }, - "src/cache-utils.ts": { - "jsdoc/require-returns": { - "count": 1 - } - }, - "src/changelog-check.mts": { - "typescript/explicit-function-return-type": { - "count": 1 - }, - "typescript/no-unsafe-argument": { - "count": 1 - }, - "typescript/no-unsafe-member-access": { - "count": 1 - } - }, - "src/error-utils.ts": { - "typescript/explicit-function-return-type": { - "count": 1 - } - }, - "src/fs-utils.ts": { - "typescript/no-unsafe-return": { - "count": 1 - } - }, "src/get-review-metrics.ts": { - "jsdoc/require-returns": { - "count": 1 - }, - "typescript/explicit-function-return-type": { - "count": 1 - }, "typescript/no-unnecessary-type-assertion": { "count": 1 - }, - "typescript/no-unsafe-argument": { - "count": 1 - }, - "typescript/no-unsafe-assignment": { - "count": 1 - }, - "typescript/no-unsafe-member-access": { - "count": 1 - } - }, - "src/github/octokit.ts": { - "jsdoc/require-returns": { - "count": 1 - } - }, - "src/scripts/count-references-to-contributor-docs/cli.ts": { - "typescript/explicit-function-return-type": { - "count": 1 - } - }, - "src/segment-schema-draft-pr/analytics-model.ts": { - "unicorn/no-useless-undefined": { - "count": 1 - } - }, - "src/segment-schema-draft-pr/apply-changes.ts": { - "import/consistent-type-specifier-style": { - "count": 1 - }, - "typescript/explicit-function-return-type": { - "count": 1 - }, - "typescript/no-unnecessary-type-assertion": { - "count": 2 - } - }, - "src/segment-schema-draft-pr/cli.ts": { - "import/consistent-type-specifier-style": { - "count": 1 - } - }, - "src/segment-schema-draft-pr/diff-models.ts": { - "typescript/no-unsafe-assignment": { - "count": 6 - } - }, - "src/segment-schema-draft-pr/generate.test.ts": { - "typescript/return-await": { - "count": 2 } }, "src/segment-schema-draft-pr/github-output.ts": { @@ -421,19 +339,6 @@ "count": 1 } }, - "src/segment-schema-draft-pr/publish.test.ts": { - "import/consistent-type-specifier-style": { - "count": 1 - }, - "typescript/no-unsafe-member-access": { - "count": 1 - } - }, - "src/segment-schema-draft-pr/schema-index.ts": { - "typescript/no-unnecessary-type-assertion": { - "count": 2 - } - }, "yarn.config.cjs": { "import/unambiguous": { "count": 1 diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 5e0e47d4..bfa4bca1 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -28,6 +28,7 @@ const DEFAULT_MAX_AGE = 60 * 60 * 1000; // 1 hour * considered "fresh". Affects subsequent calls: if `fetchOrPopulateFileCache` * is called again with the same file path within the duration specified here, * `getDataToCache` will not get called again, otherwise it will. + * @returns The cached data if it is fresh, otherwise the newly generated data. */ export async function fetchOrPopulateFileCache({ filePath, diff --git a/src/changelog-check.mts b/src/changelog-check.mts index cfd0ae06..1083b899 100644 --- a/src/changelog-check.mts +++ b/src/changelog-check.mts @@ -529,7 +529,7 @@ async function getChangedPackages( /** * Main function to run the changelog check. */ -async function main() { +async function main(): Promise { // Parse command-line arguments const args = process.argv.slice(2); @@ -623,7 +623,7 @@ async function main() { } } -main().catch((error) => { +main().catch((error: { message: string }) => { logError(error.message); // eslint-disable-next-line n/no-process-exit process.exit(1); diff --git a/src/error-utils.ts b/src/error-utils.ts index 8ff21a9b..af5348ee 100644 --- a/src/error-utils.ts +++ b/src/error-utils.ts @@ -41,7 +41,7 @@ export function isErrorWithCode(error: unknown): error is { code: string } { * something throwable). * @returns A new error object. */ -export function wrapError(message: string, originalError: unknown) { +export function wrapError(message: string, originalError: unknown): Error { if (isError(originalError)) { const error: Error & { code?: string } = new Error(message, { cause: originalError, diff --git a/src/fs-utils.ts b/src/fs-utils.ts index 9246327c..ce30e826 100644 --- a/src/fs-utils.ts +++ b/src/fs-utils.ts @@ -54,7 +54,7 @@ export async function readJsonFile( ): Promise { try { const content = await readFile(filePath); - return JSON.parse(content); + return JSON.parse(content) as Value; } catch (error) { throw wrapError(`Could not read JSON file '${filePath}'`, error); } diff --git a/src/get-review-metrics.ts b/src/get-review-metrics.ts index a9e9fa94..12ae91c3 100644 --- a/src/get-review-metrics.ts +++ b/src/get-review-metrics.ts @@ -33,8 +33,9 @@ const pullRequests: { * Get all review comments for the repository specified. * * @param page - The page number of results to fetch. + * @returns Whether the last page of results has been reached. */ -async function getAllComments(page = 1) { +async function getAllComments(page = 1): Promise { const { data } = await octokit.rest.pulls.listReviewCommentsForRepo({ owner: 'MetaMask', repo: 'metamask-extension', @@ -75,7 +76,9 @@ async function execute(): Promise { }); const pulls = Object.keys(pullRequests); for (const pull of pulls) { - const { data } = await octokit.request(pull); + const { data } = (await octokit.request(pull)) as { + data: { user: { login: string } }; + }; if (TEAM.includes(data.user.login) && pullRequests[pull]) { (pullRequests[pull] as PullRequestData).isInternal = true; } diff --git a/src/github/octokit.ts b/src/github/octokit.ts index 4748454d..6fab9110 100644 --- a/src/github/octokit.ts +++ b/src/github/octokit.ts @@ -9,6 +9,7 @@ import { getRequiredEnvironmentVariable } from '../env-utils'; * * @param args - The same arguments that * [`graphql`](https://github.com/octokit/graphql.js) takes. + * @returns The response data of the GraphQL request. */ export async function graphql( ...args: Parameters diff --git a/src/scripts/count-references-to-contributor-docs/cli.ts b/src/scripts/count-references-to-contributor-docs/cli.ts index 4cd56452..f02d224d 100644 --- a/src/scripts/count-references-to-contributor-docs/cli.ts +++ b/src/scripts/count-references-to-contributor-docs/cli.ts @@ -30,7 +30,7 @@ main().catch(console.error); * This script counts the number of references to the `contributor-docs` repo * across a selection of MetaMask repositories. */ -async function main() { +async function main(): Promise { const spinner = ora(); console.log( diff --git a/src/segment-schema-draft-pr/analytics-model.ts b/src/segment-schema-draft-pr/analytics-model.ts index a46e02fe..2d31fb25 100644 --- a/src/segment-schema-draft-pr/analytics-model.ts +++ b/src/segment-schema-draft-pr/analytics-model.ts @@ -25,7 +25,7 @@ export function extractAnalyticsModel( filePath: string, sourceText: string, config: PlatformConfig, - sharedCatalog: EventCatalog | undefined = undefined, + sharedCatalog?: EventCatalog | undefined, ): AnalyticsModel { const sourceFile = ts.createSourceFile( filePath, diff --git a/src/segment-schema-draft-pr/apply-changes.ts b/src/segment-schema-draft-pr/apply-changes.ts index dca253c2..60978c8b 100644 --- a/src/segment-schema-draft-pr/apply-changes.ts +++ b/src/segment-schema-draft-pr/apply-changes.ts @@ -5,7 +5,8 @@ import type { Document as YamlDocument } from 'yaml'; import { TODO_DESCRIPTION } from './constants'; import { uniqueKebabSlug } from './names'; -import { defaultPropKeys, type SchemaIndex } from './schema-index'; +import { defaultPropKeys } from './schema-index'; +import type { SchemaIndex } from './schema-index'; import type { AnalyticsChangeSet, IntendedFileChange, @@ -126,7 +127,7 @@ function newEventNames( const names: string[] = []; const seen = new Set(); - const consider = (eventName: string) => { + const consider = (eventName: string): void => { if (seen.has(eventName) || index.eventsByName.has(eventName)) { return; } @@ -454,7 +455,7 @@ function yamlKey(value: unknown): string | undefined { return value; } if (value && typeof value === 'object' && 'value' in value) { - const inner = (value as { value: unknown }).value; + const inner = value.value; if (typeof inner === 'string') { return inner; } @@ -476,7 +477,7 @@ function isYamlMap(value: unknown): value is { typeof value === 'object' && value !== null && 'items' in value && - Array.isArray((value as { items: unknown }).items) + Array.isArray(value.items) ); } diff --git a/src/segment-schema-draft-pr/cli.ts b/src/segment-schema-draft-pr/cli.ts index 6be73bc7..8f2ba332 100644 --- a/src/segment-schema-draft-pr/cli.ts +++ b/src/segment-schema-draft-pr/cli.ts @@ -3,7 +3,8 @@ import { botBranchName } from './config'; import { generateSchemaDraft, writeSummaryFile } from './generate'; import { createOctokitClients, parseRepo } from './github-api'; import { writeGithubOutput } from './github-output'; -import { parseCliArgs, type CliArgs } from './parse-args'; +import { parseCliArgs } from './parse-args'; +import type { CliArgs } from './parse-args'; import { runPublish } from './publish'; main().catch((error: unknown) => { diff --git a/src/segment-schema-draft-pr/diff-models.ts b/src/segment-schema-draft-pr/diff-models.ts index 1e164728..88a701a0 100644 --- a/src/segment-schema-draft-pr/diff-models.ts +++ b/src/segment-schema-draft-pr/diff-models.ts @@ -3,6 +3,7 @@ import type { AnalyticsModel, EventChange, PropertyChange, + PropertyType, RemovedProperty, RenameChange, UnresolvedProperty, @@ -54,8 +55,10 @@ export function diffModels( continue; } - const baseProps = base.events.get(eventName)?.properties ?? new Map(); - const headProps = head.events.get(eventName)?.properties ?? new Map(); + const baseProps = + base.events.get(eventName)?.properties ?? new Map(); + const headProps = + head.events.get(eventName)?.properties ?? new Map(); for (const [key, type] of headProps) { const previous = baseProps.get(key); diff --git a/src/segment-schema-draft-pr/generate.test.ts b/src/segment-schema-draft-pr/generate.test.ts index b0fc2bcf..e7370705 100644 --- a/src/segment-schema-draft-pr/generate.test.ts +++ b/src/segment-schema-draft-pr/generate.test.ts @@ -70,9 +70,9 @@ function mockClientOctokit( new Error('Not Found'), { status: 404 }, ); - return Promise.reject(error); + return await Promise.reject(error); } - return Promise.resolve(encodedFile(text)); + return await Promise.resolve(encodedFile(text)); }, ); diff --git a/src/segment-schema-draft-pr/publish.test.ts b/src/segment-schema-draft-pr/publish.test.ts index eaabf195..fe2ee6eb 100644 --- a/src/segment-schema-draft-pr/publish.test.ts +++ b/src/segment-schema-draft-pr/publish.test.ts @@ -1,5 +1,6 @@ import type { Octokit } from '@octokit/rest'; -import { describe, expect, it, vi, type Mock } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; +import type { Mock } from 'vitest'; import { PROPOSAL_MARKER } from './constants'; import type { CliArgs } from './parse-args'; @@ -153,7 +154,8 @@ describe('publishGenerateResult', () => { body: expect.stringContaining(PROPOSAL_MARKER), }), ); - expect(updateComment.mock.calls[0]?.[0].body).toContain( + const [updateArgs] = updateComment.mock.calls[0] as [{ body: string }]; + expect(updateArgs.body).toContain( 'https://github.com/Consensys/segment-schema/pull/9', ); expect(createComment).not.toHaveBeenCalled(); diff --git a/src/segment-schema-draft-pr/schema-index.ts b/src/segment-schema-draft-pr/schema-index.ts index f4fd0677..71bd1eea 100644 --- a/src/segment-schema-draft-pr/schema-index.ts +++ b/src/segment-schema-draft-pr/schema-index.ts @@ -183,7 +183,7 @@ function isYamlMap(value: unknown): value is { typeof value === 'object' && value !== null && 'items' in value && - Array.isArray((value as { items: unknown }).items) + Array.isArray(value.items) ); } @@ -198,7 +198,7 @@ function asString(value: unknown): string | undefined { return value; } if (value && typeof value === 'object' && 'value' in value) { - const inner = (value as { value: unknown }).value; + const inner = value.value; if (typeof inner === 'string') { return inner; } diff --git a/vitest.config.mts b/vitest.config.mts index 33b3ca06..e4f04224 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -49,7 +49,7 @@ export default defineConfig({ thresholds: { // Raises the thresholds in this file when coverage improves. autoUpdate: true, - branches: 41.72, + branches: 41.69, functions: 50.63, lines: 41.61, statements: 41.5,