Skip to content

Commit 58ca186

Browse files
committed
fix(match-description): tighten default regex to require punctuation at the end even if only a single character
1 parent 3b61dcc commit 58ca186

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

.README/rules/match-description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The default is this basic expression to match English sentences (Support
66
for Unicode upper case may be added in a future version when it can be handled
77
by our supported Node versions):
88

9-
``^([A-Z]|[`\\d_])([\\s\\S]*[.?!`])?$``
9+
``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
1010

1111
#### Options
1212

README.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,7 @@ The default is this basic expression to match English sentences (Support
22852285
for Unicode upper case may be added in a future version when it can be handled
22862286
by our supported Node versions):
22872287

2288-
``^([A-Z]|[`\\d_])([\\s\\S]*[.?!`])?$``
2288+
``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
22892289

22902290
<a name="eslint-plugin-jsdoc-rules-match-description-options-1"></a>
22912291
#### Options
@@ -2400,7 +2400,7 @@ function quux () {
24002400
// Message: JSDoc description does not satisfy the regex pattern.
24012401

24022402
/**
2403-
* тест.
2403+
* Abc.
24042404
*/
24052405
function quux () {
24062406

@@ -2563,6 +2563,33 @@ class quux {
25632563
// Options: [{"contexts":["ClassDeclaration"],"noDefaults":true}]
25642564
>>>>>>> feat(match-description): allow `main description: string|boolean` to override or disable main description separate from default
25652565
// Message: JSDoc description does not satisfy the regex pattern.
2566+
2567+
class MyClass {
2568+
/**
2569+
* Abc
2570+
*/
2571+
myClassField = 1
2572+
}
2573+
// Options: [{"contexts":["ClassProperty"],"noDefaults":true}]
2574+
// Message: JSDoc description does not satisfy the regex pattern.
2575+
2576+
/**
2577+
* foo.
2578+
*/
2579+
interface quux {
2580+
2581+
}
2582+
// Options: [{"contexts":["TSInterfaceDeclaration"],"noDefaults":true}]
2583+
// Message: JSDoc description does not satisfy the regex pattern.
2584+
2585+
const myObject = {
2586+
/**
2587+
* Bad description
2588+
*/
2589+
myProp: true
2590+
};
2591+
// Options: [{"contexts":["Property"],"noDefaults":true}]
2592+
// Message: JSDoc description does not satisfy the regex pattern.
25662593
````
25672594

25682595
The following patterns are not considered problems:
@@ -2715,6 +2742,30 @@ class quux {
27152742

27162743
}
27172744
// Options: [{"tags":{"main description":true}}]
2745+
2746+
class MyClass {
2747+
/**
2748+
* Abc.
2749+
*/
2750+
myClassField = 1
2751+
}
2752+
// Options: [{"contexts":["ClassProperty"],"noDefaults":true}]
2753+
2754+
/**
2755+
* Foo.
2756+
*/
2757+
interface quux {
2758+
2759+
}
2760+
// Options: [{"contexts":["TSInterfaceDeclaration"],"noDefaults":true}]
2761+
2762+
const myObject = {
2763+
/**
2764+
* Bad description
2765+
*/
2766+
myProp: true
2767+
};
2768+
// Options: [{"contexts":[],"noDefaults":true}]
27182769
````
27192770

27202771

@@ -3523,6 +3574,7 @@ interface quux {
35233574
}
35243575
// Options: [{"contexts":["TSInterfaceDeclaration"],"noDefaults":true}]
35253576
// Message: Missing JSDoc @description declaration.
3577+
<<<<<<< HEAD
35263578

35273579
/**
35283580
*
@@ -3541,6 +3593,8 @@ var quux = {
35413593
};
35423594
// Options: [{"contexts":["ObjectExpression"]}]
35433595
// Message: Missing JSDoc @description declaration.
3596+
=======
3597+
>>>>>>> fix(match-description): tighten default regex to require punctuation at the end even if only a single character
35443598
````
35453599

35463600
The following patterns are not considered problems:
@@ -3602,6 +3656,7 @@ function quux () {
36023656
interface quux {
36033657

36043658
}
3659+
<<<<<<< HEAD
36053660

36063661
/**
36073662
*
@@ -3616,6 +3671,9 @@ var quux = class {
36163671
var quux = {
36173672

36183673
};
3674+
=======
3675+
// Message: Missing JSDoc @description declaration.
3676+
>>>>>>> fix(match-description): tighten default regex to require punctuation at the end even if only a single character
36193677
````
36203678

36213679

@@ -3883,6 +3941,11 @@ be checked by the rule.
38833941
- `FunctionExpression`
38843942
- `MethodDefinition`
38853943

3944+
- `contexts` - Set this to a string or array of strings representing the additional
3945+
AST context where you wish the rule to be applied (e.g., `Property` for properties).
3946+
Note that unlike `require-description` and `match-description`, this rule has no
3947+
`noDefaults` option because its defaults are instead set up by `require`.
3948+
38863949
|||
38873950
|---|---|
38883951
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`|
@@ -4214,6 +4277,12 @@ export function someMethod() {
42144277
}
42154278
// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
42164279
// Message: Missing JSDoc comment.
4280+
4281+
const myObject = {
4282+
myProp: true
4283+
};
4284+
// Options: [{"contexts":["Property"]}]
4285+
// Message: Missing JSDoc comment.
42174286
````
42184287

42194288
The following patterns are not considered problems:
@@ -4683,6 +4752,11 @@ exports.someMethod = function() {
46834752

46844753
}
46854754
// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
4755+
4756+
const myObject = {
4757+
myProp: true
4758+
};
4759+
// Options: [{"contexts":[]}]
46864760
````
46874761

46884762

src/rules/matchDescription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default iterateJsdoc(({
2323

2424
// If supporting Node >= 10, we could loosen to this for the
2525
// initial letter: \\p{Upper}
26-
) || '^[A-Z`\\d_](?:[\\s\\S]*[.?!`])?$',
26+
) || '^[A-Z`\\d_][\\s\\S]*[.?!`]$',
2727
'u'
2828
);
2929

0 commit comments

Comments
 (0)