You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 00c1a4f
Browse filesBrowse the repository at this point in the historyBrowse files
The previous fallback used getCommentsBefore(classNode) directly, which
broke in two ways identified by reviewer haimuhaimu:
1. Node remapping: ESLint 9's SourceCode#getJSDocComment redirects
exported class declarations to their export parent and class
expressions to parent.parent. The fallback was calling getCommentsBefore
on the class node itself, returning [] for those patterns.
2. Adjacency & intervening comments: getCommentsBefore does not enforce
the 'at most one blank line' constraint. It also skips over line
comments (// ...) to pick an earlier JSDoc, incorrectly returning a
match where ESLint 9 would return null.
Fix mirrors ESLint's own ast-utils.js logic:
- isExportDeclaration(): detects export parent nodes for remapping
- findJSDocComment(): uses getTokenBefore(node, { includeComments: true })
with the line-adjacency check (gap <= 1)
- getFunctionExpressionJSDocTarget(): extracted helper for the
ArrowFunctionExpression/FunctionExpression parent-walk (also reduces
getJSDocComment cognitive complexity from 21 to ~9)
ESLint 5-9 users are unaffected: the getJSDocComment native path is
taken whenever typeof sourceCode.getJSDocComment === 'function'.
Tests: 14 contract validation cases covering plain ClassDeclaration,
exported declarations (Named + Default), ClassExpression via parent.parent
remapping, blank-line separation, intervening line comments, and the
ESLint 9 native path (available / null / throws).
0 commit comments