eslint-plugin-jsdoc 48.0.0 → 48.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/package.json +2 -2
  2. package/src/WarnSettings.js +34 -0
  3. package/src/alignTransform.js +356 -0
  4. package/src/defaultTagOrder.js +168 -0
  5. package/src/exportParser.js +957 -0
  6. package/src/getDefaultTagStructureForMode.js +969 -0
  7. package/src/index.js +266 -0
  8. package/src/iterateJsdoc.js +2555 -0
  9. package/src/jsdocUtils.js +1693 -0
  10. package/src/rules/checkAccess.js +45 -0
  11. package/src/rules/checkAlignment.js +63 -0
  12. package/src/rules/checkExamples.js +594 -0
  13. package/src/rules/checkIndentation.js +75 -0
  14. package/src/rules/checkLineAlignment.js +364 -0
  15. package/src/rules/checkParamNames.js +404 -0
  16. package/src/rules/checkPropertyNames.js +152 -0
  17. package/src/rules/checkSyntax.js +30 -0
  18. package/src/rules/checkTagNames.js +314 -0
  19. package/src/rules/checkTypes.js +535 -0
  20. package/src/rules/checkValues.js +220 -0
  21. package/src/rules/emptyTags.js +88 -0
  22. package/src/rules/implementsOnClasses.js +64 -0
  23. package/src/rules/importsAsDependencies.js +131 -0
  24. package/src/rules/informativeDocs.js +182 -0
  25. package/src/rules/matchDescription.js +286 -0
  26. package/src/rules/matchName.js +147 -0
  27. package/src/rules/multilineBlocks.js +333 -0
  28. package/src/rules/noBadBlocks.js +109 -0
  29. package/src/rules/noBlankBlockDescriptions.js +69 -0
  30. package/src/rules/noBlankBlocks.js +53 -0
  31. package/src/rules/noDefaults.js +85 -0
  32. package/src/rules/noMissingSyntax.js +195 -0
  33. package/src/rules/noMultiAsterisks.js +134 -0
  34. package/src/rules/noRestrictedSyntax.js +91 -0
  35. package/src/rules/noTypes.js +73 -0
  36. package/src/rules/noUndefinedTypes.js +328 -0
  37. package/src/rules/requireAsteriskPrefix.js +189 -0
  38. package/src/rules/requireDescription.js +161 -0
  39. package/src/rules/requireDescriptionCompleteSentence.js +333 -0
  40. package/src/rules/requireExample.js +118 -0
  41. package/src/rules/requireFileOverview.js +154 -0
  42. package/src/rules/requireHyphenBeforeParamDescription.js +178 -0
  43. package/src/rules/requireJsdoc.js +629 -0
  44. package/src/rules/requireParam.js +592 -0
  45. package/src/rules/requireParamDescription.js +89 -0
  46. package/src/rules/requireParamName.js +55 -0
  47. package/src/rules/requireParamType.js +89 -0
  48. package/src/rules/requireProperty.js +48 -0
  49. package/src/rules/requirePropertyDescription.js +25 -0
  50. package/src/rules/requirePropertyName.js +25 -0
  51. package/src/rules/requirePropertyType.js +25 -0
  52. package/src/rules/requireReturns.js +238 -0
  53. package/src/rules/requireReturnsCheck.js +141 -0
  54. package/src/rules/requireReturnsDescription.js +59 -0
  55. package/src/rules/requireReturnsType.js +51 -0
  56. package/src/rules/requireThrows.js +111 -0
  57. package/src/rules/requireYields.js +216 -0
  58. package/src/rules/requireYieldsCheck.js +208 -0
  59. package/src/rules/sortTags.js +557 -0
  60. package/src/rules/tagLines.js +359 -0
  61. package/src/rules/textEscaping.js +146 -0
  62. package/src/rules/validTypes.js +368 -0
  63. package/src/tagNames.js +234 -0
  64. package/src/utils/hasReturnValue.js +549 -0
@@ -0,0 +1,45 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ const accessLevels = [
4
+ 'package', 'private', 'protected', 'public',
5
+ ];
6
+
7
+ export default iterateJsdoc(({
8
+ report,
9
+ utils,
10
+ }) => {
11
+ utils.forEachPreferredTag('access', (jsdocParameter, targetTagName) => {
12
+ const desc = jsdocParameter.name + ' ' + jsdocParameter.description;
13
+
14
+ if (!accessLevels.includes(desc.trim())) {
15
+ report(
16
+ `Missing valid JSDoc @${targetTagName} level.`,
17
+ null,
18
+ jsdocParameter,
19
+ );
20
+ }
21
+ });
22
+ const accessLength = utils.getTags('access').length;
23
+ const individualTagLength = utils.getPresentTags(accessLevels).length;
24
+ if (accessLength && individualTagLength) {
25
+ report(
26
+ 'The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).',
27
+ );
28
+ }
29
+
30
+ if (accessLength > 1 || individualTagLength > 1) {
31
+ report(
32
+ 'At most one access-control tag may be present on a jsdoc block.',
33
+ );
34
+ }
35
+ }, {
36
+ checkPrivate: true,
37
+ iterateAllJsdocs: true,
38
+ meta: {
39
+ docs: {
40
+ description: 'Checks that `@access` tags have a valid value.',
41
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-access.md#repos-sticky-header',
42
+ },
43
+ type: 'suggestion',
44
+ },
45
+ });
@@ -0,0 +1,63 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ /**
4
+ * @param {string} string
5
+ * @returns {string}
6
+ */
7
+ const trimStart = (string) => {
8
+ return string.replace(/^\s+/u, '');
9
+ };
10
+
11
+ export default iterateJsdoc(({
12
+ sourceCode,
13
+ jsdocNode,
14
+ report,
15
+ indent,
16
+ }) => {
17
+ // `indent` is whitespace from line 1 (`/**`), so slice and account for "/".
18
+ const indentLevel = indent.length + 1;
19
+ const sourceLines = sourceCode.getText(jsdocNode).split('\n')
20
+ .slice(1)
21
+ .map((line) => {
22
+ return line.split('*')[0];
23
+ })
24
+ .filter((line) => {
25
+ return !trimStart(line).length;
26
+ });
27
+
28
+ /** @type {import('eslint').Rule.ReportFixer} */
29
+ const fix = (fixer) => {
30
+ const replacement = sourceCode.getText(jsdocNode).split('\n')
31
+ .map((line, index) => {
32
+ // Ignore the first line and all lines not starting with `*`
33
+ const ignored = !index || trimStart(line.split('*')[0]).length;
34
+
35
+ return ignored ? line : `${indent} ${trimStart(line)}`;
36
+ })
37
+ .join('\n');
38
+
39
+ return fixer.replaceText(jsdocNode, replacement);
40
+ };
41
+
42
+ sourceLines.some((line, lineNum) => {
43
+ if (line.length !== indentLevel) {
44
+ report('Expected JSDoc block to be aligned.', fix, {
45
+ line: lineNum + 1,
46
+ });
47
+
48
+ return true;
49
+ }
50
+
51
+ return false;
52
+ });
53
+ }, {
54
+ iterateAllJsdocs: true,
55
+ meta: {
56
+ docs: {
57
+ description: 'Reports invalid alignment of JSDoc block asterisks.',
58
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-alignment.md#repos-sticky-header',
59
+ },
60
+ fixable: 'code',
61
+ type: 'layout',
62
+ },
63
+ });
@@ -0,0 +1,594 @@
1
+ // Todo: When replace `CLIEngine` with `ESLint` when feature set complete per https://github.com/eslint/eslint/issues/14745
2
+ // https://github.com/eslint/eslint/blob/master/docs/user-guide/migrating-to-7.0.0.md#-the-cliengine-class-has-been-deprecated
3
+ import iterateJsdoc from '../iterateJsdoc.js';
4
+ import eslint, {
5
+ ESLint,
6
+ } from 'eslint';
7
+ import semver from 'semver';
8
+
9
+ const {
10
+ // @ts-expect-error Older ESLint
11
+ CLIEngine,
12
+ } = eslint;
13
+
14
+ const zeroBasedLineIndexAdjust = -1;
15
+ const likelyNestedJSDocIndentSpace = 1;
16
+ const preTagSpaceLength = 1;
17
+
18
+ // If a space is present, we should ignore it
19
+ const firstLinePrefixLength = preTagSpaceLength;
20
+
21
+ const hasCaptionRegex = /^\s*<caption>([\s\S]*?)<\/caption>/u;
22
+
23
+ /**
24
+ * @param {string} str
25
+ * @returns {string}
26
+ */
27
+ const escapeStringRegexp = (str) => {
28
+ return str.replaceAll(/[.*+?^${}()|[\]\\]/gu, '\\$&');
29
+ };
30
+
31
+ /**
32
+ * @param {string} str
33
+ * @param {string} ch
34
+ * @returns {import('../iterateJsdoc.js').Integer}
35
+ */
36
+ const countChars = (str, ch) => {
37
+ return (str.match(new RegExp(escapeStringRegexp(ch), 'gu')) || []).length;
38
+ };
39
+
40
+ /** @type {import('eslint').Linter.RulesRecord} */
41
+ const defaultMdRules = {
42
+ // "always" newline rule at end unlikely in sample code
43
+ 'eol-last': 0,
44
+
45
+ // Wouldn't generally expect example paths to resolve relative to JS file
46
+ 'import/no-unresolved': 0,
47
+
48
+ // Snippets likely too short to always include import/export info
49
+ 'import/unambiguous': 0,
50
+
51
+ 'jsdoc/require-file-overview': 0,
52
+
53
+ // The end of a multiline comment would end the comment the example is in.
54
+ 'jsdoc/require-jsdoc': 0,
55
+
56
+ // Unlikely to have inadvertent debugging within examples
57
+ 'no-console': 0,
58
+
59
+ // Often wish to start `@example` code after newline; also may use
60
+ // empty lines for spacing
61
+ 'no-multiple-empty-lines': 0,
62
+
63
+ // Many variables in examples will be `undefined`
64
+ 'no-undef': 0,
65
+
66
+ // Common to define variables for clarity without always using them
67
+ 'no-unused-vars': 0,
68
+
69
+ // See import/no-unresolved
70
+ 'node/no-missing-import': 0,
71
+ 'node/no-missing-require': 0,
72
+
73
+ // Can generally look nicer to pad a little even if code imposes more stringency
74
+ 'padded-blocks': 0,
75
+ };
76
+
77
+ /** @type {import('eslint').Linter.RulesRecord} */
78
+ const defaultExpressionRules = {
79
+ ...defaultMdRules,
80
+ 'chai-friendly/no-unused-expressions': 'off',
81
+ 'no-empty-function': 'off',
82
+ 'no-new': 'off',
83
+ 'no-unused-expressions': 'off',
84
+ quotes: [
85
+ 'error', 'double',
86
+ ],
87
+ semi: [
88
+ 'error', 'never',
89
+ ],
90
+ strict: 'off',
91
+ };
92
+
93
+ /**
94
+ * @param {string} text
95
+ * @returns {[
96
+ * import('../iterateJsdoc.js').Integer,
97
+ * import('../iterateJsdoc.js').Integer
98
+ * ]}
99
+ */
100
+ const getLinesCols = (text) => {
101
+ const matchLines = countChars(text, '\n');
102
+
103
+ const colDelta = matchLines ?
104
+ text.slice(text.lastIndexOf('\n') + 1).length :
105
+ text.length;
106
+
107
+ return [
108
+ matchLines, colDelta,
109
+ ];
110
+ };
111
+
112
+ export default iterateJsdoc(({
113
+ report,
114
+ utils,
115
+ context,
116
+ globalState,
117
+ }) => {
118
+ if (semver.gte(ESLint.version, '8.0.0')) {
119
+ report(
120
+ 'This rule cannot yet be supported for ESLint 8; you ' +
121
+ 'should either downgrade to ESLint 7 or disable this rule. The ' +
122
+ 'possibility for ESLint 8 support is being tracked at https://github.com/eslint/eslint/issues/14745',
123
+ null,
124
+ {
125
+ column: 1,
126
+ line: 1,
127
+ },
128
+ );
129
+
130
+ return;
131
+ }
132
+
133
+ if (!globalState.has('checkExamples-matchingFileName')) {
134
+ globalState.set('checkExamples-matchingFileName', new Map());
135
+ }
136
+
137
+ const matchingFileNameMap = /** @type {Map<string, string>} */ (
138
+ globalState.get('checkExamples-matchingFileName')
139
+ );
140
+
141
+ const options = context.options[0] || {};
142
+ let {
143
+ exampleCodeRegex = null,
144
+ rejectExampleCodeRegex = null,
145
+ } = options;
146
+ const {
147
+ checkDefaults = false,
148
+ checkParams = false,
149
+ checkProperties = false,
150
+ noDefaultExampleRules = false,
151
+ checkEslintrc = true,
152
+ matchingFileName = null,
153
+ matchingFileNameDefaults = null,
154
+ matchingFileNameParams = null,
155
+ matchingFileNameProperties = null,
156
+ paddedIndent = 0,
157
+ baseConfig = {},
158
+ configFile,
159
+ allowInlineConfig = true,
160
+ reportUnusedDisableDirectives = true,
161
+ captionRequired = false,
162
+ } = options;
163
+
164
+ // Make this configurable?
165
+ /**
166
+ * @type {never[]}
167
+ */
168
+ const rulePaths = [];
169
+
170
+ const mdRules = noDefaultExampleRules ? undefined : defaultMdRules;
171
+
172
+ const expressionRules = noDefaultExampleRules ? undefined : defaultExpressionRules;
173
+
174
+ if (exampleCodeRegex) {
175
+ exampleCodeRegex = utils.getRegexFromString(exampleCodeRegex);
176
+ }
177
+
178
+ if (rejectExampleCodeRegex) {
179
+ rejectExampleCodeRegex = utils.getRegexFromString(rejectExampleCodeRegex);
180
+ }
181
+
182
+ /**
183
+ * @param {{
184
+ * filename: string,
185
+ * defaultFileName: string|undefined,
186
+ * source: string,
187
+ * targetTagName: string,
188
+ * rules?: import('eslint').Linter.RulesRecord|undefined,
189
+ * lines?: import('../iterateJsdoc.js').Integer,
190
+ * cols?: import('../iterateJsdoc.js').Integer,
191
+ * skipInit?: boolean,
192
+ * sources?: {
193
+ * nonJSPrefacingCols: import('../iterateJsdoc.js').Integer,
194
+ * nonJSPrefacingLines: import('../iterateJsdoc.js').Integer,
195
+ * string: string,
196
+ * }[],
197
+ * tag?: import('comment-parser').Spec & {
198
+ * line?: import('../iterateJsdoc.js').Integer,
199
+ * }|{
200
+ * line: import('../iterateJsdoc.js').Integer,
201
+ * }
202
+ * }} cfg
203
+ */
204
+ const checkSource = ({
205
+ filename,
206
+ defaultFileName,
207
+ rules = expressionRules,
208
+ lines = 0,
209
+ cols = 0,
210
+ skipInit,
211
+ source,
212
+ targetTagName,
213
+ sources = [],
214
+ tag = {
215
+ line: 0,
216
+ },
217
+ }) => {
218
+ if (!skipInit) {
219
+ sources.push({
220
+ nonJSPrefacingCols: cols,
221
+ nonJSPrefacingLines: lines,
222
+ string: source,
223
+ });
224
+ }
225
+
226
+ // Todo: Make fixable
227
+
228
+ /**
229
+ * @param {{
230
+ * nonJSPrefacingCols: import('../iterateJsdoc.js').Integer,
231
+ * nonJSPrefacingLines: import('../iterateJsdoc.js').Integer,
232
+ * string: string
233
+ * }} cfg
234
+ */
235
+ const checkRules = function ({
236
+ nonJSPrefacingCols,
237
+ nonJSPrefacingLines,
238
+ string,
239
+ }) {
240
+ const cliConfig = {
241
+ allowInlineConfig,
242
+ baseConfig,
243
+ configFile,
244
+ reportUnusedDisableDirectives,
245
+ rulePaths,
246
+ rules,
247
+ useEslintrc: checkEslintrc,
248
+ };
249
+ const cliConfigStr = JSON.stringify(cliConfig);
250
+
251
+ const src = paddedIndent ?
252
+ string.replaceAll(new RegExp(`(^|\n) {${paddedIndent}}(?!$)`, 'gu'), '\n') :
253
+ string;
254
+
255
+ // Programmatic ESLint API: https://eslint.org/docs/developer-guide/nodejs-api
256
+ const fileNameMapKey = filename ?
257
+ 'a' + cliConfigStr + filename :
258
+ 'b' + cliConfigStr + defaultFileName;
259
+ const file = filename || defaultFileName;
260
+ let cliFile;
261
+ if (matchingFileNameMap.has(fileNameMapKey)) {
262
+ cliFile = matchingFileNameMap.get(fileNameMapKey);
263
+ } else {
264
+ const cli = new CLIEngine(cliConfig);
265
+ let config;
266
+ if (filename || checkEslintrc) {
267
+ config = cli.getConfigForFile(file);
268
+ }
269
+
270
+ // We need a new instance to ensure that the rules that may only
271
+ // be available to `file` (if it has its own `.eslintrc`),
272
+ // will be defined.
273
+ cliFile = new CLIEngine({
274
+ allowInlineConfig,
275
+ baseConfig: {
276
+ ...baseConfig,
277
+ ...config,
278
+ },
279
+ configFile,
280
+ reportUnusedDisableDirectives,
281
+ rulePaths,
282
+ rules,
283
+ useEslintrc: false,
284
+ });
285
+ matchingFileNameMap.set(fileNameMapKey, cliFile);
286
+ }
287
+
288
+ const {
289
+ results: [
290
+ {
291
+ messages,
292
+ },
293
+ ],
294
+ } = cliFile.executeOnText(src);
295
+
296
+ if (!('line' in tag)) {
297
+ tag.line = tag.source[0].number;
298
+ }
299
+
300
+ // NOTE: `tag.line` can be 0 if of form `/** @tag ... */`
301
+ const codeStartLine = /**
302
+ * @type {import('comment-parser').Spec & {
303
+ * line: import('../iterateJsdoc.js').Integer,
304
+ * }}
305
+ */ (tag).line + nonJSPrefacingLines;
306
+ const codeStartCol = likelyNestedJSDocIndentSpace;
307
+
308
+ for (const {
309
+ message,
310
+ line,
311
+ column,
312
+ severity,
313
+ ruleId,
314
+ } of messages) {
315
+ const startLine = codeStartLine + line + zeroBasedLineIndexAdjust;
316
+ const startCol = codeStartCol + (
317
+
318
+ // This might not work for line 0, but line 0 is unlikely for examples
319
+ line <= 1 ? nonJSPrefacingCols + firstLinePrefixLength : preTagSpaceLength
320
+ ) + column;
321
+
322
+ report(
323
+ '@' + targetTagName + ' ' + (severity === 2 ? 'error' : 'warning') +
324
+ (ruleId ? ' (' + ruleId + ')' : '') + ': ' +
325
+ message,
326
+ null,
327
+ {
328
+ column: startCol,
329
+ line: startLine,
330
+ },
331
+ );
332
+ }
333
+ };
334
+
335
+ for (const targetSource of sources) {
336
+ checkRules(targetSource);
337
+ }
338
+ };
339
+
340
+ /**
341
+ *
342
+ * @param {string} filename
343
+ * @param {string} [ext] Since `eslint-plugin-markdown` v2, and
344
+ * ESLint 7, this is the default which other JS-fenced rules will used.
345
+ * Formerly "md" was the default.
346
+ * @returns {{defaultFileName: string|undefined, filename: string}}
347
+ */
348
+ const getFilenameInfo = (filename, ext = 'md/*.js') => {
349
+ let defaultFileName;
350
+ if (!filename) {
351
+ const jsFileName = context.getFilename();
352
+ if (typeof jsFileName === 'string' && jsFileName.includes('.')) {
353
+ defaultFileName = jsFileName.replace(/\.[^.]*$/u, `.${ext}`);
354
+ } else {
355
+ defaultFileName = `dummy.${ext}`;
356
+ }
357
+ }
358
+
359
+ return {
360
+ defaultFileName,
361
+ filename,
362
+ };
363
+ };
364
+
365
+ if (checkDefaults) {
366
+ const filenameInfo = getFilenameInfo(matchingFileNameDefaults, 'jsdoc-defaults');
367
+ utils.forEachPreferredTag('default', (tag, targetTagName) => {
368
+ if (!tag.description.trim()) {
369
+ return;
370
+ }
371
+
372
+ checkSource({
373
+ source: `(${utils.getTagDescription(tag)})`,
374
+ targetTagName,
375
+ ...filenameInfo,
376
+ });
377
+ });
378
+ }
379
+
380
+ if (checkParams) {
381
+ const filenameInfo = getFilenameInfo(matchingFileNameParams, 'jsdoc-params');
382
+ utils.forEachPreferredTag('param', (tag, targetTagName) => {
383
+ if (!tag.default || !tag.default.trim()) {
384
+ return;
385
+ }
386
+
387
+ checkSource({
388
+ source: `(${tag.default})`,
389
+ targetTagName,
390
+ ...filenameInfo,
391
+ });
392
+ });
393
+ }
394
+
395
+ if (checkProperties) {
396
+ const filenameInfo = getFilenameInfo(matchingFileNameProperties, 'jsdoc-properties');
397
+ utils.forEachPreferredTag('property', (tag, targetTagName) => {
398
+ if (!tag.default || !tag.default.trim()) {
399
+ return;
400
+ }
401
+
402
+ checkSource({
403
+ source: `(${tag.default})`,
404
+ targetTagName,
405
+ ...filenameInfo,
406
+ });
407
+ });
408
+ }
409
+
410
+ const tagName = /** @type {string} */ (utils.getPreferredTagName({
411
+ tagName: 'example',
412
+ }));
413
+ if (!utils.hasTag(tagName)) {
414
+ return;
415
+ }
416
+
417
+ const matchingFilenameInfo = getFilenameInfo(matchingFileName);
418
+
419
+ utils.forEachPreferredTag('example', (tag, targetTagName) => {
420
+ let source = /** @type {string} */ (utils.getTagDescription(tag));
421
+ const match = source.match(hasCaptionRegex);
422
+
423
+ if (captionRequired && (!match || !match[1].trim())) {
424
+ report('Caption is expected for examples.', null, tag);
425
+ }
426
+
427
+ source = source.replace(hasCaptionRegex, '');
428
+ const [
429
+ lines,
430
+ cols,
431
+ ] = match ? getLinesCols(match[0]) : [
432
+ 0, 0,
433
+ ];
434
+
435
+ if (exampleCodeRegex && !exampleCodeRegex.test(source) ||
436
+ rejectExampleCodeRegex && rejectExampleCodeRegex.test(source)
437
+ ) {
438
+ return;
439
+ }
440
+
441
+ const sources = [];
442
+ let skipInit = false;
443
+ if (exampleCodeRegex) {
444
+ let nonJSPrefacingCols = 0;
445
+ let nonJSPrefacingLines = 0;
446
+
447
+ let startingIndex = 0;
448
+ let lastStringCount = 0;
449
+
450
+ let exampleCode;
451
+ exampleCodeRegex.lastIndex = 0;
452
+ while ((exampleCode = exampleCodeRegex.exec(source)) !== null) {
453
+ const {
454
+ index,
455
+ '0': n0,
456
+ '1': n1,
457
+ } = exampleCode;
458
+
459
+ // Count anything preceding user regex match (can affect line numbering)
460
+ const preMatch = source.slice(startingIndex, index);
461
+
462
+ const [
463
+ preMatchLines,
464
+ colDelta,
465
+ ] = getLinesCols(preMatch);
466
+
467
+ let nonJSPreface;
468
+ let nonJSPrefaceLineCount;
469
+ if (n1) {
470
+ const idx = n0.indexOf(n1);
471
+ nonJSPreface = n0.slice(0, idx);
472
+ nonJSPrefaceLineCount = countChars(nonJSPreface, '\n');
473
+ } else {
474
+ nonJSPreface = '';
475
+ nonJSPrefaceLineCount = 0;
476
+ }
477
+
478
+ nonJSPrefacingLines += lastStringCount + preMatchLines + nonJSPrefaceLineCount;
479
+
480
+ // Ignore `preMatch` delta if newlines here
481
+ if (nonJSPrefaceLineCount) {
482
+ const charsInLastLine = nonJSPreface.slice(nonJSPreface.lastIndexOf('\n') + 1).length;
483
+
484
+ nonJSPrefacingCols += charsInLastLine;
485
+ } else {
486
+ nonJSPrefacingCols += colDelta + nonJSPreface.length;
487
+ }
488
+
489
+ const string = n1 || n0;
490
+ sources.push({
491
+ nonJSPrefacingCols,
492
+ nonJSPrefacingLines,
493
+ string,
494
+ });
495
+ startingIndex = exampleCodeRegex.lastIndex;
496
+ lastStringCount = countChars(string, '\n');
497
+ if (!exampleCodeRegex.global) {
498
+ break;
499
+ }
500
+ }
501
+
502
+ skipInit = true;
503
+ }
504
+
505
+ checkSource({
506
+ cols,
507
+ lines,
508
+ rules: mdRules,
509
+ skipInit,
510
+ source,
511
+ sources,
512
+ tag,
513
+ targetTagName,
514
+ ...matchingFilenameInfo,
515
+ });
516
+ });
517
+ }, {
518
+ iterateAllJsdocs: true,
519
+ meta: {
520
+ docs: {
521
+ description: 'Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.',
522
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-examples.md#repos-sticky-header',
523
+ },
524
+ schema: [
525
+ {
526
+ additionalProperties: false,
527
+ properties: {
528
+ allowInlineConfig: {
529
+ default: true,
530
+ type: 'boolean',
531
+ },
532
+ baseConfig: {
533
+ type: 'object',
534
+ },
535
+ captionRequired: {
536
+ default: false,
537
+ type: 'boolean',
538
+ },
539
+ checkDefaults: {
540
+ default: false,
541
+ type: 'boolean',
542
+ },
543
+ checkEslintrc: {
544
+ default: true,
545
+ type: 'boolean',
546
+ },
547
+ checkParams: {
548
+ default: false,
549
+ type: 'boolean',
550
+ },
551
+ checkProperties: {
552
+ default: false,
553
+ type: 'boolean',
554
+ },
555
+ configFile: {
556
+ type: 'string',
557
+ },
558
+ exampleCodeRegex: {
559
+ type: 'string',
560
+ },
561
+ matchingFileName: {
562
+ type: 'string',
563
+ },
564
+ matchingFileNameDefaults: {
565
+ type: 'string',
566
+ },
567
+ matchingFileNameParams: {
568
+ type: 'string',
569
+ },
570
+ matchingFileNameProperties: {
571
+ type: 'string',
572
+ },
573
+ noDefaultExampleRules: {
574
+ default: false,
575
+ type: 'boolean',
576
+ },
577
+ paddedIndent: {
578
+ default: 0,
579
+ type: 'integer',
580
+ },
581
+ rejectExampleCodeRegex: {
582
+ type: 'string',
583
+ },
584
+ reportUnusedDisableDirectives: {
585
+ default: true,
586
+ type: 'boolean',
587
+ },
588
+ },
589
+ type: 'object',
590
+ },
591
+ ],
592
+ type: 'suggestion',
593
+ },
594
+ });