From 5530e075354329fc95706d9950e76a465662caf1 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 26 Jan 2022 09:48:38 +0800 Subject: [PATCH] feat: update jsdoccomment; fixes #831 Includes: - feat: add non-visitable `endLine` property (so can detect line number when no description present) - fix: ensure `postName` gets a space for `@template` with a description - fix: converting JSDoc comment with tag on same line as end (e.g., single line) to AST - chore: update `jsdoc-type-pratt-parser` --- README.md | 7 ++++++ package.json | 2 +- test/rules/assertions/noRestrictedSyntax.js | 25 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07004f44f..448301892 100644 --- a/README.md +++ b/README.md @@ -9126,6 +9126,13 @@ const MY_ENUM = Object.freeze({ } as const); // "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag ~ JsdocTag[tag=/private|protected/])","context":"any","message":"Access modifier tags must come first"},{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[tag=\"enum\"])","context":":declaration","message":"@enum not allowed on declarations"}]}] // Message: @enum not allowed on declarations + +/** @type {React.FunctionComponent<{ children: React.ReactNode }>}*/ +const MyComponent = ({ children }) => { + return children; +} +// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[tag=\"type\"]:has([value=/FunctionComponent/]))","context":"any","message":"The `FunctionComponent` type is not allowed. Please use `FC` instead."}]}] +// Message: The `FunctionComponent` type is not allowed. Please use `FC` instead. ```` The following patterns are not considered problems: diff --git a/package.json b/package.json index e6caaf10c..e90dc6fc3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "url": "http://gajus.com" }, "dependencies": { - "@es-joy/jsdoccomment": "~0.17.0", + "@es-joy/jsdoccomment": "~0.18.0", "comment-parser": "1.3.0", "debug": "^4.3.3", "escape-string-regexp": "^4.0.0", diff --git a/test/rules/assertions/noRestrictedSyntax.js b/test/rules/assertions/noRestrictedSyntax.js index 14da66433..4bc120e97 100644 --- a/test/rules/assertions/noRestrictedSyntax.js +++ b/test/rules/assertions/noRestrictedSyntax.js @@ -322,6 +322,31 @@ export default { ], parser: require.resolve('@typescript-eslint/parser'), }, + { + code: ` + /** @type {React.FunctionComponent<{ children: React.ReactNode }>}*/ + const MyComponent = ({ children }) => { + return children; + } + `, + errors: [ + { + line: 2, + message: 'The `FunctionComponent` type is not allowed. Please use `FC` instead.', + }, + ], + options: [ + { + contexts: [ + { + comment: 'JsdocBlock:has(JsdocTag[tag="type"]:has([value=/FunctionComponent/]))', + context: 'any', + message: 'The `FunctionComponent` type is not allowed. Please use `FC` instead.', + }, + ], + }, + ], + }, ], valid: [ {