diff --git a/package.json b/package.json index 385f30701..bc36d7c0a 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@babel/plugin-transform-flow-strip-types": "^7.16.7", "@babel/preset-env": "^7.16.11", "@babel/register": "^7.17.7", + "@es-joy/jsdoc-eslint-parser": "^0.8.2", "@hkdobrev/run-if-changed": "^0.3.1", "@typescript-eslint/parser": "^5.17.0", "babel-plugin-add-module-exports": "^1.0.4", diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index 14882a476..538e23a2a 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -1271,7 +1271,6 @@ export default function iterateJsdoc (iterator, ruleConfig) { const checkJsdoc = (info, handler, node) => { const jsdocNode = getJSDocComment(sourceCode, node, settings); - if (!jsdocNode) { return; } diff --git a/src/rules/noMissingSyntax.js b/src/rules/noMissingSyntax.js index bbebbebaf..e217d7877 100644 --- a/src/rules/noMissingSyntax.js +++ b/src/rules/noMissingSyntax.js @@ -25,6 +25,7 @@ export default iterateJsdoc(({ info: { comment, }, + sourceCode, state, }) => { if (!context.options[0]) { @@ -38,8 +39,12 @@ export default iterateJsdoc(({ const foundContext = contexts.find((cntxt) => { return typeof cntxt === 'string' ? - esquery.matches(node, esquery.parse(cntxt)) : - (!cntxt.context || cntxt.context === 'any' || esquery.matches(node, esquery.parse(cntxt.context))) && + esquery.matches(node, esquery.parse(cntxt), null, { + visitorKeys: sourceCode.visitorKeys, + }) : + (!cntxt.context || cntxt.context === 'any' || esquery.matches(node, esquery.parse(cntxt.context), null, { + visitorKeys: sourceCode.visitorKeys, + })) && comment === cntxt.comment; }); diff --git a/src/rules/noRestrictedSyntax.js b/src/rules/noRestrictedSyntax.js index 789842ba0..fedbdffd5 100644 --- a/src/rules/noRestrictedSyntax.js +++ b/src/rules/noRestrictedSyntax.js @@ -7,6 +7,7 @@ export default iterateJsdoc(({ info: { comment, }, + sourceCode, report, }) => { if (!context.options.length) { @@ -21,8 +22,12 @@ export default iterateJsdoc(({ const foundContext = contexts.find((cntxt) => { return typeof cntxt === 'string' ? - esquery.matches(node, esquery.parse(cntxt)) : - (!cntxt.context || cntxt.context === 'any' || esquery.matches(node, esquery.parse(cntxt.context))) && + esquery.matches(node, esquery.parse(cntxt), null, { + visitorKeys: sourceCode.visitorKeys, + }) : + (!cntxt.context || cntxt.context === 'any' || esquery.matches(node, esquery.parse(cntxt.context), null, { + visitorKeys: sourceCode.visitorKeys, + })) && comment === cntxt.comment; }); diff --git a/test/rules/assertions/noRestrictedSyntax.js b/test/rules/assertions/noRestrictedSyntax.js index a1fcc73f1..c3f084ade 100644 --- a/test/rules/assertions/noRestrictedSyntax.js +++ b/test/rules/assertions/noRestrictedSyntax.js @@ -347,6 +347,31 @@ export default { }, ], }, + { + code: ` + class a { + /** */ + private b () {} + } + `, + errors: [ + { + line: 3, + message: 'Syntax is restricted: MethodDefinition:not([accessibility="public"]):has(JsdocBlock)', + }, + ], + ignoreReadme: true, + options: [ + { + contexts: [ + { + context: 'MethodDefinition:not([accessibility="public"]):has(JsdocBlock)', + }, + ], + }, + ], + parser: require.resolve('@es-joy/jsdoc-eslint-parser/typescript'), + }, ], valid: [ {