diff --git a/.README/rules/match-description.md b/.README/rules/match-description.md index 0b434276d..207d65f45 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]*[.?!`]$`` +``^([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 9a986a4f7..948d5d7a5 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]*[.?!`]$`` +``^([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. @@ -6960,7 +6960,7 @@ function quux (foo) { function quux (foo) { } -// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"^[a-zA-Z]*$","tags":{"param":true}}] +// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"^[a-zA-Z]*\\s*$","tags":{"param":true}}] // Message: JSDoc description does not satisfy the regex pattern. /** @@ -6971,7 +6971,7 @@ function quux (foo) { function quux (foo) { } -// "jsdoc/match-description": ["error"|"warn", {"mainDescription":{"match":"^[a-zA-Z]*$","message":"Letters only"},"tags":{"param":{"match":true,"message":"Needs to begin with a capital letter and end with a period."}}}] +// "jsdoc/match-description": ["error"|"warn", {"mainDescription":{"match":"^[a-zA-Z]*\\s*$","message":"Letters only"},"tags":{"param":{"match":true,"message":"Needs to begin with a capital letter and end with a period."}}}] // Message: Needs to begin with a capital letter and end with a period. /** @@ -7151,6 +7151,16 @@ function quux (foo) { } // Settings: {"jsdoc":{"tagNamePreference":{"description":false}}} // Message: JSDoc description does not satisfy the regex pattern. + +/** + * Description with extra new line + * + */ +function quux () { + +} +// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[\\s\\S]*\\S$"}] +// Message: JSDoc description does not satisfy the regex pattern. ```` The following patterns are not considered problems: diff --git a/src/rules/matchDescription.js b/src/rules/matchDescription.js index d63f877fe..8010f161c 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]*[.?!`]$'; +const matchDescriptionDefault = '^[A-Z`\\d_][\\s\\S]*[.?!`]\\s*$'; const stringOrDefault = (value, userDefault) => { return typeof value === 'string' ? @@ -68,9 +68,7 @@ export default iterateJsdoc(({ const { description, } = utils.getDescription(); - validateDescription( - description.replace(/\s+$/u, ''), - ); + validateDescription(description); } if (!tags || !Object.keys(tags).length) { diff --git a/test/rules/assertions/matchDescription.js b/test/rules/assertions/matchDescription.js index 5e5db9d2b..926d69b14 100644 --- a/test/rules/assertions/matchDescription.js +++ b/test/rules/assertions/matchDescription.js @@ -446,7 +446,7 @@ export default { ], options: [ { - mainDescription: '^[a-zA-Z]*$', + mainDescription: '^[a-zA-Z]*\\s*$', tags: { param: true, }, @@ -473,7 +473,7 @@ export default { options: [ { mainDescription: { - match: '^[a-zA-Z]*$', + match: '^[a-zA-Z]*\\s*$', message: 'Letters only', }, tags: { @@ -912,6 +912,28 @@ export default { }, }, }, + { + code: ` + /** + * Description with extra new line + * + */ + function quux () { + + } + `, + errors: [ + { + line: 3, + message: 'JSDoc description does not satisfy the regex pattern.', + }, + ], + options: [ + { + matchDescription: '[\\s\\S]*\\S$', + }, + ], + }, ], valid: [ {