Skip to content

Commit 801e1d1

Browse files
authored
fix(linter): Error on unexpected tokens when declaring lint rule (#14881)
Related to [this](#14807 (comment)) issue where missing commas in `declare_oxc_lint!` would cause documentation to be generated wrongly without erroring. In the image below, there is no warning about the missing comma after `dangerou_suggestion`, this causes `config` to not be generated in the documentation. <img width="436" height="196" alt="image" src="https://github.com/user-attachments/assets/0d40bc12-15e2-48a7-813b-62b61aafc718" /> With the fix, users will be notified about the missing comma. <img width="436" height="196" alt="image" src="https://github.com/user-attachments/assets/ca75fb69-ce08-4de0-9cc0-7332a11a5e55" />
1 parent 381e08c commit 801e1d1

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ declare_oxc_lint!(
108108
/// ```
109109
MaxDepth,
110110
eslint,
111-
pedantic
111+
pedantic,
112112
config = MaxDepth,
113113
);
114114

crates/oxc_linter/src/rules/oxc/bad_bitwise_operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ declare_oxc_lint!(
6868
/// ```
6969
BadBitwiseOperator,
7070
oxc,
71-
restriction // Restricted because there are false positives for enum bitflags in TypeScript,
71+
restriction, // Restricted because there are false positives for enum bitflags in TypeScript,
7272
// e.g. in the vscode repo
7373
pending
7474
);

crates/oxc_linter/src/rules/react/forward_ref_uses_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ declare_oxc_lint!(
6060
react,
6161
correctness,
6262
suggestion
63-
suggestion
6463
);
6564

6665
fn check_forward_ref_inner<'a>(

crates/oxc_macros/src/declare_oxc_lint.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ impl Parse for LintRuleMeta {
116116
}
117117
}
118118

119-
// Ignore the rest
120-
input.parse::<proc_macro2::TokenStream>()?;
119+
let remaining = input.parse::<proc_macro2::TokenStream>()?;
120+
if !remaining.is_empty() {
121+
return Err(Error::new_spanned(
122+
remaining,
123+
"unexpected tokens in rule declaration, missing a comma?",
124+
));
125+
}
121126

122127
Ok(Self {
123128
name: struct_name,

0 commit comments

Comments
 (0)