Skip to content

Commit b215b6c

Browse files
committed
fix(semantic): dont parse @ as jsdoc tags inside [/] (#10919)
fixes #10910 ``` × eslint-plugin-jsdoc(check-tag-names): Invalid tag name found. ╭─[index.ts:3:14] 2 │ /** 3 │ * @see [@parcel/watcher](https://github.com/parcel-bundler/watcher) · ─────────────────────────────────────────────────────────── 4 │ */ ╰──── help: `@parcel/watcher](https://github.com/parcel-bundler/watcher)` is invalid tag name. ``` `@see` was being parsed as a tag and `@parcel/watcher](https://github.com/parcel-bundler/watcher)` as another tag. I fixed this by checking if we are in `[` or `]`
1 parent a033c1e commit b215b6c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ fn test() {
562562
])),
563563
None,
564564
),
565+
// https://github.com/oxc-project/oxc/issues/10910
566+
(
567+
"
568+
/**
569+
* @see [@parcel/watcher](https://github.com/parcel-bundler/watcher)
570+
*/
571+
function quux (foo) { }
572+
",
573+
Some(serde_json::json!([ { "definedTags": [] } ])),
574+
None,
575+
),
565576
];
566577

567578
let fail = vec![

crates/oxc_semantic/src/jsdoc/parser/parse.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn parse_jsdoc(source_text: &str, jsdoc_span_start: u32) -> (JSDocCommentPar
2222
// So, find `@` to split comment and each tag.
2323
// But `@` can be found inside of `{}` (e.g. `{@see link}`), it should be distinguished.
2424
let mut in_braces = false;
25+
let mut in_square_braces = false;
2526
// Also, `@` is often found inside of backtick(` or ```), like markdown.
2627
let mut in_backticks = false;
2728
let mut comment_found = false;
@@ -30,7 +31,7 @@ pub fn parse_jsdoc(source_text: &str, jsdoc_span_start: u32) -> (JSDocCommentPar
3031

3132
let mut chars = source_text.chars().peekable();
3233
while let Some(ch) = chars.next() {
33-
let can_parse = !(in_braces || in_backticks);
34+
let can_parse = !(in_braces || in_backticks || in_square_braces);
3435
match ch {
3536
// NOTE: For now, only odd backtick(s) are handled.
3637
// - 1 backtick: inline code
@@ -45,6 +46,8 @@ pub fn parse_jsdoc(source_text: &str, jsdoc_span_start: u32) -> (JSDocCommentPar
4546
}
4647
'{' => in_braces = true,
4748
'}' => in_braces = false,
49+
'[' => in_square_braces = true,
50+
']' => in_square_braces = false,
4851
'@' if can_parse => {
4952
let part = &source_text[start..end];
5053
let span = Span::new(

0 commit comments

Comments
 (0)