Skip to content

Commit

Permalink
fix(no-restricted-syntax): include comment in templates and in de…
Browse files Browse the repository at this point in the history
…fault error message if present
  • Loading branch information
brettz9 committed Apr 2, 2022
1 parent 0f27a91 commit cc031b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -9328,7 +9328,7 @@ function quux () {

}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
// Message: Syntax is restricted: FunctionDeclaration.
// Message: Syntax is restricted: FunctionDeclaration

/**
*
Expand All @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noRestrictedSyntax.js
Expand Up @@ -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,
});
}, {
Expand Down
4 changes: 2 additions & 2 deletions test/rules/assertions/noRestrictedSyntax.js
Expand Up @@ -12,7 +12,7 @@ export default {
errors: [
{
line: 2,
message: 'Syntax is restricted: FunctionDeclaration.',
message: 'Syntax is restricted: FunctionDeclaration',
},
],
options: [
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit cc031b8

Please sign in to comment.