Skip to content

fix(linter): Fix JSON schema to deny additional properties for plugins enum.#15259

Merged
camc314 merged 1 commit intomainfrom
fix-plugins-type
Nov 4, 2025
Merged

fix(linter): Fix JSON schema to deny additional properties for plugins enum.#15259
camc314 merged 1 commit intomainfrom
fix-plugins-type

Conversation

@connorshea
Copy link
Member

@connorshea connorshea commented Nov 4, 2025

This ensures that VS Code and other editors will not accept unknown values for the plugins field.

I believe string was allowed initially because of the way jsPlugins were going to be implemented (see #12117), but then the jsPlugins plans changed to use a separate config field? I'm not 100% sure, but that appears to be the case. Anyway, the schema was never updated after that pivot, and so this fixes the problem. We could probably remove the any_of to simplify things, but eh I just want to fix this for now.

With this change, jsPlugins still allows arbitrary values, while plugins only allows known values:

Screenshot 2025-11-03 at 11 16 41 PM

In the future, it'd probably be good to add tests to do basic schema validation (e.g. here are 10 JSON blobs that should pass, here are 10 JSON blobs that should fail) so we can ensure regressions don't occur for this kind of developer experience nice-to-have.

Part of #15247.

…s enum.

This ensures that VS Code and other editors will not accept unknown values for the plugins field.

I believe `string` was allowed initially because of the way jsPlugins were going to be implemented, but then the jsPlugins plans changed to use a separate config field? I'm not 100% sure, but that appears to be the case. Anyway, the schema was never updated after that pivot, and so this fixes the problem. We could probably remove the `any_of` to simplify things, but eh I just want to fix this for now.
@connorshea connorshea requested a review from camc314 as a code owner November 4, 2025 06:17
Copilot AI review requested due to automatic review settings November 4, 2025 06:17
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 4, 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.

@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Nov 4, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the JSON schema for lint plugin options by removing the arbitrary string type, restricting plugin specifications to only predefined enum values.

  • Removes the "type": "string" option from the plugin schema's anyOf array
  • Restricts plugin names to the enumerated values defined in LintPluginOptionsSchema
  • Updates both the generated schema JSON file and the snapshot test

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
npm/oxlint/configuration_schema.json Removes string type from plugin options schema
crates/oxc_linter/src/snapshots/schema_json.snap Updates snapshot to reflect schema change
crates/oxc_linter/src/config/plugins.rs Removes code that generated string schema option
Comments suppressed due to low confidence (2)

crates/oxc_linter/src/config/plugins.rs:258

  • The anyOf subschema validation with a single item is unnecessary. When there's only one schema option, it should be used directly as the item_schema instead of wrapping it in an anyOf array. Replace lines 252-258 with let item_schema = enum_schema; to simplify the code.
        let item_schema = Schema::Object(schemars::schema::SchemaObject {
            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
                any_of: Some(vec![enum_schema]),
                ..Default::default()
            })),
            ..Default::default()
        });

crates/oxc_linter/src/config/plugins.rs:248

  • The schema enum only accepts the kebab-case canonical names for each plugin (e.g., 'typescript'), but the deserialization logic in LintPlugins::try_from (lines 130-154) accepts multiple aliases for plugins. For example, 'typescript-eslint', 'typescript_eslint', and '@typescript-eslint' are all valid for the TypeScript plugin, but the schema will reject them. This creates a mismatch between what the schema allows and what the code accepts, potentially breaking existing configurations that use these valid aliases. Consider either: (1) keeping the string type in the schema to allow validation at runtime, or (2) documenting that only canonical names are supported and updating error messages to suggest the canonical form.
        enum LintPluginOptionsSchema {
            Eslint,
            React,
            Unicorn,
            Typescript,
            Oxc,
            Import,
            Jsdoc,
            Jest,
            Vitest,
            JsxA11y,
            Nextjs,
            ReactPerf,
            Promise,
            Node,
            Regex,
            Vue,
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 4, 2025

CodSpeed Performance Report

Merging #15259 will not alter performance

Comparing fix-plugins-type (e88f0e9) with main (7a5c011)

Summary

✅ 4 untouched
⏩ 33 skipped1

Footnotes

  1. 33 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 merged commit 9304f9f into main Nov 4, 2025
30 checks passed
@camc314 camc314 deleted the fix-plugins-type branch November 4, 2025 11:52
@Boshen Boshen mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants