Skip to content

Commit b0cc5de

Browse files
connorsheaCopilot
andauthored
docs(linter): Add configuration option docs for 4 jest rules (#15172)
Part of #14743. - jest/no-restricted-matchers - jest/expect-expect - jest/no-standalone-expect - jest/no-restricted-jest-methods Note for no-restricted-matchers that this is technically incorrect in that the configuration options do not actually accept a key, it's just a direct object passed as the first argument. But there's not any way to represent that right now in the auto-gen system Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### restrictedMatchers type: `Record<string, string>` default: `{}` A map of restricted matchers/modifiers to custom messages. The key is the matcher/modifier name (e.g., "toBeFalsy", "resolves", "not.toHaveBeenCalledWith"). The value is an optional custom message to display when the matcher/modifier is used. ``` ```md ## Configuration This rule accepts a configuration object with the following properties: ### additionalTestBlockFunctions type: `string[]` default: `[]` An array of function names that should also be treated as test blocks. ### assertFunctionNamesJest type: `string[]` default: `["expect"]` A list of function names that should be treated as assertion functions. ### assertFunctionNamesVitest type: `string[]` default: `["expect", "expectTypeOf", "assert", "assertType"]` A list of function names that should be treated as assertion functions. ``` ```md ## Configuration This rule accepts a configuration object with the following properties: ### restrictedJestMethods type: `Record<string, string>` default: `{}` A mapping of restricted Jest method names to custom messages. ``` ```md ## Configuration This rule accepts a configuration object with the following properties: ### additionalTestBlockFunctions type: `string[]` default: `[]` An array of function names that should also be treated as test blocks. ``` --------- Signed-off-by: Connor Shea <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 4dd1a4e commit b0cc5de

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

crates/oxc_linter/src/rules/jest/expect_expect.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use oxc_diagnostics::OxcDiagnostic;
1111
use oxc_macros::declare_oxc_lint;
1212
use oxc_span::{CompactStr, GetSpan, Span};
1313
use oxc_syntax::scope::ScopeFlags;
14+
use schemars::JsonSchema;
1415

1516
use crate::{
1617
ast_util::get_declaration_of_variable,
@@ -30,10 +31,14 @@ fn expect_expect_diagnostic(span: Span) -> OxcDiagnostic {
3031
#[derive(Debug, Default, Clone)]
3132
pub struct ExpectExpect(Box<ExpectExpectConfig>);
3233

33-
#[derive(Debug, Clone)]
34+
#[derive(Debug, Clone, JsonSchema)]
35+
#[serde(rename_all = "camelCase", default)]
3436
pub struct ExpectExpectConfig {
37+
/// A list of function names that should be treated as assertion functions.
3538
assert_function_names_jest: Vec<CompactStr>,
39+
/// A list of function names that should be treated as assertion functions for Vitest.
3640
assert_function_names_vitest: Vec<CompactStr>,
41+
/// An array of function names that should also be treated as test blocks.
3742
additional_test_block_functions: Vec<CompactStr>,
3843
}
3944

@@ -67,7 +72,7 @@ declare_oxc_lint!(
6772
///
6873
/// ### Why is this bad?
6974
///
70-
/// People may forget to add assertions.
75+
/// People may forget to add assertions.
7176
///
7277
/// ### Examples
7378
///
@@ -91,7 +96,8 @@ declare_oxc_lint!(
9196
/// ```
9297
ExpectExpect,
9398
jest,
94-
correctness
99+
correctness,
100+
config = ExpectExpectConfig,
95101
);
96102

97103
impl Rule for ExpectExpect {

crates/oxc_linter/src/rules/jest/no_restricted_jest_methods.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
55
use rustc_hash::FxHashMap;
6+
use schemars::JsonSchema;
7+
use serde::Deserialize;
68

79
use crate::{
810
context::LintContext,
@@ -21,8 +23,10 @@ fn restricted_jest_method_with_message(x0: &str, span1: Span) -> OxcDiagnostic {
2123
#[derive(Debug, Default, Clone)]
2224
pub struct NoRestrictedJestMethods(Box<NoRestrictedJestMethodsConfig>);
2325

24-
#[derive(Debug, Default, Clone)]
26+
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
27+
#[serde(rename_all = "camelCase", default)]
2528
pub struct NoRestrictedJestMethodsConfig {
29+
/// A mapping of restricted Jest method names to custom messages.
2630
restricted_jest_methods: FxHashMap<String, String>,
2731
}
2832

@@ -67,6 +71,7 @@ declare_oxc_lint!(
6771
NoRestrictedJestMethods,
6872
jest,
6973
style,
74+
config = NoRestrictedJestMethodsConfig,
7075
);
7176

7277
impl Rule for NoRestrictedJestMethods {

crates/oxc_linter/src/rules/jest/no_restricted_matchers.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use oxc_diagnostics::OxcDiagnostic;
55
use oxc_macros::declare_oxc_lint;
66
use oxc_span::Span;
77
use rustc_hash::FxHashMap;
8+
use schemars::JsonSchema;
89

910
use crate::{
1011
context::LintContext,
@@ -28,8 +29,12 @@ fn restricted_chain_with_message(chain_call: &str, message: &str, span: Span) ->
2829
#[derive(Debug, Default, Clone)]
2930
pub struct NoRestrictedMatchers(Box<NoRestrictedMatchersConfig>);
3031

31-
#[derive(Debug, Default, Clone)]
32+
#[derive(Debug, Default, Clone, JsonSchema)]
33+
#[serde(rename_all = "camelCase", default)]
3234
pub struct NoRestrictedMatchersConfig {
35+
/// A map of restricted matchers/modifiers to custom messages.
36+
/// The key is the matcher/modifier name (e.g., "toBeFalsy", "resolves", "not.toHaveBeenCalledWith").
37+
/// The value is an optional custom message to display when the matcher/modifier is used.
3338
restricted_matchers: FxHashMap<String, String>,
3439
}
3540

@@ -103,6 +108,7 @@ declare_oxc_lint!(
103108
NoRestrictedMatchers,
104109
jest,
105110
style,
111+
config = NoRestrictedMatchersConfig,
106112
);
107113

108114
const MODIFIER_NAME: [&str; 3] = ["not", "rejects", "resolves"];

crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use oxc_macros::declare_oxc_lint;
44
use oxc_semantic::NodeId;
55
use oxc_span::{CompactStr, Span};
66
use rustc_hash::FxHashMap;
7+
use schemars::JsonSchema;
78

89
#[cfg(test)]
910
mod tests;
@@ -29,8 +30,10 @@ fn no_standalone_expect_diagnostic(span: Span) -> OxcDiagnostic {
2930
#[derive(Debug, Default, Clone)]
3031
pub struct NoStandaloneExpect(Box<NoStandaloneExpectConfig>);
3132

32-
#[derive(Debug, Default, Clone)]
33+
#[derive(Debug, Default, Clone, JsonSchema)]
34+
#[serde(rename_all = "camelCase", default)]
3335
pub struct NoStandaloneExpectConfig {
36+
/// An array of function names that should also be treated as test blocks.
3437
additional_test_block_functions: Vec<CompactStr>,
3538
}
3639

@@ -69,7 +72,8 @@ declare_oxc_lint!(
6972
/// ```
7073
NoStandaloneExpect,
7174
jest,
72-
correctness
75+
correctness,
76+
config = NoStandaloneExpectConfig,
7377
);
7478

7579
impl Rule for NoStandaloneExpect {

0 commit comments

Comments
 (0)