Skip to content

Commit

Permalink
fix(match-description): adjust default to allow for trailing whites…
Browse files Browse the repository at this point in the history
…pace but do check for such WS now

BREAKING CHANGE:

`match-description` regular expressions now need to take account for trailing whitespace
  • Loading branch information
brettz9 committed Mar 11, 2022
1 parent 26c1c2c commit a31a8fd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .README/rules/match-description.md
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions README.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

/**
Expand All @@ -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.

/**
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions src/rules/matchDescription.js
Expand Up @@ -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' ?
Expand Down Expand Up @@ -68,9 +68,7 @@ export default iterateJsdoc(({
const {
description,
} = utils.getDescription();
validateDescription(
description.replace(/\s+$/u, ''),
);
validateDescription(description);
}

if (!tags || !Object.keys(tags).length) {
Expand Down
26 changes: 24 additions & 2 deletions test/rules/assertions/matchDescription.js
Expand Up @@ -446,7 +446,7 @@ export default {
],
options: [
{
mainDescription: '^[a-zA-Z]*$',
mainDescription: '^[a-zA-Z]*\\s*$',
tags: {
param: true,
},
Expand All @@ -473,7 +473,7 @@ export default {
options: [
{
mainDescription: {
match: '^[a-zA-Z]*$',
match: '^[a-zA-Z]*\\s*$',
message: 'Letters only',
},
tags: {
Expand Down Expand Up @@ -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: [
{
Expand Down

0 comments on commit a31a8fd

Please sign in to comment.