Skip to content

Commit b024c95

Browse files
committed
Fix perf?: Early return on diagnostic
1 parent 2cdf6c0 commit b024c95

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

crates/oxc_linter/src/rules/jsdoc/require_param.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use oxc_ast::{
22
ast::{BindingPattern, BindingPatternKind, Expression, FormalParameters, MethodDefinitionKind},
33
AstKind,
44
};
5-
use oxc_diagnostics::LabeledSpan;
5+
// use oxc_diagnostics::LabeledSpan;
66
use oxc_diagnostics::OxcDiagnostic;
77
use oxc_macros::declare_oxc_lint;
88
use oxc_semantic::{AstNode, JSDoc};
@@ -20,6 +20,12 @@ use crate::{
2020
},
2121
};
2222

23+
fn require_param_diagnostic(span: Span) -> OxcDiagnostic {
24+
OxcDiagnostic::warn("eslint-plugin-jsdoc(require-param): Missing JSDoc `@param` declaration for function parameters.")
25+
.with_help("Add `@param` tag with name.")
26+
.and_label(span)
27+
}
28+
2329
#[derive(Debug, Default, Clone)]
2430
pub struct RequireParam(Box<RequireParamConfig>);
2531

@@ -162,7 +168,7 @@ impl Rule for RequireParam {
162168
let check_types_regex = Regex::new(config.check_types_pattern.as_str())
163169
.expect("`config.checkTypesPattern` should be a valid regex pattern");
164170

165-
let mut violations = vec![];
171+
// let mut violations = vec![];
166172
for (idx, param) in params_to_check.iter().enumerate() {
167173
match param {
168174
ParamKind::Single(param) => {
@@ -171,7 +177,9 @@ impl Rule for RequireParam {
171177
}
172178

173179
if !tags_to_check.iter().any(|(name, _)| **name == param.name) {
174-
violations.push(param.span);
180+
// violations.push(param.span);
181+
ctx.diagnostic(require_param_diagnostic(param.span));
182+
return;
175183
}
176184
}
177185
ParamKind::Nested(params) => {
@@ -226,24 +234,26 @@ impl Rule for RequireParam {
226234
.iter()
227235
.any(|(name, _)| is_name_equal(name, &full_param_name))
228236
{
229-
violations.push(param.span);
237+
// violations.push(param.span);
238+
ctx.diagnostic(require_param_diagnostic(param.span));
239+
return;
230240
}
231241
}
232242
}
233243
}
234244
}
235245

236-
if !violations.is_empty() {
237-
let labels = violations
238-
.iter()
239-
.map(|span| LabeledSpan::new_with_span(None, *span))
240-
.collect::<Vec<_>>();
241-
ctx.diagnostic(
242-
OxcDiagnostic::warn("eslint-plugin-jsdoc(require-param): Missing JSDoc `@param` declaration for function parameters.")
243-
.with_help("Add `@param` tag with name.")
244-
.with_labels(labels),
245-
);
246-
}
246+
// if !violations.is_empty() {
247+
// let labels = violations
248+
// .iter()
249+
// .map(|span| LabeledSpan::new_with_span(None, *span))
250+
// .collect::<Vec<_>>();
251+
// ctx.diagnostic(
252+
// OxcDiagnostic::warn("eslint-plugin-jsdoc(require-param): Missing JSDoc `@param` declaration for function parameters.")
253+
// .with_help("Add `@param` tag with name.")
254+
// .with_labels(labels),
255+
// );
256+
// }
247257
}
248258
}
249259

crates/oxc_linter/src/snapshots/require_param.snap

+15-15
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ expression: require_param
8787
╭─[require_param.tsx:5:31]
8888
4 │ */
8989
5 │ function quux ({ foo, bar: { baz }}) {
90-
· ─── ─────────────
90+
· ───
9191
6
9292
╰────
9393
help: Add `@param` tag with name.
@@ -96,7 +96,7 @@ expression: require_param
9696
╭─[require_param.tsx:5:30]
9797
4 │ */
9898
5 │ function quux ({foo}, {bar}) {
99-
· ─── ───
99+
· ───
100100
6
101101
╰────
102102
help: Add `@param` tag with name.
@@ -105,7 +105,7 @@ expression: require_param
105105
╭─[require_param.tsx:5:30]
106106
4 │ */
107107
5 │ function quux ({foo}, {bar}) {
108-
· ─── ───
108+
· ───
109109
6
110110
╰────
111111
help: Add `@param` tag with name.
@@ -114,7 +114,7 @@ expression: require_param
114114
╭─[require_param.tsx:5:30]
115115
4 │ */
116116
5 │ function quux ({foo}, {bar}) {
117-
· ─── ───
117+
· ───
118118
6
119119
╰────
120120
help: Add `@param` tag with name.
@@ -123,7 +123,7 @@ expression: require_param
123123
╭─[require_param.tsx:5:29]
124124
4 │ */
125125
5 │ function quux (foo, bar) {
126-
· ─── ───
126+
· ───
127127
6
128128
╰────
129129
help: Add `@param` tag with name.
@@ -141,7 +141,7 @@ expression: require_param
141141
╭─[require_param.tsx:5:29]
142142
4 │ */
143143
5 │ function quux (foo, bar, baz) {
144-
· ─── ───
144+
· ───
145145
6
146146
╰────
147147
help: Add `@param` tag with name.
@@ -159,7 +159,7 @@ expression: require_param
159159
╭─[require_param.tsx:5:29]
160160
4 │ */
161161
5 │ function quux (foo, bar, baz) {
162-
· ─── ───
162+
· ───
163163
6
164164
╰────
165165
help: Add `@param` tag with name.
@@ -222,7 +222,7 @@ expression: require_param
222222
╭─[require_param.tsx:5:26]
223223
4 │ */
224224
5 │ function quux ({bar, baz}, foo) {
225-
· ─── ─── ───
225+
· ───
226226
6 │ }
227227
╰────
228228
help: Add `@param` tag with name.
@@ -231,7 +231,7 @@ expression: require_param
231231
╭─[require_param.tsx:5:25]
232232
4 │ */
233233
5 │ function quux (foo, {bar, baz}) {
234-
· ─── ─── ───
234+
· ───
235235
6 │ }
236236
╰────
237237
help: Add `@param` tag with name.
@@ -240,7 +240,7 @@ expression: require_param
240240
╭─[require_param.tsx:5:26]
241241
4 │ */
242242
5 │ function quux ([bar, baz], foo) {
243-
· ─── ─── ───
243+
· ───
244244
6 │ }
245245
╰────
246246
help: Add `@param` tag with name.
@@ -339,7 +339,7 @@ expression: require_param
339339
╭─[require_param.tsx:6:39]
340340
5 │ */
341341
6 │ const bboxToObj = function ({x, y, width, height}) {
342-
· ─ ─ ───── ──────
342+
· ─
343343
7return {x, y, width, height};
344344
╰────
345345
help: Add `@param` tag with name.
@@ -348,7 +348,7 @@ expression: require_param
348348
╭─[require_param.tsx:6:39]
349349
5 │ */
350350
6 │ const bboxToObj = function ({x, y, width, height}) {
351-
· ─ ─ ───── ──────
351+
· ─
352352
7return {x, y, width, height};
353353
╰────
354354
help: Add `@param` tag with name.
@@ -357,7 +357,7 @@ expression: require_param
357357
╭─[require_param.tsx:7:23]
358358
6 │ */
359359
7 │ fetch = ({ url, ...options }, cacheKey) => {
360-
· ─── ───────
360+
· ───
361361
8 │ }
362362
╰────
363363
help: Add `@param` tag with name.
@@ -393,7 +393,7 @@ expression: require_param
393393
╭─[require_param.tsx:7:27]
394394
6 │ */
395395
7 │ function quux ({ foo: { bar } }) {}
396-
· ────────────
396+
· ────────────
397397
8
398398
╰────
399399
help: Add `@param` tag with name.
@@ -420,7 +420,7 @@ expression: require_param
420420
╭─[require_param.tsx:3:25]
421421
2 │ /** Foo. */
422422
3 │ function foo(a, b, c) {}
423-
· ─ ─ ─
423+
· ─
424424
4
425425
╰────
426426
help: Add `@param` tag with name.

0 commit comments

Comments
 (0)