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
15 changes: 15 additions & 0 deletions crates/oxc_linter/src/rules/jsdoc/require_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,21 @@ fn test() {

}
", None, None),
(
"
/**
* @param md
*/
const component = (md) => {
md.renderer.rules.fence = (...args) => {
const [tokens, index] = args;
return tokens[index];
};
};
",
None,
None,
),
("
/**
* @param root0
Expand Down
15 changes: 15 additions & 0 deletions crates/oxc_linter/src/rules/jsdoc/require_returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ fn test() {
None,
None,
),
(
"
/**
* @param md
*/
const component = (md) => {
md.renderer.rules.fence = (...args) => {
const [tokens, index] = args;
return tokens[index];
};
};
",
None,
None,
),
(
"
/**
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/utils/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,20 @@ pub fn get_function_nearest_jsdoc_node<'a, 'b>(
semantic: &'b Semantic<'a>,
) -> Option<&'b AstNode<'a>> {
let mut current_node = node;
let source_function_id = node.id();
// Whether the node has attached JSDoc or not is determined by `JSDocBuilder`
while semantic.jsdoc().get_all_by_node(semantic.nodes(), current_node).is_none() {
// Tie-breaker, otherwise every loop will end at `Program` node!
// Maybe more checks should be added
match current_node.kind() {
// Do not leak an outer function's JSDoc into nested function expressions.
// Keep walking only for the source function node itself, because function
// JSDoc can be attached on wrapper nodes like `VariableDeclaration`.
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_)
if current_node.id() != source_function_id =>
{
return None;
}
AstKind::Program(_) => return None,
AstKind::VariableDeclaration(_)
| AstKind::MethodDefinition(_)
Expand Down
Loading