Skip to content

feat(cli): migrate JSON config to JS/TS when running --init#566

Merged
fansenze merged 1 commit intomainfrom
feat/init-migrate-json-20260324
Mar 24, 2026
Merged

feat(cli): migrate JSON config to JS/TS when running --init#566
fansenze merged 1 commit intomainfrom
feat/init-migrate-json-20260324

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 24, 2026

Summary

When users have a deprecated rslint.json and run rslint --init as suggested by the deprecation warning, it now automatically migrates the JSON config to JS/TS format instead of erroring with "config file already exists".

  • JS/TS config already exists → error (unchanged behavior)
  • Only JSON config exists → migrate to JS/TS, deduplicate rules against recommended presets, delete old JSON
  • No config exists → create default JS/TS config (unchanged behavior)

Key behaviors:

  • Deduplicates rules that match js/ts/react/import recommended presets (same severity → stripped)
  • Preserves user overrides (different severity, array-form rules, rules not in presets)
  • Handles multi-entry array configs, global ignore entries, languageOptions, settings
  • Chooses output format based on project: .ts (tsconfig exists), .js (ESM), .mjs (CJS)
  • Supports JSONC (comments, trailing commas)

Related Links

Closes #565

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the rslint --init command, enabling it to intelligently migrate existing JSON-based configuration files to the more flexible JavaScript/TypeScript format. This change improves the developer experience by automating a previously manual and error-prone upgrade path, ensuring that users can seamlessly transition to the recommended configuration style while preserving their custom linting rules and settings.

Highlights

  • Automatic JSON to JS/TS Config Migration: Implemented automatic migration of deprecated rslint.json or rslint.jsonc configuration files to the modern JS/TS format when rslint --init is executed, preventing errors and streamlining the upgrade process.
  • Intelligent Rule Deduplication: Added logic to deduplicate rules against recommended presets (JavaScript, TypeScript, React, and Import) during migration, ensuring that only user-specific overrides or non-preset rules are explicitly included in the new configuration.
  • Preservation of Custom Configurations: Ensured that user-defined rule severities, array-form rules, languageOptions, settings, and global ignore entries are correctly preserved and translated into the new JS/TS configuration format.
  • Dynamic Output Format Selection: Introduced logic to determine the appropriate output file extension (.ts, .js, or .mjs) for the new configuration based on the project's existing tsconfig.json or package.json 'type' field.
  • Refactored Configuration Initialization: Moved and expanded configuration initialization and migration logic into a new dedicated file, internal/config/config_init.go, improving modularity and maintainability.
  • Comprehensive Test Coverage: Significantly expanded the test suite with numerous new tests covering various migration scenarios, rule deduplication, and edge cases to ensure robustness and correctness of the new functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the InitDefaultConfig logic into a new config_init.go file, introducing a comprehensive system to migrate old JSON/JSONC configuration files to new JS/TS formats. This system intelligently generates default configurations based on project type and deduplicates rules against recommended presets for various plugins. However, the current implementation for formatting complex rule values in the generated config files is not robust and could produce invalid JavaScript, requiring a more reliable escaping mechanism. Additionally, the hardcoded recommended rule maps pose a maintenance burden and risk becoming outdated, suggesting an automated generation process for these maps to ensure consistency and prevent incorrect rule deduplication.

@fansenze fansenze force-pushed the feat/init-migrate-json-20260324 branch 2 times, most recently from 1dbd709 to 57c4df5 Compare March 24, 2026 03:22
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 24, 2026

Deploying rslint with  Cloudflare Pages  Cloudflare Pages

Latest commit: 80d19cd
Status: ✅  Deploy successful!
Preview URL: https://152b6a2c.rslint.pages.dev
Branch Preview URL: https://feat-init-migrate-json-20260.rslint.pages.dev

View logs

@fansenze fansenze force-pushed the feat/init-migrate-json-20260324 branch 2 times, most recently from 3925773 to 42e0a17 Compare March 24, 2026 03:51
When `rslint --init` detects an existing `rslint.json`/`rslint.jsonc`
(but no JS/TS config), it now automatically migrates the JSON config
to the equivalent JS/TS format instead of erroring out.

The migration deduplicates rules that match recommended presets,
preserves user overrides, and deletes the old JSON file.

Closes #565
@fansenze fansenze force-pushed the feat/init-migrate-json-20260324 branch from 42e0a17 to 80d19cd Compare March 24, 2026 04:25
@fansenze fansenze merged commit 7c585de into main Mar 24, 2026
15 checks passed
@fansenze fansenze deleted the feat/init-migrate-json-20260324 branch March 24, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: migrating from rslint.json to ts based config

3 participants