eslint-plugin-jsdoc 55.4.0 → 56.0.0

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