Skip to content

Commit 3c39014

Browse files
committed
fix(check-examples): disallow empty caption (as with missing caption); fixes #330
1 parent 9e39914 commit 3c39014

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/rules/checkExamples.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import warnRemovedSettings from '../warnRemovedSettings';
66
const zeroBasedLineIndexAdjust = -1;
77
const likelyNestedJSDocIndentSpace = 1;
88
const preTagSpaceLength = 1;
9-
const hasCaptionRegex = /^\s*<caption>.*?<\/caption>/;
9+
const hasCaptionRegex = /^\s*<caption>(.*?)<\/caption>/;
1010

1111
const escapeStringRegexp = (str) => {
1212
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -81,7 +81,7 @@ export default iterateJsdoc(({
8181
let source = tag.source.slice(initialTagLength);
8282
const match = source.match(hasCaptionRegex);
8383

84-
if (captionRequired && !match) {
84+
if (captionRequired && (!match || !match[1].trim())) {
8585
report('Caption is expected for examples.', null, tag);
8686
}
8787

test/rules/assertions/checkExamples.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,24 @@ export default {
443443
reportUnusedDisableDirectives: true
444444
}
445445
}
446+
},
447+
{
448+
code: `
449+
/**
450+
* @typedef {string} Foo
451+
* @example <caption></caption>
452+
* 'foo'
453+
*/
454+
`,
455+
errors: [
456+
{
457+
message: 'Caption is expected for examples.'
458+
}
459+
],
460+
options: [{
461+
captionRequired: true,
462+
eslintrcForExamples: false
463+
}]
446464
}
447465
],
448466
valid: [

0 commit comments

Comments
 (0)