Skip to content

Commit a331993

Browse files
committed
docs(linter): Improve docs for eslint/radix rule. (#19611)
To explain the change that occurred, and make it clearer for users that run into this problem.
1 parent 79fe3b4 commit a331993

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn missing_parameters(span: Span) -> OxcDiagnostic {
1616

1717
fn missing_radix(span: Span) -> OxcDiagnostic {
1818
OxcDiagnostic::warn("Missing radix parameter.")
19-
.with_help("Add radix parameter `10` for parsing decimal numbers.")
19+
.with_help("Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.")
2020
.with_label(span)
2121
}
2222

@@ -25,8 +25,8 @@ fn invalid_radix(span: Span) -> OxcDiagnostic {
2525
.with_label(span)
2626
}
2727

28-
/// `RadixType` has no affect, it only here for backward compatibility.
29-
/// Without it, the linter will report unknown rule configuration error.
28+
// `RadixType` has no effect, it is only here for backward compatibility.
29+
// Without it, the linter will report unknown rule configuration error.
3030
#[derive(Debug, Default, Clone, JsonSchema, Deserialize, Serialize)]
3131
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
3232
pub struct Radix(RadixType);
@@ -50,7 +50,8 @@ enum RadixType {
5050
declare_oxc_lint!(
5151
/// ### What it does
5252
///
53-
/// Enforce the consistent use of the radix argument when using `parseInt()`.
53+
/// Enforce the consistent use of the radix argument when using `parseInt()`,
54+
/// which specifies what base to use for parsing the number.
5455
///
5556
/// ### Why is this bad?
5657
///
@@ -59,18 +60,29 @@ declare_oxc_lint!(
5960
///
6061
/// See the
6162
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#radix)
62-
/// for more information.
63+
/// for more information on how `parseInt()` handles certain edge-cases.
64+
///
65+
/// ### Configuration
66+
///
67+
/// Note that passing an option to this rule has no effect on its behavior.
68+
/// In v1.49.0, the config option for this rule was removed and made a no-op.
69+
/// This matches the behavior change made in ESLint v10, and the rule now
70+
/// always enforces that a radix parameter is provided to `parseInt()`.
71+
///
72+
/// If you receive new violations due to this change, you may either opt
73+
/// to disable this rule, or add the radix parameter to all usages of
74+
/// `parseInt()` in your codebase.
6375
///
6476
/// ### Examples
6577
///
6678
/// Examples of **incorrect** code for this rule:
6779
/// ```javascript
68-
/// var num = parseInt("071"); // 57
80+
/// let num = parseInt("071"); // 57
6981
/// ```
7082
///
7183
/// Examples of **correct** code for this rule:
7284
/// ```javascript
73-
/// var num = parseInt("071", 10); // 71
85+
/// let num = parseInt("071", 10); // 71
7486
/// ```
7587
Radix,
7688
eslint,

crates/oxc_linter/src/snapshots/eslint_radix.snap

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4+
45
eslint(radix): Missing parameters.
56
╭─[radix.tsx:1:1]
67
1parseInt();
@@ -12,28 +13,28 @@ source: crates/oxc_linter/src/tester.rs
1213
1parseInt("10");
1314
· ──────────────
1415
╰────
15-
help: Add radix parameter `10` for parsing decimal numbers.
16+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
1617

1718
eslint(radix): Missing radix parameter.
1819
╭─[radix.tsx:1:1]
1920
1parseInt("10",);
2021
· ───────────────
2122
╰────
22-
help: Add radix parameter `10` for parsing decimal numbers.
23+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
2324

2425
eslint(radix): Missing radix parameter.
2526
╭─[radix.tsx:1:1]
2627
1parseInt((0, "10"));
2728
· ───────────────────
2829
╰────
29-
help: Add radix parameter `10` for parsing decimal numbers.
30+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
3031

3132
eslint(radix): Missing radix parameter.
3233
╭─[radix.tsx:1:1]
3334
1parseInt((0, "10"),);
3435
· ────────────────────
3536
╰────
36-
help: Add radix parameter `10` for parsing decimal numbers.
37+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
3738

3839
eslint(radix): Invalid radix parameter, must be an integer between 2 and 36.
3940
╭─[radix.tsx:1:16]
@@ -94,7 +95,7 @@ source: crates/oxc_linter/src/tester.rs
9495
1Number.parseInt("10");
9596
· ─────────────────────
9697
╰────
97-
help: Add radix parameter `10` for parsing decimal numbers.
98+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
9899

99100
eslint(radix): Invalid radix parameter, must be an integer between 2 and 36.
100101
╭─[radix.tsx:1:23]
@@ -119,28 +120,28 @@ source: crates/oxc_linter/src/tester.rs
119120
1parseInt?.("10");
120121
· ────────────────
121122
╰────
122-
help: Add radix parameter `10` for parsing decimal numbers.
123+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
123124

124125
eslint(radix): Missing radix parameter.
125126
╭─[radix.tsx:1:1]
126127
1Number.parseInt?.("10");
127128
· ───────────────────────
128129
╰────
129-
help: Add radix parameter `10` for parsing decimal numbers.
130+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
130131

131132
eslint(radix): Missing radix parameter.
132133
╭─[radix.tsx:1:1]
133134
1Number?.parseInt("10");
134135
· ──────────────────────
135136
╰────
136-
help: Add radix parameter `10` for parsing decimal numbers.
137+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
137138

138139
eslint(radix): Missing radix parameter.
139140
╭─[radix.tsx:1:1]
140141
1 │ (Number?.parseInt)("10");
141142
· ────────────────────────
142143
╰────
143-
help: Add radix parameter `10` for parsing decimal numbers.
144+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
144145

145146
eslint(radix): Missing parameters.
146147
╭─[radix.tsx:1:1]
@@ -159,14 +160,14 @@ source: crates/oxc_linter/src/tester.rs
159160
1parseInt("10");
160161
· ──────────────
161162
╰────
162-
help: Add radix parameter `10` for parsing decimal numbers.
163+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
163164

164165
eslint(radix): Missing radix parameter.
165166
╭─[radix.tsx:1:1]
166167
1parseInt("10");
167168
· ──────────────
168169
╰────
169-
help: Add radix parameter `10` for parsing decimal numbers.
170+
help: Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.
170171

171172
eslint(radix): Invalid radix parameter, must be an integer between 2 and 36.
172173
╭─[radix.tsx:1:16]

0 commit comments

Comments
 (0)