Skip to content

Commit 2e02fe0

Browse files
authored
docs(linter): Add configuration option docs for jest/no-deprecated-functions rule (#14976)
Part of #14743. Also made some minor improvements to the docs block. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### jest type: `object` Jest configuration options. #### jest.version type: `string` default: `"29"` The version of Jest being used. ```
1 parent cdc6c4f commit 2e02fe0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use oxc_ast::ast::Expression;
44
use oxc_diagnostics::OxcDiagnostic;
55
use oxc_macros::declare_oxc_lint;
66
use oxc_span::{GetSpan, Span};
7+
use schemars::JsonSchema;
8+
use serde::Deserialize;
79

810
use crate::{context::LintContext, rule::Rule};
911

@@ -12,8 +14,10 @@ fn deprecated_function(deprecated: &str, new: &str, span: Span) -> OxcDiagnostic
1214
.with_label(span)
1315
}
1416

15-
#[derive(Debug, Clone)]
17+
#[derive(Debug, Clone, Deserialize, JsonSchema)]
18+
#[serde(rename_all = "camelCase", default)]
1619
pub struct JestConfig {
20+
/// The version of Jest being used.
1721
version: String,
1822
}
1923

@@ -26,8 +30,10 @@ impl Default for JestConfig {
2630
#[derive(Debug, Default, Clone)]
2731
pub struct NoDeprecatedFunctions(Box<NoDeprecatedFunctionsConfig>);
2832

29-
#[derive(Debug, Default, Clone)]
33+
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
34+
#[serde(rename_all = "camelCase", default)]
3035
pub struct NoDeprecatedFunctionsConfig {
36+
/// Jest configuration options.
3137
jest: JestConfig,
3238
}
3339

@@ -46,26 +52,32 @@ declare_oxc_lint!(
4652
/// either been renamed for clarity, or replaced with more powerful APIs.
4753
///
4854
/// This rule can also autofix a number of these deprecations for you.
55+
///
4956
/// #### `jest.resetModuleRegistry`
57+
///
5058
/// This function was renamed to `resetModules` in Jest 15 and removed in Jest 27.
5159
///
5260
/// #### `jest.addMatchers`
61+
///
5362
/// This function was replaced with `expect.extend` in Jest 17 and removed in Jest 27.
5463
///
5564
/// #### `require.requireActual` & `require.requireMock`
65+
///
5666
/// These functions were replaced in Jest 21 and removed in Jest 26.
5767
///
58-
/// Originally, the `requireActual` & `requireMock` the `requireActual`&
59-
/// `requireMock` functions were placed onto the `require` function.
68+
/// Originally, the `requireActual` and `requireMock` functions were placed
69+
/// onto the `require` function.
6070
///
6171
/// These functions were later moved onto the `jest` object in order to be easier
6272
/// for type checkers to handle, and their use via `require` deprecated. Finally,
6373
/// the release of Jest 26 saw them removed from the `require` function altogether.
6474
///
6575
/// #### `jest.runTimersToTime`
76+
///
6677
/// This function was renamed to `advanceTimersByTime` in Jest 22 and removed in Jest 27.
6778
///
6879
/// #### `jest.genMockFromModule`
80+
///
6981
/// This function was renamed to `createMockFromModule` in Jest 26, and is scheduled for removal in Jest 30.
7082
///
7183
/// ### Why is this bad?
@@ -83,7 +95,8 @@ declare_oxc_lint!(
8395
NoDeprecatedFunctions,
8496
jest,
8597
style,
86-
fix
98+
fix,
99+
config = NoDeprecatedFunctionsConfig,
87100
);
88101

89102
fn deprecated_functions_map(deprecated_fn: &str) -> Option<(usize, &'static str)> {

0 commit comments

Comments
 (0)