Skip to content

feat(lint): require validation before casting parsed JSON - #169

Draft
jcosta33 wants to merge 1 commit into
codex/no-positional-boolean-flagsfrom
codex/no-unchecked-json-cast
Draft

jcosta33 wants to merge 1 commit into
codex/no-positional-boolean-flagsfrom
codex/no-unchecked-json-cast

Conversation

@jcosta33

@jcosta33 jcosta33 commented Dec 2, 2026 •

Copy link
Copy Markdown

Report casts on JSON.parse() and known web response .json() calls as errors in both base configs. A type assertion can hide unexpected data. Validate the decoded value at the boundary so downstream code can use a checked type.

Examples

Before

type Settings = { label: string };

export function parseSettings(text: string): Settings {
    return JSON.parse(text) as Settings;
}

export async function readSettings(response: Response): Promise<Settings> {
    return (await response.json()) as Settings;
}

Corrected

import { z } from 'zod';

const settingsSchema = z.object({ label: z.string() });
type Settings = z.infer<typeof settingsSchema>;

export function parseSettings(text: string): Settings {
    const raw: unknown = JSON.parse(text);

    return settingsSchema.parse(raw);
}

export async function readSettings(response: Response): Promise<Settings> {
    const raw: unknown = await response.json();

    return settingsSchema.parse(raw);
}

Parent #168

@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ba308b3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@frontify/eslint-config-basic Minor
@frontify/eslint-config-react Minor
@frontify/eslint-plugin Patch
@frontify/oxlint-config-basic Minor
@frontify/oxlint-config-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant