diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 0180fca8d896b..3fda7f957bcca 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -1,5 +1,6 @@ mod env; mod globals; +mod parser_options; mod rules; mod settings; @@ -13,7 +14,7 @@ use serde::Deserialize; use crate::{rules::RuleEnum, AllowWarnDeny, RuleWithSeverity}; pub use self::{ - env::OxlintEnv, globals::OxlintGlobals, rules::OxlintRules, + env::OxlintEnv, globals::OxlintGlobals, parser_options::OxlintParseOptions, rules::OxlintRules, settings::jsdoc::JSDocPluginSettings, settings::OxlintSettings, }; @@ -56,6 +57,9 @@ pub struct OxlintConfig { pub(crate) settings: OxlintSettings, pub(crate) env: OxlintEnv, pub(crate) globals: OxlintGlobals, + + #[serde(rename = "parserOptions")] + pub(crate) parser_options: OxlintParseOptions, } impl OxlintConfig { @@ -208,14 +212,20 @@ mod test { }, }, "env": { "browser": true, }, - "globals": { "foo": "readonly", } + "globals": { "foo": "readonly", }, + "parserOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true + } })); assert!(config.is_ok()); - let OxlintConfig { rules, settings, env, globals } = config.unwrap(); + let OxlintConfig { rules, settings, env, globals, parser_options } = config.unwrap(); assert!(!rules.is_empty()); assert_eq!(settings.jsx_a11y.polymorphic_prop_name, Some("role".to_string())); assert_eq!(env.iter().count(), 1); assert!(globals.is_enabled("foo")); + assert!(parser_options.emit_decorator_metadata); + assert!(parser_options.experimental_decorators); } } diff --git a/crates/oxc_linter/src/config/parser_options.rs b/crates/oxc_linter/src/config/parser_options.rs new file mode 100644 index 0000000000000..99e913cc70095 --- /dev/null +++ b/crates/oxc_linter/src/config/parser_options.rs @@ -0,0 +1,49 @@ +use schemars::JsonSchema; +use serde::Deserialize; + +// +#[derive(Debug, Default, Clone, Deserialize, JsonSchema)] +#[serde(default)] +pub struct OxlintParseOptions { + /// This option allow you to tell parser to act as if `emitDecoratorMetadata: true` is set in `tsconfig.json`. + #[serde(rename = "emitDecoratorMetadata")] + pub emit_decorator_metadata: bool, + + /// This option allow you to tell parser to act as if `experimentalDecorators: true` is set in `tsconfig.json`. + #[serde(rename = "experimentalDecorators")] + pub experimental_decorators: bool, +} + +#[cfg(test)] +mod test { + use super::OxlintParseOptions; + use serde::Deserialize; + + #[test] + fn test_parse_options() { + let options = OxlintParseOptions::deserialize(&serde_json::json!({ + "emitDecoratorMetadata": true, + "experimentalDecorators": true + })) + .unwrap(); + assert!(options.emit_decorator_metadata); + assert!(options.experimental_decorators); + } + + #[test] + fn test_parse_options_default() { + let options = OxlintParseOptions::default(); + assert!(!options.emit_decorator_metadata); + assert!(!options.experimental_decorators); + } + + #[test] + fn test_one_lack_field() { + let options = OxlintParseOptions::deserialize(&serde_json::json!({ + "emitDecoratorMetadata": true + })) + .unwrap(); + assert!(options.emit_decorator_metadata); + assert!(!options.experimental_decorators); + } +} diff --git a/crates/oxc_linter/src/snapshots/schema_json.snap b/crates/oxc_linter/src/snapshots/schema_json.snap index 13685991c9f7b..9a06dfe74f8f2 100644 --- a/crates/oxc_linter/src/snapshots/schema_json.snap +++ b/crates/oxc_linter/src/snapshots/schema_json.snap @@ -14,6 +14,9 @@ expression: json "globals": { "$ref": "#/definitions/OxlintGlobals" }, + "parserOptions": { + "$ref": "#/definitions/OxlintParseOptions" + }, "rules": { "description": "See [Oxlint Rules](./rules)", "allOf": [ @@ -190,6 +193,21 @@ expression: json "$ref": "#/definitions/GlobalValue" } }, + "OxlintParseOptions": { + "type": "object", + "properties": { + "emitDecoratorMetadata": { + "description": "This option allow you to tell parser to act as if `emitDecoratorMetadata: true` is set in `tsconfig.json`.", + "default": false, + "type": "boolean" + }, + "experimentalDecorators": { + "description": "This option allow you to tell parser to act as if `experimentalDecorators: true` is set in `tsconfig.json`.", + "default": false, + "type": "boolean" + } + } + }, "OxlintRules": { "type": "object", "additionalProperties": { diff --git a/npm/oxlint/configuration_schema.json b/npm/oxlint/configuration_schema.json index 8af6c5eee5777..15c24ba224356 100644 --- a/npm/oxlint/configuration_schema.json +++ b/npm/oxlint/configuration_schema.json @@ -10,6 +10,9 @@ "globals": { "$ref": "#/definitions/OxlintGlobals" }, + "parserOptions": { + "$ref": "#/definitions/OxlintParseOptions" + }, "rules": { "description": "See [Oxlint Rules](./rules)", "allOf": [ @@ -186,6 +189,21 @@ "$ref": "#/definitions/GlobalValue" } }, + "OxlintParseOptions": { + "type": "object", + "properties": { + "emitDecoratorMetadata": { + "description": "This option allow you to tell parser to act as if `emitDecoratorMetadata: true` is set in `tsconfig.json`.", + "default": false, + "type": "boolean" + }, + "experimentalDecorators": { + "description": "This option allow you to tell parser to act as if `experimentalDecorators: true` is set in `tsconfig.json`.", + "default": false, + "type": "boolean" + } + } + }, "OxlintRules": { "type": "object", "additionalProperties": { diff --git a/tasks/website/src/linter/snapshots/schema_markdown.snap b/tasks/website/src/linter/snapshots/schema_markdown.snap index 5b13ea876da4c..242cf74461e5c 100644 --- a/tasks/website/src/linter/snapshots/schema_markdown.snap +++ b/tasks/website/src/linter/snapshots/schema_markdown.snap @@ -50,6 +50,30 @@ Add or remove global variables. +## parserOptions + +type: `object` + + + + +### parserOptions.emitDecoratorMetadata + +type: `boolean` + +This option allow you to tell parser to act as if `emitDecoratorMetadata: true` is set in `tsconfig.json`. + + + +### parserOptions.experimentalDecorators + +type: `boolean` + +This option allow you to tell parser to act as if `experimentalDecorators: true` is set in `tsconfig.json`. + + + + ## rules