88 stringify as commentStringify ,
99 util ,
1010} from 'comment-parser' ;
11+ import esquery from 'esquery' ;
1112
1213/**
1314 * @typedef {number } Integer
@@ -26,7 +27,8 @@ import {
2627 * tags?: string[],
2728 * replacement?: string,
2829 * minimum?: Integer,
29- * message?: string
30+ * message?: string,
31+ * forceRequireReturn?: boolean
3032 * }} ContextObject
3133 */
3234/**
@@ -467,6 +469,16 @@ import {
467469 * @returns {boolean }
468470 */
469471
472+ /**
473+ * @callback FindContext
474+ * @param {Context[] } contexts
475+ * @param {string|undefined } comment
476+ * @returns {{
477+ * foundContext: Context|undefined,
478+ * contextStr: string
479+ * }}
480+ */
481+
470482/**
471483 * @typedef {BasicUtils & {
472484 * isIteratingFunction: IsIteratingFunction,
@@ -526,7 +538,8 @@ import {
526538 * hasOptionTag: HasOptionTag,
527539 * getClassNode: GetClassNode,
528540 * getClassJsdoc: GetClassJsdoc,
529- * classHasTag: ClassHasTag
541+ * classHasTag: ClassHasTag,
542+ * findContext: FindContext
530543 * }} Utils
531544 */
532545
@@ -1712,6 +1725,39 @@ const getUtils = (
17121725 }
17131726 } ;
17141727
1728+ /** @type {FindContext } */
1729+ utils . findContext = ( contexts , comment ) => {
1730+ const foundContext = contexts . find ( ( cntxt ) => {
1731+ return typeof cntxt === 'string' ?
1732+ esquery . matches (
1733+ /** @type {Node } */ ( node ) ,
1734+ esquery . parse ( cntxt ) ,
1735+ undefined ,
1736+ {
1737+ visitorKeys : sourceCode . visitorKeys ,
1738+ } ,
1739+ ) :
1740+ ( ! cntxt . context || cntxt . context === 'any' ||
1741+ esquery . matches (
1742+ /** @type {Node } */ ( node ) ,
1743+ esquery . parse ( cntxt . context ) ,
1744+ undefined ,
1745+ {
1746+ visitorKeys : sourceCode . visitorKeys ,
1747+ } ,
1748+ ) ) && comment === cntxt . comment ;
1749+ } ) ;
1750+
1751+ const contextStr = typeof foundContext === 'object' ?
1752+ foundContext . context ?? 'any' :
1753+ String ( foundContext ) ;
1754+
1755+ return {
1756+ contextStr,
1757+ foundContext,
1758+ } ;
1759+ } ;
1760+
17151761 return utils ;
17161762} ;
17171763
@@ -1938,7 +1984,6 @@ const makeReport = (context, commentNode) => {
19381984 * @param {JsdocBlockWithInline } jsdoc
19391985 * @param {RuleConfig } ruleConfig
19401986 * @param {import('eslint').Rule.RuleContext } context
1941- * @param {string[] } lines
19421987 * @param {import('@es-joy/jsdoccomment').Token } jsdocNode
19431988 * @param {Node|null } node
19441989 * @param {Settings } settings
@@ -1951,7 +1996,7 @@ const makeReport = (context, commentNode) => {
19511996const iterate = (
19521997 info ,
19531998 indent , jsdoc ,
1954- ruleConfig , context , lines , jsdocNode , node , settings ,
1999+ ruleConfig , context , jsdocNode , node , settings ,
19552000 sourceCode , iterator , state , iteratingAll ,
19562001) => {
19572002 const jsdocNde = /** @type {unknown } */ ( jsdocNode ) ;
@@ -2145,7 +2190,6 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
21452190 jsdoc ,
21462191 ruleConfig ,
21472192 context ,
2148- lines ,
21492193 jsdocNode ,
21502194 /** @type {Node } */
21512195 ( node ) ,
@@ -2188,7 +2232,6 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
21882232 jsdoc ,
21892233 ruleConfig ,
21902234 context ,
2191- lines ,
21922235 jsdocNode ,
21932236 node ,
21942237 /** @type {Settings } */
@@ -2448,7 +2491,6 @@ export default function iterateJsdoc (iterator, ruleConfig) {
24482491 jsdoc ,
24492492 ruleConfig ,
24502493 context ,
2451- lines ,
24522494 jsdocNode ,
24532495 node ,
24542496 settings ,
0 commit comments