Skip to content

Commit 096fb2c

Browse files
authored
docs(linter): Add config option docs for 3 rules. (#15211)
Part of #14743. - eslint/no-bitwise - eslint/no-console - eslint/no-inner-declarations Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allow type: `string[]` default: `[]` The `allow` option permits the given list of console methods to be used as exceptions to this rule. Say the option was configured as `{ "allow": ["info"] }` then the rule would behave as follows: Example of **incorrect** code for this option: \```javascript console.log('foo'); \``` Example of **correct** code for this option: \```javascript console.info('foo'); \``` ``` ```md ## Configuration This rule accepts a configuration object with the following properties: ### blockScopedFunctions default: `null` Controls whether function declarations in nested blocks are allowed in strict mode (ES6+ behavior). ### config default: `"functions"` Determines what type of declarations to check. ``` ```md ## Configuration This rule accepts a configuration object with the following properties: ### allow type: `string[]` default: `[]` The `allow` option permits the given list of bitwise operators to be used as exceptions to this rule. For example `{ "allow": ["~"] }` would allow the use of the bitwise operator `~` without restriction. Such as in the following: \```javascript ~[1,2,3].indexOf(1) === -1; \``` ### int32Hint type: `boolean` default: `false` When set to true the `int32Hint` option allows the use of bitwise OR in |0 pattern for type casting. For example with `{ "int32Hint": true }` the following is permitted: \```javascript const b = a|0; \``` ```
1 parent 3f393e3 commit 096fb2c

File tree

3 files changed

+60
-63
lines changed

3 files changed

+60
-63
lines changed

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

Lines changed: 22 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::{CompactStr, Span};
55
use oxc_syntax::operator::BinaryOperator;
6+
use schemars::JsonSchema;
67

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

@@ -15,9 +16,27 @@ fn no_bitwise_diagnostic(operator: &str, span: Span) -> OxcDiagnostic {
1516
#[derive(Debug, Default, Clone)]
1617
pub struct NoBitwise(Box<NoBitwiseConfig>);
1718

18-
#[derive(Debug, Default, Clone)]
19+
#[derive(Debug, Default, Clone, JsonSchema)]
20+
#[serde(rename_all = "camelCase", default)]
1921
pub struct NoBitwiseConfig {
22+
/// The `allow` option permits the given list of bitwise operators to be used
23+
/// as exceptions to this rule.
24+
///
25+
/// For example `{ "allow": ["~"] }` would allow the use of the bitwise operator
26+
/// `~` without restriction. Such as in the following:
27+
///
28+
/// ```javascript
29+
/// ~[1,2,3].indexOf(1) === -1;
30+
/// ```
2031
allow: Vec<CompactStr>,
32+
/// When set to true the `int32Hint` option allows the use of bitwise OR in |0
33+
/// pattern for type casting.
34+
///
35+
/// For example with `{ "int32Hint": true }` the following is permitted:
36+
///
37+
/// ```javascript
38+
/// const b = a|0;
39+
/// ```
2140
int32_hint: bool,
2241
}
2342

@@ -66,38 +85,10 @@ declare_oxc_lint!(
6685
/// ```javascript
6786
/// var x = y > z;
6887
/// ```
69-
///
70-
/// ### Options
71-
///
72-
/// #### allow
73-
///
74-
/// `{ type: string[], default: [] }`
75-
///
76-
/// The `allow` option permits the given list of bitwise operators to be used
77-
/// as exceptions to this rule.
78-
///
79-
/// For example `{ "allow": ["~"] }` would allow the use of the bitwise operator
80-
/// `~` without restriction. Such as in the following:
81-
///
82-
/// ```javascript
83-
/// ~[1,2,3].indexOf(1) === -1;
84-
/// ```
85-
///
86-
/// #### int32Hint
87-
///
88-
/// `{ type: boolean, default: false }`
89-
///
90-
/// When set to true the `int32Hint` option allows the use of bitwise OR in |0
91-
/// pattern for type casting.
92-
///
93-
/// For example with `{ "int32Hint": true }` the following is permitted:
94-
///
95-
/// ```javascript
96-
/// const b = a|0;
97-
/// ```
9888
NoBitwise,
9989
eslint,
100-
restriction
90+
restriction,
91+
config = NoBitwiseConfig,
10192
);
10293

10394
impl Rule for NoBitwise {

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use oxc_ast::{AstKind, ast::Expression};
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::{CompactStr, GetSpan, Span};
5+
use schemars::JsonSchema;
6+
use serde::Deserialize;
57

68
use crate::{
79
AstNode,
@@ -23,8 +25,24 @@ fn no_console_diagnostic(span: Span, allow: &[CompactStr]) -> OxcDiagnostic {
2325
#[derive(Debug, Default, Clone)]
2426
pub struct NoConsole(Box<NoConsoleConfig>);
2527

26-
#[derive(Debug, Default, Clone)]
28+
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
29+
#[serde(rename_all = "camelCase", default)]
2730
pub struct NoConsoleConfig {
31+
/// The `allow` option permits the given list of console methods to be used as exceptions to
32+
/// this rule.
33+
///
34+
/// Say the option was configured as `{ "allow": ["info"] }` then the rule would behave as
35+
/// follows:
36+
///
37+
/// Example of **incorrect** code for this option:
38+
/// ```javascript
39+
/// console.log('foo');
40+
/// ```
41+
///
42+
/// Example of **correct** code for this option:
43+
/// ```javascript
44+
/// console.info('foo');
45+
/// ```
2846
pub allow: Vec<CompactStr>,
2947
}
3048

@@ -63,32 +81,11 @@ declare_oxc_lint!(
6381
/// // custom console
6482
/// Console.log("Hello world!");
6583
/// ```
66-
///
67-
/// ### Options
68-
///
69-
/// #### allow
70-
///
71-
/// `{ type: string[], default: [] }`
72-
///
73-
/// The `allow` option permits the given list of console methods to be used as exceptions to
74-
/// this rule.
75-
///
76-
/// Say the option was configured as `{ "allow": ["info"] }` then the rule would behave as
77-
/// follows:
78-
///
79-
/// Example of **incorrect** code for this option:
80-
/// ```javascript
81-
/// console.log('foo');
82-
/// ```
83-
///
84-
/// Example of **correct** code for this option:
85-
/// ```javascript
86-
/// console.info('foo');
87-
/// ```
8884
NoConsole,
8985
eslint,
9086
restriction,
91-
conditional_suggestion
87+
conditional_suggestion,
88+
config = NoConsoleConfig,
9289
);
9390

9491
impl Rule for NoConsole {

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use oxc_ast::AstKind;
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
5+
use schemars::JsonSchema;
6+
use serde::{Deserialize, Serialize};
57

68
use crate::{AstNode, context::LintContext, rule::Rule};
79

@@ -11,27 +13,33 @@ fn no_inner_declarations_diagnostic(decl_type: &str, body: &str, span: Span) ->
1113
.with_label(span)
1214
}
1315

14-
#[derive(Debug, Default, Clone)]
16+
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
17+
#[serde(rename_all = "camelCase", default)]
1518
pub struct NoInnerDeclarations {
19+
/// Determines what type of declarations to check.
1620
config: NoInnerDeclarationsConfig,
21+
/// Controls whether function declarations in nested blocks are allowed in strict mode (ES6+ behavior).
22+
#[schemars(with = "BlockScopedFunctions")]
1723
block_scoped_functions: Option<BlockScopedFunctions>,
1824
}
1925

20-
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
26+
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
27+
#[serde(rename_all = "lowercase")]
2128
enum NoInnerDeclarationsConfig {
22-
/// Disallows function declarations in nested blocks
29+
/// Disallows function declarations in nested blocks.
2330
#[default]
2431
Functions,
25-
/// Disallows function and var declarations in nested blocks
32+
/// Disallows function and var declarations in nested blocks.
2633
Both,
2734
}
2835

29-
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
36+
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
37+
#[serde(rename_all = "lowercase")]
3038
enum BlockScopedFunctions {
31-
/// Allow function declarations in nested blocks in strict mode (ES6+ behavior)
39+
/// Allow function declarations in nested blocks in strict mode (ES6+ behavior).
3240
#[default]
3341
Allow,
34-
/// Disallow function declarations in nested blocks regardless of strict mode
42+
/// Disallow function declarations in nested blocks regardless of strict mode.
3543
Disallow,
3644
}
3745

@@ -64,7 +72,8 @@ declare_oxc_lint!(
6472
/// ```
6573
NoInnerDeclarations,
6674
eslint,
67-
pedantic
75+
pedantic,
76+
config = NoInnerDeclarations,
6877
);
6978

7079
impl Rule for NoInnerDeclarations {

0 commit comments

Comments
 (0)