Skip to content

Commit

Permalink
refactor: switch default mode to typescript; fixes #834
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
brettz9 committed May 7, 2023
1 parent 60c8d29 commit 055adf8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/rules/check-tag-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ function quux (foo) {}
* @template
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"jsdoc"}}
// Message: Invalid JSDoc tag name "internal".

/**
Expand Down
1 change: 1 addition & 0 deletions docs/rules/check-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ function foo(spec) {
}

foo()
// Settings: {"jsdoc":{"mode":"jsdoc"}}

/**
* @param {object} root
Expand Down
1 change: 1 addition & 0 deletions docs/rules/no-undefined-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class Foo {
bar (baz) {
}
}
// Settings: {"jsdoc":{"mode":"jsdoc"}}
// Message: The type 'TEMPLATE_TYPE_A' is undefined.

/**
Expand Down
1 change: 1 addition & 0 deletions docs/rules/valid-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 1 addition & 4 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions test/rules/assertions/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,11 @@ export default {
message: 'Invalid JSDoc tag name "template".',
},
],
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `${ONE_CLOSURE_TAGS_COMMENT}\nfunction quux (foo) {}`,
Expand Down
5 changes: 5 additions & 0 deletions test/rules/assertions/checkTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3073,6 +3073,11 @@ export default {
foo()
`,
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `
Expand Down
5 changes: 5 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ export default {
message: 'The type \'TEMPLATE_TYPE_B\' is undefined.',
},
],
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `
Expand Down
10 changes: 10 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ export default {
allowEmptyNamepaths: false,
},
],
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `
Expand Down Expand Up @@ -887,6 +892,11 @@ export default {
},
],
ignoreReadme: true,
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `
Expand Down

0 comments on commit 055adf8

Please sign in to comment.