From 1b6f6738ad20a6a843599efe6e69d119f7b147ae Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Sun, 26 Oct 2025 21:28:07 -0600 Subject: [PATCH 1/3] docs(linter): Add configuration option docs for typescript/no-empty-object-type rule. --- .../rules/typescript/no_empty_object_type.rs | 96 +++++++++---------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs index 9cd71ae1e2a77..aa27883b1e2e5 100644 --- a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs @@ -9,6 +9,8 @@ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::NodeId; use oxc_span::Span; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::{AstNode, context::LintContext, rule::Rule}; @@ -25,13 +27,46 @@ fn no_empty_object_type_diagnostic>>( pub struct NoEmptyObjectType(Box); #[expect(clippy::struct_field_names)] -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase", default)] pub struct NoEmptyObjectTypeConfig { - /** Whether to allow empty interfaces. */ + /// Whether to allow empty interfaces. + /// + /// Allowed values are: + /// - `'always'`: to always allow interfaces with no fields + /// - `'never'` _(default)_: to never allow interfaces with no fields + /// - `'with-single-extends'`: to allow empty interfaces that `extend` from a single base interface + /// + /// Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`: + /// ```ts + /// interface Base { + /// value: boolean; + /// } + /// interface Derived extends Base {} + /// ``` allow_interfaces: AllowInterfaces, - /** Whether to allow empty object type literals. */ + /// Whether to allow empty object type literals. + /// + /// Allowed values are: + /// - `'always'`: to always allow object type literals with no fields + /// - `'never'` _(default)_: to never allow object type literals with no fields allow_object_types: AllowObjectTypes, - /** allow interfaces and object type aliases with the configured name pattern (regex) */ + /// A stringified regular expression to allow interfaces and object type aliases with the configured name. + /// + /// This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`. + /// + /// Example of **incorrect** code for this rule with `{ allowWithName: 'Props$' }`: + /// ```ts + /// interface InterfaceValue {} + /// type TypeValue = {}; + /// ``` + /// + /// Example of **correct** code for this rule with `{ allowWithName: 'Props$' }`: + /// ```ts + /// interface InterfaceProps {} + /// type TypeProps = {}; + /// ``` + #[serde(skip)] // TODO: Serialize this so it can be documented properly. allow_with_name: Option, } @@ -86,55 +121,10 @@ declare_oxc_lint!( /// } /// type TypeWith = { property: boolean }; /// ``` - /// - /// ### Options - /// - /// #### `allowInterfaces` - /// - /// Whether to allow empty interfaces. Default: `"never"`. - /// - /// Allowed values are: - /// - `'always'`: to always allow interfaces with no fields - /// - `'never'` _(default)_: to never allow interfaces with no fields - /// - `'with-single-extends'`: to allow empty interfaces that `extend` from a single base interface - /// - /// Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`: - /// ```ts - /// interface Base { - /// value: boolean; - /// } - /// interface Derived extends Base {} - /// ``` - /// - /// #### `allowObjectTypes` - /// - /// Whether to allow empty object type literals. Default: `"never"`. - /// - /// Allowed values are: - /// - `'always'`: to always allow object type literals with no fields - /// - `'never'` _(default)_: to never allow object type literals with no fields - /// - /// #### `allowWithName` - /// - /// A stringified regular expression to allow interfaces and object type aliases with the configured name. - /// - /// This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`. - /// - /// Example of **incorrect** code for this rule with `{ allowWithName: 'Props$' }`: - /// ```ts - /// interface InterfaceValue {} - /// type TypeValue = {}; - /// ``` - /// - /// Example of **correct** code for this rule with `{ allowWithName: 'Props$' }`: - /// ```ts - /// interface InterfaceProps {} - /// type TypeProps = {}; - /// ``` - /// NoEmptyObjectType, typescript, restriction, + config = NoEmptyObjectTypeConfig, ); impl Rule for NoEmptyObjectType { @@ -246,7 +236,8 @@ fn check_type_literal( )); } -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] +#[serde(rename_all = "lowercase")] enum AllowInterfaces { #[default] Never, @@ -264,7 +255,8 @@ impl From<&str> for AllowInterfaces { } } -#[derive(Debug, Default, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema)] +#[serde(rename_all = "lowercase")] enum AllowObjectTypes { #[default] Never, From a1dc697d0c02879f944779b4c62fe77697d0548e Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Sun, 26 Oct 2025 21:34:05 -0600 Subject: [PATCH 2/3] Set the values in the enum to kebab-case. --- crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs index aa27883b1e2e5..baf5d6944ee98 100644 --- a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs @@ -237,7 +237,7 @@ fn check_type_literal( } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "kebab-case")] enum AllowInterfaces { #[default] Never, From 24b9b0d1f35d01715bfe219ddacf2e633c965e13 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Sun, 26 Oct 2025 21:35:11 -0600 Subject: [PATCH 3/3] Remove unused import Serialize. --- crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs index baf5d6944ee98..d778e175ff8b9 100644 --- a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs @@ -10,7 +10,7 @@ use oxc_macros::declare_oxc_lint; use oxc_semantic::NodeId; use oxc_span::Span; use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use crate::{AstNode, context::LintContext, rule::Rule};