Skip to content

Commit 0e89cc8

Browse files
committed
fix(check-examples): only exclude optional initial space from description, not initial newline (needed for line counts, and rules)
Also updates tests to indicate expected line number
1 parent df83290 commit 0e89cc8

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ function quux2 () {
908908
function quux2 () {
909909

910910
}
911-
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
911+
// Message: @example error (no-multiple-empty-lines): Too many blank lines at the beginning of file. Max of 0 allowed.
912912

913913
/**
914914
* @example const i = 5;

src/iterateJsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const parseComment = (commentNode, indent, trim = true) => {
5454
}
5555

5656
// Tweak original regex to capture only single optional space
57-
const result = str.match(/^\s?((.|\s)+)?/u);
57+
const result = str.match(/^ ?((.|\s)+)?/u);
5858

5959
// Always has at least whitespace due to `indent` we've added
6060
/* istanbul ignore next */

test/rules/assertions/checkExamples.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ export default {
1111
`,
1212
errors: [
1313
{
14+
line: 3,
1415
message: '@example error (no-alert): Unexpected alert.',
1516
},
1617
{
18+
line: 3,
1719
message: '@example error (semi): Missing semicolon.',
1820
},
1921
],
@@ -38,9 +40,11 @@ export default {
3840
`,
3941
errors: [
4042
{
43+
line: 3,
4144
message: '@example error (no-alert): Unexpected alert.',
4245
},
4346
{
47+
line: 3,
4448
message: '@example error (semi): Missing semicolon.',
4549
},
4650
],
@@ -67,6 +71,7 @@ export default {
6771
`,
6872
errors: [
6973
{
74+
line: 4,
7075
message: '@example error (semi): Extra semicolon.',
7176
},
7277
],
@@ -93,6 +98,7 @@ export default {
9398
`,
9499
errors: [
95100
{
101+
line: 5,
96102
message: '@example error (semi): Extra semicolon.',
97103
},
98104
],
@@ -118,6 +124,7 @@ export default {
118124
`,
119125
errors: [
120126
{
127+
line: 4,
121128
message: '@example error (semi): Extra semicolon.',
122129
},
123130
],
@@ -143,6 +150,7 @@ export default {
143150
`,
144151
errors: [
145152
{
153+
line: 4,
146154
message: '@example error (semi): Extra semicolon.',
147155
},
148156
],
@@ -173,6 +181,7 @@ export default {
173181
`,
174182
errors: [
175183
{
184+
line: 9,
176185
message: '@example error (semi): Extra semicolon.',
177186
},
178187
],
@@ -198,6 +207,7 @@ export default {
198207
`,
199208
errors: [
200209
{
210+
line: 4,
201211
message: '@example error (no-undef): \'quux\' is not defined.',
202212
},
203213
],
@@ -226,6 +236,7 @@ export default {
226236
`,
227237
errors: [
228238
{
239+
line: 6,
229240
message: 'Caption is expected for examples.',
230241
},
231242
],
@@ -245,6 +256,7 @@ export default {
245256
`,
246257
errors: [
247258
{
259+
line: 3,
248260
message: '@example error (indent): Expected indentation of 0 spaces but found 1.',
249261
},
250262
],
@@ -267,6 +279,7 @@ export default {
267279
`,
268280
errors: [
269281
{
282+
line: 3,
270283
message: '@example error: Unused eslint-disable directive (no problems were reported from \'semi\').',
271284
},
272285
],
@@ -286,6 +299,7 @@ export default {
286299
`,
287300
errors: [
288301
{
302+
line: 4,
289303
message: '@example error (semi): Missing semicolon.',
290304
},
291305
],
@@ -312,9 +326,11 @@ export default {
312326
`,
313327
errors: [
314328
{
329+
line: 3,
315330
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
316331
},
317332
{
333+
line: 4,
318334
message: '@example error (semi): Missing semicolon.',
319335
},
320336
],
@@ -334,9 +350,11 @@ export default {
334350
`,
335351
errors: [
336352
{
353+
line: 3,
337354
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
338355
},
339356
{
357+
line: 4,
340358
message: '@example error (semi): Missing semicolon.',
341359
},
342360
],
@@ -359,9 +377,15 @@ export default {
359377
`,
360378
errors: [
361379
{
380+
line: 3,
381+
message: '@example error (no-multiple-empty-lines): Too many blank lines at the beginning of file. Max of 0 allowed.',
382+
},
383+
{
384+
line: 4,
362385
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
363386
},
364387
{
388+
line: 5,
365389
message: '@example error (semi): Missing semicolon.',
366390
},
367391
],
@@ -378,6 +402,7 @@ export default {
378402
`,
379403
errors: [
380404
{
405+
line: 4,
381406
message: '@example error (semi): Missing semicolon.',
382407
},
383408
],
@@ -398,6 +423,7 @@ export default {
398423
`,
399424
errors: [
400425
{
426+
line: 4,
401427
message: '@example warning (semi): Missing semicolon.',
402428
},
403429
],
@@ -423,33 +449,43 @@ export default {
423449
`,
424450
errors: [
425451
{
452+
line: 1,
426453
message: '`settings.jsdoc.captionRequired` has been removed, use options in the rule `check-examples` instead.',
427454
},
428455
{
456+
line: 1,
429457
message: '`settings.jsdoc.exampleCodeRegex` has been removed, use options in the rule `check-examples` instead.',
430458
},
431459
{
460+
line: 1,
432461
message: '`settings.jsdoc.rejectExampleCodeRegex` has been removed, use options in the rule `check-examples` instead.',
433462
},
434463
{
464+
line: 1,
435465
message: '`settings.jsdoc.allowInlineConfig` has been removed, use options in the rule `check-examples` instead.',
436466
},
437467
{
468+
line: 1,
438469
message: '`settings.jsdoc.noDefaultExampleRules` has been removed, use options in the rule `check-examples` instead.',
439470
},
440471
{
472+
line: 1,
441473
message: '`settings.jsdoc.matchingFileName` has been removed, use options in the rule `check-examples` instead.',
442474
},
443475
{
476+
line: 1,
444477
message: '`settings.jsdoc.configFile` has been removed, use options in the rule `check-examples` instead.',
445478
},
446479
{
480+
line: 1,
447481
message: '`settings.jsdoc.eslintrcForExamples` has been removed, use options in the rule `check-examples` instead.',
448482
},
449483
{
484+
line: 1,
450485
message: '`settings.jsdoc.baseConfig` has been removed, use options in the rule `check-examples` instead.',
451486
},
452487
{
488+
line: 1,
453489
message: '`settings.jsdoc.reportUnusedDisableDirectives` has been removed, use options in the rule `check-examples` instead.',
454490
},
455491
],
@@ -478,6 +514,7 @@ export default {
478514
`,
479515
errors: [
480516
{
517+
line: 4,
481518
message: 'Caption is expected for examples.',
482519
},
483520
],
@@ -499,6 +536,7 @@ export default {
499536
`,
500537
errors: [
501538
{
539+
line: 4,
502540
message: '@example error (semi): Missing semicolon.',
503541
},
504542
],

0 commit comments

Comments
 (0)