From 71e6ed0901a8a4189fe814cdf831365707cfab04 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 7 May 2023 14:31:01 -0700 Subject: [PATCH] refactor: switch default `mode` to `typescript`; fixes #834 BREAKING CHANGE: Users must now opt into adding `settings.jsdoc.mode` set to `"jsdoc"` if they want normal JSDoc mode. Note that "typescript" mode does not need to imply use of TypeScript syntax, but rather use of the TypeScript flavor within JSDoc comment blocks which holds the advantages of working in IDEs to draw in third-party module documentation and optionally allowing one to type check one's JavaScript code by TypeScript. There are also tools for building docs with this flavor (e.g., typedoc). --- docs/rules/check-tag-names.md | 1 + docs/rules/check-types.md | 1 + docs/rules/no-undefined-types.md | 1 + docs/rules/valid-types.md | 1 + src/iterateJsdoc.js | 5 +---- test/rules/assertions/checkTagNames.js | 5 +++++ test/rules/assertions/checkTypes.js | 5 +++++ test/rules/assertions/noUndefinedTypes.js | 5 +++++ test/rules/assertions/validTypes.js | 10 ++++++++++ 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/rules/check-tag-names.md b/docs/rules/check-tag-names.md index d3bc5cac7..b6c7282d9 100644 --- a/docs/rules/check-tag-names.md +++ b/docs/rules/check-tag-names.md @@ -720,6 +720,7 @@ function quux (foo) {} * @template */ function quux (foo) {} +// Settings: {"jsdoc":{"mode":"jsdoc"}} // Message: Invalid JSDoc tag name "internal". /** diff --git a/docs/rules/check-types.md b/docs/rules/check-types.md index b54ce34c7..ba4dbbe63 100644 --- a/docs/rules/check-types.md +++ b/docs/rules/check-types.md @@ -1179,6 +1179,7 @@ function foo(spec) { } foo() +// Settings: {"jsdoc":{"mode":"jsdoc"}} /** * @param {object} root diff --git a/docs/rules/no-undefined-types.md b/docs/rules/no-undefined-types.md index 760ccb029..05e774a73 100644 --- a/docs/rules/no-undefined-types.md +++ b/docs/rules/no-undefined-types.md @@ -201,6 +201,7 @@ class Foo { bar (baz) { } } +// Settings: {"jsdoc":{"mode":"jsdoc"}} // Message: The type 'TEMPLATE_TYPE_A' is undefined. /** diff --git a/docs/rules/valid-types.md b/docs/rules/valid-types.md index 05d8449d3..f0e9a739b 100644 --- a/docs/rules/valid-types.md +++ b/docs/rules/valid-types.md @@ -231,6 +231,7 @@ function quux() { * @this */ class Bar {}; +// Settings: {"jsdoc":{"mode":"jsdoc"}} // "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}] // Message: Tag @this must have either a type or namepath in "jsdoc" mode. diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index d41ab0fe3..245b93cd8 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -974,10 +974,7 @@ const getSettings = (context) => { exemptDestructuredRootsFromChecks: context.settings.jsdoc?.exemptDestructuredRootsFromChecks, // Many rules, e.g., `check-tag-names` - mode: context.settings.jsdoc?.mode ?? - (context.parserPath?.includes('@typescript-eslint') || - context.languageOptions?.parser?.meta?.name?.includes('typescript') ? - 'typescript' : 'jsdoc'), + mode: context.settings.jsdoc?.mode ?? 'typescript', // Many rules contexts: context.settings.jsdoc?.contexts, diff --git a/test/rules/assertions/checkTagNames.js b/test/rules/assertions/checkTagNames.js index 87b2864ab..d9b54910c 100644 --- a/test/rules/assertions/checkTagNames.js +++ b/test/rules/assertions/checkTagNames.js @@ -858,6 +858,11 @@ export default { message: 'Invalid JSDoc tag name "template".', }, ], + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, }, { code: `${ONE_CLOSURE_TAGS_COMMENT}\nfunction quux (foo) {}`, diff --git a/test/rules/assertions/checkTypes.js b/test/rules/assertions/checkTypes.js index 33aa941af..f4cb968ac 100644 --- a/test/rules/assertions/checkTypes.js +++ b/test/rules/assertions/checkTypes.js @@ -3073,6 +3073,11 @@ export default { foo() `, + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, }, { code: ` diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 808667070..d5ba59fc4 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -276,6 +276,11 @@ export default { message: 'The type \'TEMPLATE_TYPE_B\' is undefined.', }, ], + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, }, { code: ` diff --git a/test/rules/assertions/validTypes.js b/test/rules/assertions/validTypes.js index 3c825ca66..77d0cd65c 100644 --- a/test/rules/assertions/validTypes.js +++ b/test/rules/assertions/validTypes.js @@ -251,6 +251,11 @@ export default { allowEmptyNamepaths: false, }, ], + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, }, { code: ` @@ -887,6 +892,11 @@ export default { }, ], ignoreReadme: true, + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, }, { code: `