diff --git a/.README/rules/match-description.md b/.README/rules/match-description.md index 207d65f45..b60bb9384 100644 --- a/.README/rules/match-description.md +++ b/.README/rules/match-description.md @@ -6,7 +6,7 @@ The default is this basic expression to match English sentences (Support for Unicode upper case may be added in a future version when it can be handled by our supported Node versions): -``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]\\s*$`` +``^\n?([A-Z`\\d_][\\s\\S]*[.?!`]\\s*)?$`` Applies to the jsdoc block description and `@description` (or `@desc`) by default but the `tags` option (see below) may be used to match other tags. diff --git a/README.md b/README.md index c051fa251..7077bd8e0 100644 --- a/README.md +++ b/README.md @@ -6608,7 +6608,7 @@ The default is this basic expression to match English sentences (Support for Unicode upper case may be added in a future version when it can be handled by our supported Node versions): -``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]\\s*$`` +``^\n?([A-Z`\\d_][\\s\\S]*[.?!`]\\s*)?$`` Applies to the jsdoc block description and `@description` (or `@desc`) by default but the `tags` option (see below) may be used to match other tags. @@ -8528,6 +8528,8 @@ function quux () { /* */ +/** */ + /* @custom */ // "jsdoc/no-bad-blocks": ["error"|"warn", {"ignore":["custom"]}] @@ -8539,6 +8541,8 @@ function quux () { function quux (foo) { } + +/***/ ```` @@ -10049,6 +10053,10 @@ class Foo { /****/ +/* */ + +/*** */ + /** * */ diff --git a/package.json b/package.json index 21ad2ff42..da33792eb 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "url": "http://gajus.com" }, "dependencies": { - "@es-joy/jsdoccomment": "~0.21.2", - "comment-parser": "1.3.0", - "debug": "^4.3.3", + "@es-joy/jsdoccomment": "~0.22.0", + "comment-parser": "1.3.1", + "debug": "^4.3.4", "escape-string-regexp": "^4.0.0", "esquery": "^1.4.0", "regextras": "^0.8.0", @@ -17,15 +17,15 @@ "description": "JSDoc linting rules for ESLint.", "devDependencies": { "@babel/cli": "^7.17.6", - "@babel/core": "^7.17.5", + "@babel/core": "^7.17.8", "@babel/eslint-parser": "^7.17.0", "@babel/node": "^7.16.8", "@babel/plugin-syntax-class-properties": "^7.12.13", "@babel/plugin-transform-flow-strip-types": "^7.16.7", "@babel/preset-env": "^7.16.11", - "@babel/register": "^7.17.0", + "@babel/register": "^7.17.7", "@hkdobrev/run-if-changed": "^0.3.1", - "@typescript-eslint/parser": "^5.14.0", + "@typescript-eslint/parser": "^5.15.0", "babel-plugin-add-module-exports": "^1.0.4", "babel-plugin-istanbul": "^6.1.1", "camelcase": "^6.3.0", @@ -37,7 +37,7 @@ "gitdown": "^3.1.5", "glob": "^7.2.0", "husky": "^7.0.4", - "lint-staged": "^12.3.5", + "lint-staged": "^12.3.7", "lodash.defaultsdeep": "^4.6.1", "mocha": "^9.2.2", "nyc": "^15.1.0", diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index f732c08ad..82ac1549f 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -1,5 +1,3 @@ -/* eslint-disable jsdoc/valid-types */ - import { getReducedASTNode, getJSDocComment, @@ -284,7 +282,13 @@ const getUtils = ( utils.addTag = ( targetTagName, - number = (jsdoc.tags[jsdoc.tags.length - 1]?.source[0]?.number ?? 0) + 1, + number = (jsdoc.tags[jsdoc.tags.length - 1]?.source[0]?.number ?? jsdoc.source.findIndex(({ + tokens: { + tag, + }, + }) => { + return tag; + }) - 1) + 1, tokens = {}, ) => { jsdoc.source.splice(number, 0, { diff --git a/src/rules/matchDescription.js b/src/rules/matchDescription.js index 9633cea97..60d31423a 100644 --- a/src/rules/matchDescription.js +++ b/src/rules/matchDescription.js @@ -2,7 +2,7 @@ import iterateJsdoc from '../iterateJsdoc'; // If supporting Node >= 10, we could loosen the default to this for the // initial letter: \\p{Upper} -const matchDescriptionDefault = '^[A-Z`\\d_][\\s\\S]*[.?!`]\\s*$'; +const matchDescriptionDefault = '^\n?([A-Z`\\d_][\\s\\S]*[.?!`]\\s*)?$'; const stringOrDefault = (value, userDefault) => { return typeof value === 'string' ? diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index 4268612fd..9abfab8ab 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -74,7 +74,7 @@ export default iterateJsdoc(({ const typedefDeclarations = context.getAllComments() .filter((comment) => { - return comment.value.startsWith('*'); + return (/^\*\s/u).test(comment.value); }) .map((commentNode) => { return parseComment(commentNode, ''); diff --git a/src/rules/requireDescriptionCompleteSentence.js b/src/rules/requireDescriptionCompleteSentence.js index 0d2536418..4cc0c7a53 100644 --- a/src/rules/requireDescriptionCompleteSentence.js +++ b/src/rules/requireDescriptionCompleteSentence.js @@ -74,7 +74,7 @@ const validateDescription = ( description, reportOrig, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd, ) => { - if (!description) { + if (!description || (/^\n+$/u).test(description)) { return false; } diff --git a/test/rules/assertions/noBadBlocks.js b/test/rules/assertions/noBadBlocks.js index 9cdbc2bbb..06ac28c7c 100644 --- a/test/rules/assertions/noBadBlocks.js +++ b/test/rules/assertions/noBadBlocks.js @@ -222,6 +222,9 @@ export default { { code: '/* */', }, + { + code: '/** */', + }, { code: '/* @custom */', options: [ @@ -244,5 +247,8 @@ export default { } `, }, + { + code: '/***/', + }, ], }; diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index c5cd6c848..352d2f153 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -812,6 +812,10 @@ export default { code: ` /****/ + /* */ + + /*** */ + /** * */ diff --git a/test/rules/assertions/requireExample.js b/test/rules/assertions/requireExample.js index ccfc31d8d..0e8451df6 100644 --- a/test/rules/assertions/requireExample.js +++ b/test/rules/assertions/requireExample.js @@ -17,6 +17,7 @@ export default { ], output: ` /** + * * @example */ function quux () { @@ -46,6 +47,7 @@ export default { ], output: ` /** + * * @example */ function quux (someParam) { @@ -68,6 +70,7 @@ function quux () { }, ], output: `/** + * * @example */ function quux () { @@ -157,6 +160,7 @@ function quux () { ], output: ` /** + * * @example */ class quux { @@ -185,6 +189,7 @@ function quux () { ], output: ` /** + * * @example */ `, @@ -212,6 +217,7 @@ function quux () { ], output: ` /** + * * @example */ function quux () { @@ -241,6 +247,7 @@ function quux () { output: ` class TestClass { /** + * * @example */ get Test() { } @@ -291,6 +298,7 @@ function quux () { output: ` class TestClass { /** + * * @example */ set Test(value) { } diff --git a/test/rules/assertions/requireParam.js b/test/rules/assertions/requireParam.js index a176b7c18..6b075198d 100644 --- a/test/rules/assertions/requireParam.js +++ b/test/rules/assertions/requireParam.js @@ -23,6 +23,7 @@ export default { ], output: ` /** + * * @param foo */ function quux (foo) { @@ -54,6 +55,7 @@ export default { ], output: ` /** + * * @param foo */ function quux (foo) { @@ -82,6 +84,7 @@ export default { ], output: ` /** + * * @param root0 * @param root0.foo */ @@ -209,6 +212,7 @@ export default { ], output: ` /** + * * @param root0 * @param root0.foo */ @@ -379,6 +383,7 @@ export default { ], output: ` /** + * * @param arg0 * @param arg0.foo * @param arg1 @@ -425,6 +430,7 @@ export default { ], output: ` /** + * * @param arg * @param arg.foo * @param config0 @@ -472,6 +478,7 @@ export default { ], output: ` /** + * * @param arg * @param arg.foo */ @@ -501,6 +508,7 @@ export default { ], output: ` /** + * * @param foo * @param bar */ @@ -844,6 +852,7 @@ export default { */ class A { /** + * * @param foo */ quux (foo) { @@ -883,6 +892,7 @@ export default { */ class A { /** + * * @param foo */ quux (foo) { @@ -922,6 +932,7 @@ export default { */ class A { /** + * * @param foo */ quux (foo) { @@ -961,6 +972,7 @@ export default { */ class A { /** + * * @param foo */ quux (foo) { @@ -995,6 +1007,7 @@ export default { */ class A { /** + * * @param foo */ quux (foo) { @@ -1083,6 +1096,7 @@ export default { ], output: ` /** + * * @param root0 * @param root0.bar * @param root0.baz @@ -1120,6 +1134,7 @@ export default { ], output: ` /** + * * @param foo * @param root0 * @param root0.bar @@ -1157,6 +1172,7 @@ export default { ], output: ` /** + * * @param root0 * @param root0."0" * @param root0."1" @@ -1189,6 +1205,7 @@ export default { ], output: ` /** + * * @param foo */ function quux (foo) { @@ -1393,6 +1410,7 @@ export default { declare class TestClass { /** + * * @param id */ TestMethod(id);