From cc031b8c6a9653a5420857e5b186277baedf94f7 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 2 Apr 2022 12:30:04 +0800 Subject: [PATCH] fix(`no-restricted-syntax`): include `comment` in templates and in default error message if present --- README.md | 4 ++-- src/rules/noRestrictedSyntax.js | 4 +++- test/rules/assertions/noRestrictedSyntax.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b81e00ab1..8bf058b9a 100644 --- a/README.md +++ b/README.md @@ -9328,7 +9328,7 @@ function quux () { } // "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}] -// Message: Syntax is restricted: FunctionDeclaration. +// Message: Syntax is restricted: FunctionDeclaration /** * @@ -9346,7 +9346,7 @@ function quux () { } // "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration"}]}] -// Message: Syntax is restricted: FunctionDeclaration. +// Message: Syntax is restricted: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Bar"]:nth-child(1)) /** * @implements {Bar|Foo} diff --git a/src/rules/noRestrictedSyntax.js b/src/rules/noRestrictedSyntax.js index f442b5bff..789842ba0 100644 --- a/src/rules/noRestrictedSyntax.js +++ b/src/rules/noRestrictedSyntax.js @@ -36,9 +36,11 @@ export default iterateJsdoc(({ foundContext.context ?? 'any' : foundContext; const message = foundContext?.message ?? - 'Syntax is restricted: {{context}}.'; + 'Syntax is restricted: {{context}}' + + (comment ? ' with {{comment}}' : ''); report(message, null, null, { + comment, context: contextStr, }); }, { diff --git a/test/rules/assertions/noRestrictedSyntax.js b/test/rules/assertions/noRestrictedSyntax.js index 29135a30a..a1fcc73f1 100644 --- a/test/rules/assertions/noRestrictedSyntax.js +++ b/test/rules/assertions/noRestrictedSyntax.js @@ -12,7 +12,7 @@ export default { errors: [ { line: 2, - message: 'Syntax is restricted: FunctionDeclaration.', + message: 'Syntax is restricted: FunctionDeclaration', }, ], options: [ @@ -61,7 +61,7 @@ export default { errors: [ { line: 2, - message: 'Syntax is restricted: FunctionDeclaration.', + message: 'Syntax is restricted: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Bar"]:nth-child(1))', }, ], options: [