Skip to content

Commit b6402dd

Browse files
authored
docs(linter): Move documentation comments for the valid-typeof rule to the struct (#14841)
This ensures the autogenerated documentation handles the configuration section. Part of #14743. The generated docs look like this (but without the backslashes before the code blocks): ```md ## Configuration This rule accepts a configuration object with the following properties: ### requireStringLiterals type: `boolean` default: `false` The `requireStringLiterals` option when set to `true`, allows the comparison of `typeof` expressions with only string literals or other `typeof` expressions, and disallows comparisons to any other value. Default is `false`. With `requireStringLiterals` set to `true`, the following are examples of **incorrect** code: \```js typeof foo === undefined typeof bar == Object typeof baz === "strnig" typeof qux === "some invalid type" typeof baz === anotherVariable typeof foo == 5 \``` With `requireStringLiterals` set to `true`, the following are examples of **correct** code: \```js typeof foo === "undefined" typeof bar == "object" typeof baz === "string" typeof bar === typeof qux \``` ```
1 parent a02567f commit b6402dd

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

crates/oxc_linter/src/rules/eslint/valid_typeof.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::{GetSpan, Span};
55
use oxc_syntax::operator::UnaryOperator;
6+
use schemars::JsonSchema;
67

78
use crate::{AstNode, context::LintContext, rule::Rule};
89

@@ -23,11 +24,33 @@ fn invalid_value(help: Option<&'static str>, span: Span) -> OxcDiagnostic {
2324
d
2425
}
2526

26-
#[derive(Debug, Clone, Default)]
27+
#[derive(Debug, Clone, Default, JsonSchema)]
28+
#[serde(rename_all = "camelCase", default)]
2729
pub struct ValidTypeof {
28-
/// true requires typeof expressions to only be compared to string literals or other typeof expressions, and disallows comparisons to any other value.
30+
/// The `requireStringLiterals` option when set to `true`, allows the comparison of `typeof`
31+
/// expressions with only string literals or other `typeof` expressions, and disallows
32+
/// comparisons to any other value. Default is `false`.
33+
///
34+
/// With `requireStringLiterals` set to `true`, the following are examples of **incorrect** code:
35+
/// ```js
36+
/// typeof foo === undefined
37+
/// typeof bar == Object
38+
/// typeof baz === "strnig"
39+
/// typeof qux === "some invalid type"
40+
/// typeof baz === anotherVariable
41+
/// typeof foo == 5
42+
/// ```
43+
///
44+
/// With `requireStringLiterals` set to `true`, the following are examples of **correct** code:
45+
/// ```js
46+
/// typeof foo === "undefined"
47+
/// typeof bar == "object"
48+
/// typeof baz === "string"
49+
/// typeof bar === typeof qux
50+
/// ```
2951
require_string_literals: bool,
3052
}
53+
3154
declare_oxc_lint!(
3255
/// ### What it does
3356
///
@@ -57,38 +80,11 @@ declare_oxc_lint!(
5780
/// typeof foo === baz
5881
/// typeof bar === typeof qux
5982
/// ```
60-
///
61-
/// ### Options
62-
///
63-
/// #### requireStringLiterals
64-
///
65-
/// `{ type: boolean, default: false }`
66-
///
67-
/// The `requireStringLiterals` option when set to `true`, allows the comparison of `typeof`
68-
/// expressions with only string literals or other `typeof` expressions, and disallows
69-
/// comparisons to any other value. Default is `false`.
70-
///
71-
/// With `requireStringLiterals` set to `true` the following are examples of incorrect code:
72-
/// ```js
73-
/// typeof foo === undefined
74-
/// typeof bar == Object
75-
/// typeof baz === "strnig"
76-
/// typeof qux === "some invalid type"
77-
/// typeof baz === anotherVariable
78-
/// typeof foo == 5
79-
/// ```
80-
///
81-
/// With `requireStringLiterals` set to `true` the following are examples of correct code:
82-
/// ```js
83-
/// typeof foo === "undefined"
84-
/// typeof bar == "object"
85-
/// typeof baz === "string"
86-
/// typeof bar === typeof qux
87-
/// ```
8883
ValidTypeof,
8984
eslint,
9085
correctness,
91-
conditional_fix
86+
conditional_fix,
87+
config = ValidTypeof,
9288
);
9389

9490
impl Rule for ValidTypeof {

0 commit comments

Comments
 (0)