Skip to content

Commit

Permalink
fix(no-restricted-syntax, no-missing-syntax): pass on parser's `v…
Browse files Browse the repository at this point in the history
…isitorKeys` to esquery

Also:
- test(`no-restricted-syntax`): use custom parser to include JsdocBlock reference in main `context`
  • Loading branch information
brettz9 committed Apr 2, 2022
1 parent cc031b8 commit f873e32
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/iterateJsdoc.js
Expand Up @@ -1271,7 +1271,6 @@ export default function iterateJsdoc (iterator, ruleConfig) {

const checkJsdoc = (info, handler, node) => {
const jsdocNode = getJSDocComment(sourceCode, node, settings);

if (!jsdocNode) {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions src/rules/noMissingSyntax.js
Expand Up @@ -25,6 +25,7 @@ export default iterateJsdoc(({
info: {
comment,
},
sourceCode,
state,
}) => {
if (!context.options[0]) {
Expand All @@ -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;
});

Expand Down
9 changes: 7 additions & 2 deletions src/rules/noRestrictedSyntax.js
Expand Up @@ -7,6 +7,7 @@ export default iterateJsdoc(({
info: {
comment,
},
sourceCode,
report,
}) => {
if (!context.options.length) {
Expand All @@ -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;
});

Expand Down
25 changes: 25 additions & 0 deletions test/rules/assertions/noRestrictedSyntax.js
Expand Up @@ -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: [
{
Expand Down

0 comments on commit f873e32

Please sign in to comment.