Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace JSON.parse with parseJsonWithSchema (@dev-mohit06) #6207

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dev-mohit06
Copy link

@dev-mohit06 dev-mohit06 commented Jan 23, 2025

Description

Replaces raw JSON parsing with schema-based validation across frontend TypeScript files to improve type safety and error handling.

Scope of Changes

  • Updated JSON parsing in:

    • account.ts
    • import-export-settings.ts
    • analytics-controller.ts
    • local-storage-with-schema.ts
    • url-handler.ts
    • commandline/lists.ts
    • test/wikipedia.ts
  • Added schema in test/custom-text.ts:

    export const customTextDataSchema = z.object({
      text: z.array(z.string()),
      mode: CustomTextModeSchema,
      limit: z.object({ 
        value: z.number(), 
        mode: CustomTextLimitModeSchema 
      }),
      pipeDelimiter: z.boolean(),
    });

Benefits

  • Enhanced runtime type safety
  • More robust error handling
  • Consistent JSON parsing approach

Checks

  • Follows Conventional Commits
  • Includes GitHub username
  • Adding quotes? (N/A)
  • Adding language/theme? (N/A)

@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Jan 23, 2025
Copy link
Member

@fehmer fehmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dev-mohit06, nice work. I added some comments for you.

@github-actions github-actions bot added the waiting for update Pull requests or issues that require changes/comments before continuing label Jan 23, 2025
@github-actions github-actions bot removed the waiting for update Pull requests or issues that require changes/comments before continuing label Jan 23, 2025
…WithSchema (@dev-mohit06)

- Updated schema definitions for better clarity and reusability.
- Replaced  with  where applicable.
- Addressed all review comments for better code consistency.
@dev-mohit06
Copy link
Author

Hey @fehmer, could you take a look at the changes?

frontend/src/ts/controllers/analytics-controller.ts Outdated Show resolved Hide resolved
frontend/src/ts/controllers/analytics-controller.ts Outdated Show resolved Hide resolved
frontend/src/ts/event-handlers/account.ts Outdated Show resolved Hide resolved
frontend/src/ts/test/wikipedia.ts Outdated Show resolved Hide resolved
frontend/src/ts/utils/url-handler.ts Show resolved Hide resolved
frontend/src/ts/utils/url-handler.ts Show resolved Hide resolved
frontend/src/ts/utils/url-handler.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot added waiting for update Pull requests or issues that require changes/comments before continuing and removed waiting for update Pull requests or issues that require changes/comments before continuing labels Jan 24, 2025
@dev-mohit06
Copy link
Author

Hey @fehmer, could you take a look at the changes?

@dev-mohit06 dev-mohit06 requested a review from fehmer January 24, 2025 12:33
@github-actions github-actions bot added the waiting for review Pull requests that require a review before continuing label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend User interface or web stuff waiting for review Pull requests that require a review before continuing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants