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

feat(linter): add parserOptions.emitDecoratorMetadata and parserOptions.experimentalDecorators for config file #3645

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions crates/oxc_linter/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod env;
mod globals;
mod parser_options;
mod rules;
mod settings;

Expand All @@ -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,
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
49 changes: 49 additions & 0 deletions crates/oxc_linter/src/config/parser_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use schemars::JsonSchema;
use serde::Deserialize;

// <https://typescript-eslint.io/packages/parser/#configuration>
#[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);
}
}
18 changes: 18 additions & 0 deletions crates/oxc_linter/src/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ expression: json
"globals": {
"$ref": "#/definitions/OxlintGlobals"
},
"parserOptions": {
"$ref": "#/definitions/OxlintParseOptions"
},
"rules": {
"description": "See [Oxlint Rules](./rules)",
"allOf": [
Expand Down Expand Up @@ -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": {
Expand Down
18 changes: 18 additions & 0 deletions npm/oxlint/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"globals": {
"$ref": "#/definitions/OxlintGlobals"
},
"parserOptions": {
"$ref": "#/definitions/OxlintParseOptions"
},
"rules": {
"description": "See [Oxlint Rules](./rules)",
"allOf": [
Expand Down Expand Up @@ -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": {
Expand Down
24 changes: 24 additions & 0 deletions tasks/website/src/linter/snapshots/schema_markdown.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down