Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 14, 2025

Implements support for rule configuration objects in tsgolint headless mode as requested in oxc-project/tsgolint#51.

Problem

The current tsgolint headless mode only supports passing rule names as an array:

{
  "files": [
    {
      "file_path": "/absolute/path/to/file.ts",
      "rules": ["no-floating-promises", "no-unsafe-call"]
    }
  ]
}

This prevents users from configuring rules on a per-file basis, which is essential for complex projects with varying rule requirements across different files.

Solution

Added support for rule configuration objects while maintaining full backward compatibility:

{
  "files": [
    {
      "file_path": "/absolute/path/to/file.ts",
      "rules": {
        "no-floating-promises": {
          "ignoreVoid": true,
          "ignoreIIFE": true
        },
        "no-misused-promises": {
          "checksVoidReturn": false,
          "checksConditionals": true
        }
      }
    }
  ]
}

Implementation Details

  • Dual Format Support: Introduced TsGoLintRules enum supporting both Array(Vec<String>) and Object(Map<String, Value>) formats
  • Custom Serialization: Implemented custom serde serialization/deserialization for seamless JSON handling
  • Backward Compatibility: Uses array format by default to maintain compatibility with existing tsgolint binaries
  • Environment Variable Control: Enable object format with OXLINT_TSGOLINT_OBJECT_FORMAT=1 for testing
  • Infrastructure Ready: Foundation in place to extract actual rule configurations from RuleEnum instances

Testing

Added comprehensive test suite covering:

  • JSON serialization and deserialization for both formats
  • Backward compatibility parsing of legacy array format
  • Object format with actual rule configurations
  • Round-trip serialization/parsing verification
# Test current functionality (array format)
cargo test --package oxlint test_tsgolint

# Test new object format
OXLINT_TSGOLINT_OBJECT_FORMAT=1 cargo test --package oxlint test_json_serialization_formats -- --nocapture

Future Work

This implementation provides the foundation for rule configuration support. Next steps include:

  1. Extract actual rule configurations from RuleEnum instances
  2. Enable object format by default once tsgolint supports it
  3. Add API for programmatic rule configuration

The changes are minimal and surgical, maintaining full backward compatibility while enabling the requested functionality.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor

graphite-app bot commented Aug 14, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@Copilot Copilot AI changed the title [WIP] https://github.com/oxc-project/tsgolint/issues/51 feat: Add rule configuration object support for tsgolint headless mode Aug 14, 2025
@Copilot Copilot AI requested a review from camc314 August 14, 2025 20:25
Copilot finished work on behalf of camc314 August 14, 2025 20:25
@Boshen Boshen closed this Sep 26, 2025
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.

3 participants