Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,27 @@ fn test() {
None,
None,
),
(
"
/**
* @license bcrypt.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
* Released under the Apache License, Version 2.0
*/
function quux () { }
",
None,
None,
),
(
"
/**
* @see Uses @vue/shared package
*/
function quux () { }
",
None,
None,
),
];

let fail = vec![
Expand Down
13 changes: 9 additions & 4 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ line2
#[test]
fn jsdoc_comment() {
for (source_text, parsed, span_text, tag_len) in [
("/** single line @k1 c1 @k2 */", "single line", " single line ", 2),
(
"/** single line @k1 c1 @k2 */",
"single line @k1 c1 @k2",
" single line @k1 c1 @k2 ",
0,
),
(
"/**
* multi
Expand Down Expand Up @@ -162,9 +167,9 @@ line2
"
/** ハロー @comment だよ*/
",
"ハロー",
" ハロー ",
1,
"ハロー @comment だよ",
" ハロー @comment だよ",
0,
),
] {
let allocator = Allocator::default();
Expand Down
31 changes: 1 addition & 30 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ mod test {
#[test]
fn jsdoc_tag_span() {
for (source_text, tag_span_text) in [
(
"
/**
* multi
* line @k1 c1
*/
",
"@k1 c1\n ",
),
(
"
/**
Expand All @@ -228,7 +219,6 @@ mod test {
",
"@k3 c3\n ",
),
("/** single line @k4 c4 */", "@k4 c4 "),
(
"
/**
Expand Down Expand Up @@ -257,8 +247,6 @@ mod test {
#[test]
fn jsdoc_tag_kind() {
for (source_text, tag_kind, tag_kind_span_text) in [
("/** single line @k1 c1 */", "k1", "@k1"),
("/** single line @k2*/", "k2", "@k2"),
(
"/**
* multi
Expand All @@ -269,16 +257,8 @@ mod test {
"k3",
"@k3",
),
(
"/**
* multi
* line @k4
*/",
"k4",
"@k4",
),
(" /**@*/ ", "", "@"),
(" /**@@*/ ", "", "@"),
(" /**@@*/ ", "@", "@@"),
(" /** @あいう え */ ", "あいう", "@あいう"),
] {
let allocator = Allocator::default();
Expand All @@ -294,8 +274,6 @@ mod test {
#[test]
fn jsdoc_tag_comment() {
for (source_text, parsed_comment_part) in [
("/** single line @k1 c1 */", ("c1", " c1 ")),
("/** single line @k2*/", ("", "")),
(
"/**
* multi
Expand All @@ -305,13 +283,6 @@ mod test {
*/",
("c3a\nc3b", " c3a\n * c3b\n "),
),
(
"/**
* multi
* line @k4
*/",
("", "\n "),
),
("/**@k5 c5 w/ {@inline}!*/", ("c5 w/ {@inline}!", " c5 w/ {@inline}!")),
(" /**@k6 */ ", ("", " ")),
(" /**@*/ ", ("", "")),
Expand Down
19 changes: 18 additions & 1 deletion crates/oxc_semantic/src/jsdoc/parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ pub fn parse_jsdoc(
let mut in_double_quotes = false;
let mut in_single_quotes = false;

// Tracks whether we're at the logical start of a line.
// Only `@` at the start of a line (after optional whitespace and `*` markers)
// should be treated as a new tag. This prevents false positives from `@` in
// email addresses (e.g. `user@example.com`) or npm scoped packages
// (e.g. `@vue/shared`) appearing mid-line in tag descriptions.
let mut at_line_start = true;

// This flag tells us if we have already found the main comment block.
// The first part before any @tags is considered the comment. Everything after is a tag.
let mut comment_found = false;
Expand Down Expand Up @@ -89,7 +96,7 @@ pub fn parse_jsdoc(
'[' => square_brace_depth += 1,
']' => square_brace_depth = square_brace_depth.saturating_sub(1),

'@' if can_parse => {
'@' if can_parse && at_line_start => {
let part = &source_text[start..end];
let span = Span::new(
jsdoc_span_start + u32::try_from(start).unwrap_or_default(),
Expand All @@ -110,6 +117,16 @@ pub fn parse_jsdoc(
_ => {}
}

// Update line-start tracking:
// - `\n` resets to true (new line)
// - Whitespace and `*` preserve true (JSDoc line leaders like ` * `)
// - Everything else sets to false
if ch == '\n' {
at_line_start = true;
} else if at_line_start && !matches!(ch, ' ' | '\t' | '\r' | '*') {
at_line_start = false;
}

// Move the `end` pointer forward by the character's length
end += ch.len_utf8();
}
Expand Down
Loading