Skip to content

Commit 35b36e0

Browse files
authored
docs(linter): Add configuration option docs for eslint/no-eval rule. (#15015)
These docs already existed, but were not using the standard format. Part of #14743. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allowIndirect type: `boolean` default: `true` This `allowIndirect` option allows indirect `eval()` calls. Indirect calls to `eval`(e.g., `window['eval']`) are less dangerous than direct calls because they cannot dynamically change the scope. Indirect `eval()` calls also typically have less impact on performance compared to direct calls, as they do not invoke JavaScript's scope chain. ```
1 parent d222b85 commit 35b36e0

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

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

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use oxc_ast::AstKind;
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::{GetSpan, Span};
5+
use schemars::JsonSchema;
56

67
use crate::{
78
AstNode,
@@ -15,8 +16,15 @@ fn no_eval_diagnostic(span: Span) -> OxcDiagnostic {
1516
OxcDiagnostic::warn("eval can be harmful.").with_label(span)
1617
}
1718

18-
#[derive(Debug, Clone)]
19+
#[derive(Debug, Clone, JsonSchema)]
20+
#[serde(rename_all = "camelCase", default)]
1921
pub struct NoEval {
22+
/// This `allowIndirect` option allows indirect `eval()` calls.
23+
///
24+
/// Indirect calls to `eval`(e.g., `window['eval']`) are less dangerous
25+
/// than direct calls because they cannot dynamically change the scope.
26+
/// Indirect `eval()` calls also typically have less impact on performance
27+
/// compared to direct calls, as they do not invoke JavaScript's scope chain.
2028
allow_indirect: bool,
2129
}
2230

@@ -77,30 +85,10 @@ declare_oxc_lint!(
7785
/// static eval() { }
7886
/// }
7987
/// ```
80-
///
81-
/// ### Options
82-
///
83-
/// #### allowIndirect
84-
///
85-
/// `{ type: boolean, default: true }`
86-
///
87-
/// This `allowIndirect` option allows indirect `eval()` calls.
88-
///
89-
/// Indirect calls to `eval`(e.g., `window['eval']`) are less dangerous
90-
/// than direct calls because they cannot dynamically change the scope.
91-
/// Indirect `eval()` calls also typically have less impact on performance
92-
/// compared to direct calls, as they do not invoke JavaScript's scope chain.
93-
///
94-
/// Example:
95-
/// ```json
96-
/// "eslint/no-eval": [
97-
/// "error",
98-
/// { "allowIndirect": true }
99-
/// ]
100-
/// ```
10188
NoEval,
10289
eslint,
103-
correctness
90+
correctness,
91+
config = NoEval,
10492
);
10593

10694
impl Rule for NoEval {

0 commit comments

Comments
 (0)