@@ -3,11 +3,12 @@ use std::sync::{
3
3
} ;
4
4
5
5
use lazy_regex:: Regex ;
6
+ use oxc_span:: Span ;
6
7
use rustc_hash:: { FxHashMap , FxHashSet } ;
7
8
use serde:: Deserialize ;
8
9
9
10
use oxc_ast:: { AstKind , ast:: MethodDefinitionKind } ;
10
- use oxc_diagnostics:: { LabeledSpan , OxcDiagnostic } ;
11
+ use oxc_diagnostics:: OxcDiagnostic ;
11
12
use oxc_macros:: declare_oxc_lint;
12
13
use oxc_semantic:: { AstNode , JSDoc } ;
13
14
@@ -20,6 +21,12 @@ use crate::{
20
21
} ,
21
22
} ;
22
23
24
+ fn require_param_diagnostic ( violations : Vec < Span > ) -> OxcDiagnostic {
25
+ OxcDiagnostic :: warn ( "Missing JSDoc `@param` declaration for function parameters." )
26
+ . with_help ( "Add `@param` tag with name." )
27
+ . with_labels ( violations)
28
+ }
29
+
23
30
#[ derive( Debug , Default , Clone ) ]
24
31
pub struct RequireParam ( Box < RequireParamConfig > ) ;
25
32
@@ -149,10 +156,14 @@ impl Rule for RequireParam {
149
156
}
150
157
}
151
158
159
+ // If there is a `@type` tag for this function, then `@param` is not required
160
+ if jsdocs. iter ( ) . any ( has_type_tag) {
161
+ return ;
162
+ }
163
+
152
164
// If JSDoc is found but safely ignored, skip
153
165
if jsdocs
154
166
. iter ( )
155
- . filter ( |jsdoc| !should_ignore_as_custom_skip ( jsdoc) )
156
167
. filter ( |jsdoc| !should_ignore_as_avoid ( jsdoc, settings, & config. exempted_by ) )
157
168
. filter ( |jsdoc| !should_ignore_as_private ( jsdoc, settings) )
158
169
. filter ( |jsdoc| !should_ignore_as_internal ( jsdoc, settings) )
@@ -175,6 +186,7 @@ impl Rule for RequireParam {
175
186
} ) ;
176
187
177
188
let mut violations = vec ! [ ] ;
189
+
178
190
for ( idx, param) in params_to_check. iter ( ) . enumerate ( ) {
179
191
match param {
180
192
ParamKind :: Single ( param) => {
@@ -246,15 +258,7 @@ impl Rule for RequireParam {
246
258
}
247
259
248
260
if !violations. is_empty ( ) {
249
- let labels = violations
250
- . iter ( )
251
- . map ( |span| LabeledSpan :: new_with_span ( None , * span) )
252
- . collect :: < Vec < _ > > ( ) ;
253
- ctx. diagnostic (
254
- OxcDiagnostic :: warn ( "Missing JSDoc `@param` declaration for function parameters." )
255
- . with_help ( "Add `@param` tag with name." )
256
- . with_labels ( labels) ,
257
- ) ;
261
+ ctx. diagnostic ( require_param_diagnostic ( violations) ) ;
258
262
}
259
263
}
260
264
}
@@ -286,7 +290,8 @@ fn collect_tags<'a>(
286
290
collected
287
291
}
288
292
289
- fn should_ignore_as_custom_skip ( jsdoc : & JSDoc ) -> bool {
293
+ /// Returns true if the JSDoc has a `@type` tag in it
294
+ fn has_type_tag ( jsdoc : & JSDoc ) -> bool {
290
295
jsdoc. tags ( ) . iter ( ) . any ( |tag| "type" == tag. kind . parsed ( ) )
291
296
}
292
297
@@ -747,6 +752,15 @@ fn test() {
747
752
return a + b;
748
753
}
749
754
" , None , None ) , // { "parser": typescriptEslintParser, }
755
+ // https://github.com/oxc-project/oxc/issues/10253
756
+ ( "
757
+ /** @typedef {import('../types.d.ts').FileURL} FileURL */
758
+
759
+ /**
760
+ * @type {import('node:module').ResolveHook}
761
+ */
762
+ async function resolveJSONC(specifier, ctx, nextResolve) {}
763
+ " , None , None )
750
764
] ;
751
765
752
766
let fail = vec ! [
0 commit comments