eslint-plugin-jsdoc 52.0.3 → 52.0.4
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.
- package/dist/WarnSettings.cjs +35 -18
- package/dist/WarnSettings.cjs.map +1 -1
- package/dist/alignTransform.cjs +305 -224
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/defaultTagOrder.cjs +43 -132
- package/dist/defaultTagOrder.cjs.map +1 -1
- package/dist/exportParser.cjs +696 -478
- package/dist/exportParser.cjs.map +1 -1
- package/dist/generateRule.cjs +242 -0
- package/dist/generateRule.cjs.map +1 -0
- package/dist/getDefaultTagStructureForMode.cjs +288 -184
- package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.cjs +550 -364
- package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.d.ts +65 -68
- package/dist/getJsdocProcessorPlugin.d.ts.map +1 -1
- package/dist/index.cjs +383 -398
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/iterateJsdoc.cjs +1988 -1528
- package/dist/iterateJsdoc.cjs.map +1 -1
- package/dist/iterateJsdoc.d.ts +349 -358
- package/dist/iterateJsdoc.d.ts.map +1 -1
- package/dist/jsdocUtils.cjs +1376 -1009
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/rules/checkAccess.cjs +36 -29
- package/dist/rules/checkAccess.cjs.map +1 -1
- package/dist/rules/checkAlignment.cjs +54 -41
- package/dist/rules/checkAlignment.cjs.map +1 -1
- package/dist/rules/checkExamples.cjs +484 -327
- package/dist/rules/checkExamples.cjs.map +1 -1
- package/dist/rules/checkIndentation.cjs +65 -50
- package/dist/rules/checkIndentation.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.cjs +311 -220
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkParamNames.cjs +335 -227
- package/dist/rules/checkParamNames.cjs.map +1 -1
- package/dist/rules/checkPropertyNames.cjs +106 -78
- package/dist/rules/checkPropertyNames.cjs.map +1 -1
- package/dist/rules/checkSyntax.cjs +34 -21
- package/dist/rules/checkSyntax.cjs.map +1 -1
- package/dist/rules/checkTagNames.cjs +210 -188
- package/dist/rules/checkTagNames.cjs.map +1 -1
- package/dist/rules/checkTemplateNames.cjs +178 -121
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/checkTypes.cjs +385 -291
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkValues.cjs +146 -100
- package/dist/rules/checkValues.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.cjs +306 -228
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/emptyTags.cjs +72 -62
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/implementsOnClasses.cjs +56 -36
- package/dist/rules/implementsOnClasses.cjs.map +1 -1
- package/dist/rules/importsAsDependencies.cjs +99 -62
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/informativeDocs.cjs +142 -105
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +105 -70
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/matchDescription.cjs +222 -160
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchName.cjs +128 -73
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/multilineBlocks.cjs +352 -235
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.cjs +86 -63
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noBlankBlockDescriptions.cjs +57 -35
- package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -1
- package/dist/rules/noBlankBlocks.cjs +48 -26
- package/dist/rules/noBlankBlocks.cjs.map +1 -1
- package/dist/rules/noDefaults.cjs +79 -52
- package/dist/rules/noDefaults.cjs.map +1 -1
- package/dist/rules/noMissingSyntax.cjs +165 -115
- package/dist/rules/noMissingSyntax.cjs.map +1 -1
- package/dist/rules/noMultiAsterisks.cjs +89 -48
- package/dist/rules/noMultiAsterisks.cjs.map +1 -1
- package/dist/rules/noRestrictedSyntax.cjs +79 -45
- package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
- package/dist/rules/noTypes.cjs +80 -59
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/noUndefinedTypes.cjs +388 -297
- package/dist/rules/noUndefinedTypes.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.cjs +159 -108
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireDescription.cjs +129 -89
- package/dist/rules/requireDescription.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +262 -201
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireExample.cjs +104 -73
- package/dist/rules/requireExample.cjs.map +1 -1
- package/dist/rules/requireFileOverview.cjs +129 -75
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +133 -85
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireJsdoc.cjs +557 -384
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireParam.cjs +526 -336
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireParamDescription.cjs +80 -55
- package/dist/rules/requireParamDescription.cjs.map +1 -1
- package/dist/rules/requireParamName.cjs +50 -32
- package/dist/rules/requireParamName.cjs.map +1 -1
- package/dist/rules/requireParamType.cjs +80 -55
- package/dist/rules/requireParamType.cjs.map +1 -1
- package/dist/rules/requireProperty.cjs +42 -31
- package/dist/rules/requireProperty.cjs.map +1 -1
- package/dist/rules/requirePropertyDescription.cjs +25 -17
- package/dist/rules/requirePropertyDescription.cjs.map +1 -1
- package/dist/rules/requirePropertyName.cjs +25 -17
- package/dist/rules/requirePropertyName.cjs.map +1 -1
- package/dist/rules/requirePropertyType.cjs +25 -17
- package/dist/rules/requirePropertyType.cjs.map +1 -1
- package/dist/rules/requireReturns.cjs +203 -125
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.cjs +103 -60
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireReturnsDescription.cjs +54 -39
- package/dist/rules/requireReturnsDescription.cjs.map +1 -1
- package/dist/rules/requireReturnsType.cjs +50 -32
- package/dist/rules/requireReturnsType.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +178 -119
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/requireThrows.cjs +95 -61
- package/dist/rules/requireThrows.cjs.map +1 -1
- package/dist/rules/requireYields.cjs +166 -106
- package/dist/rules/requireYields.cjs.map +1 -1
- package/dist/rules/requireYieldsCheck.cjs +152 -96
- package/dist/rules/requireYieldsCheck.cjs.map +1 -1
- package/dist/rules/sortTags.cjs +444 -258
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules/tagLines.cjs +266 -179
- package/dist/rules/tagLines.cjs.map +1 -1
- package/dist/rules/textEscaping.cjs +127 -92
- package/dist/rules/textEscaping.cjs.map +1 -1
- package/dist/rules/validTypes.cjs +265 -252
- package/dist/rules/validTypes.cjs.map +1 -1
- package/dist/tagNames.cjs +170 -134
- package/dist/tagNames.cjs.map +1 -1
- package/dist/utils/hasReturnValue.cjs +474 -246
- package/dist/utils/hasReturnValue.cjs.map +1 -1
- package/package.json +24 -40
- package/src/WarnSettings.js +34 -0
- package/src/alignTransform.js +358 -0
- package/src/defaultTagOrder.js +169 -0
- package/src/exportParser.js +978 -0
- package/src/getDefaultTagStructureForMode.js +969 -0
- package/src/getJsdocProcessorPlugin.js +672 -0
- package/src/index.js +530 -0
- package/src/iterateJsdoc.js +2518 -0
- package/src/jsdocUtils.js +1896 -0
- package/src/rules/checkAccess.js +45 -0
- package/src/rules/checkAlignment.js +63 -0
- package/src/rules/checkExamples.js +589 -0
- package/src/rules/checkIndentation.js +75 -0
- package/src/rules/checkLineAlignment.js +372 -0
- package/src/rules/checkParamNames.js +474 -0
- package/src/rules/checkPropertyNames.js +152 -0
- package/src/rules/checkSyntax.js +30 -0
- package/src/rules/checkTagNames.js +314 -0
- package/src/rules/checkTemplateNames.js +204 -0
- package/src/rules/checkTypes.js +535 -0
- package/src/rules/checkValues.js +248 -0
- package/src/rules/convertToJsdocComments.js +398 -0
- package/src/rules/emptyTags.js +98 -0
- package/src/rules/implementsOnClasses.js +64 -0
- package/src/rules/importsAsDependencies.js +133 -0
- package/src/rules/informativeDocs.js +189 -0
- package/src/rules/linesBeforeBlock.js +134 -0
- package/src/rules/matchDescription.js +286 -0
- package/src/rules/matchName.js +151 -0
- package/src/rules/multilineBlocks.js +493 -0
- package/src/rules/noBadBlocks.js +119 -0
- package/src/rules/noBlankBlockDescriptions.js +69 -0
- package/src/rules/noBlankBlocks.js +53 -0
- package/src/rules/noDefaults.js +85 -0
- package/src/rules/noMissingSyntax.js +195 -0
- package/src/rules/noMultiAsterisks.js +134 -0
- package/src/rules/noRestrictedSyntax.js +91 -0
- package/src/rules/noTypes.js +93 -0
- package/src/rules/noUndefinedTypes.js +543 -0
- package/src/rules/requireAsteriskPrefix.js +190 -0
- package/src/rules/requireDescription.js +161 -0
- package/src/rules/requireDescriptionCompleteSentence.js +335 -0
- package/src/rules/requireExample.js +118 -0
- package/src/rules/requireFileOverview.js +154 -0
- package/src/rules/requireHyphenBeforeParamDescription.js +176 -0
- package/src/rules/requireJsdoc.js +743 -0
- package/src/rules/requireParam.js +602 -0
- package/src/rules/requireParamDescription.js +89 -0
- package/src/rules/requireParamName.js +55 -0
- package/src/rules/requireParamType.js +89 -0
- package/src/rules/requireProperty.js +48 -0
- package/src/rules/requirePropertyDescription.js +25 -0
- package/src/rules/requirePropertyName.js +25 -0
- package/src/rules/requirePropertyType.js +25 -0
- package/src/rules/requireReturns.js +238 -0
- package/src/rules/requireReturnsCheck.js +145 -0
- package/src/rules/requireReturnsDescription.js +59 -0
- package/src/rules/requireReturnsType.js +51 -0
- package/src/rules/requireTemplate.js +201 -0
- package/src/rules/requireThrows.js +111 -0
- package/src/rules/requireYields.js +216 -0
- package/src/rules/requireYieldsCheck.js +208 -0
- package/src/rules/sortTags.js +558 -0
- package/src/rules/tagLines.js +359 -0
- package/src/rules/textEscaping.js +154 -0
- package/src/rules/validTypes.js +401 -0
- package/src/tagNames.js +238 -0
- package/src/utils/hasReturnValue.js +572 -0
- package/dist/WarnSettings.js +0 -20
- package/dist/WarnSettings.js.map +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -32
- package/dist/_virtual/rolldown_runtime.js +0 -11
- package/dist/alignTransform.js +0 -241
- package/dist/alignTransform.js.map +0 -1
- package/dist/defaultTagOrder.js +0 -134
- package/dist/defaultTagOrder.js.map +0 -1
- package/dist/exportParser.js +0 -518
- package/dist/exportParser.js.map +0 -1
- package/dist/getDefaultTagStructureForMode.js +0 -188
- package/dist/getDefaultTagStructureForMode.js.map +0 -1
- package/dist/getJsdocProcessorPlugin.d.cts +0 -70
- package/dist/getJsdocProcessorPlugin.d.cts.map +0 -1
- package/dist/getJsdocProcessorPlugin.js +0 -383
- package/dist/getJsdocProcessorPlugin.js.map +0 -1
- package/dist/index.d.cts +0 -22
- package/dist/index.d.cts.map +0 -1
- package/dist/index.js +0 -425
- package/dist/index.js.map +0 -1
- package/dist/iterateJsdoc.d.cts +0 -471
- package/dist/iterateJsdoc.d.cts.map +0 -1
- package/dist/iterateJsdoc.js +0 -1617
- package/dist/iterateJsdoc.js.map +0 -1
- package/dist/jsdocUtils.js +0 -1123
- package/dist/jsdocUtils.js.map +0 -1
- package/dist/rules/checkAccess.js +0 -33
- package/dist/rules/checkAccess.js.map +0 -1
- package/dist/rules/checkAlignment.js +0 -47
- package/dist/rules/checkAlignment.js.map +0 -1
- package/dist/rules/checkExamples.js +0 -348
- package/dist/rules/checkExamples.js.map +0 -1
- package/dist/rules/checkIndentation.js +0 -59
- package/dist/rules/checkIndentation.js.map +0 -1
- package/dist/rules/checkLineAlignment.js +0 -229
- package/dist/rules/checkLineAlignment.js.map +0 -1
- package/dist/rules/checkParamNames.js +0 -237
- package/dist/rules/checkParamNames.js.map +0 -1
- package/dist/rules/checkPropertyNames.js +0 -88
- package/dist/rules/checkPropertyNames.js.map +0 -1
- package/dist/rules/checkSyntax.js +0 -25
- package/dist/rules/checkSyntax.js.map +0 -1
- package/dist/rules/checkTagNames.js +0 -191
- package/dist/rules/checkTagNames.js.map +0 -1
- package/dist/rules/checkTemplateNames.js +0 -124
- package/dist/rules/checkTemplateNames.js.map +0 -1
- package/dist/rules/checkTypes.js +0 -299
- package/dist/rules/checkTypes.js.map +0 -1
- package/dist/rules/checkValues.js +0 -103
- package/dist/rules/checkValues.js.map +0 -1
- package/dist/rules/convertToJsdocComments.js +0 -231
- package/dist/rules/convertToJsdocComments.js.map +0 -1
- package/dist/rules/emptyTags.js +0 -67
- package/dist/rules/emptyTags.js.map +0 -1
- package/dist/rules/implementsOnClasses.js +0 -40
- package/dist/rules/implementsOnClasses.js.map +0 -1
- package/dist/rules/importsAsDependencies.js +0 -68
- package/dist/rules/importsAsDependencies.js.map +0 -1
- package/dist/rules/informativeDocs.js +0 -110
- package/dist/rules/informativeDocs.js.map +0 -1
- package/dist/rules/linesBeforeBlock.js +0 -75
- package/dist/rules/linesBeforeBlock.js.map +0 -1
- package/dist/rules/matchDescription.js +0 -167
- package/dist/rules/matchDescription.js.map +0 -1
- package/dist/rules/matchName.js +0 -77
- package/dist/rules/matchName.js.map +0 -1
- package/dist/rules/multilineBlocks.js +0 -245
- package/dist/rules/multilineBlocks.js.map +0 -1
- package/dist/rules/noBadBlocks.js +0 -68
- package/dist/rules/noBadBlocks.js.map +0 -1
- package/dist/rules/noBlankBlockDescriptions.js +0 -41
- package/dist/rules/noBlankBlockDescriptions.js.map +0 -1
- package/dist/rules/noBlankBlocks.js +0 -30
- package/dist/rules/noBlankBlocks.js.map +0 -1
- package/dist/rules/noDefaults.js +0 -56
- package/dist/rules/noDefaults.js.map +0 -1
- package/dist/rules/noMissingSyntax.js +0 -126
- package/dist/rules/noMissingSyntax.js.map +0 -1
- package/dist/rules/noMultiAsterisks.js +0 -58
- package/dist/rules/noMultiAsterisks.js.map +0 -1
- package/dist/rules/noRestrictedSyntax.js +0 -49
- package/dist/rules/noRestrictedSyntax.js.map +0 -1
- package/dist/rules/noTypes.js +0 -65
- package/dist/rules/noTypes.js.map +0 -1
- package/dist/rules/noUndefinedTypes.js +0 -303
- package/dist/rules/noUndefinedTypes.js.map +0 -1
- package/dist/rules/requireAsteriskPrefix.js +0 -112
- package/dist/rules/requireAsteriskPrefix.js.map +0 -1
- package/dist/rules/requireDescription.js +0 -95
- package/dist/rules/requireDescription.js.map +0 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +0 -220
- package/dist/rules/requireDescriptionCompleteSentence.js.map +0 -1
- package/dist/rules/requireExample.js +0 -77
- package/dist/rules/requireExample.js.map +0 -1
- package/dist/rules/requireFileOverview.js +0 -81
- package/dist/rules/requireFileOverview.js.map +0 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +0 -89
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +0 -1
- package/dist/rules/requireJsdoc.js +0 -404
- package/dist/rules/requireJsdoc.js.map +0 -1
- package/dist/rules/requireParam.js +0 -344
- package/dist/rules/requireParam.js.map +0 -1
- package/dist/rules/requireParamDescription.js +0 -59
- package/dist/rules/requireParamDescription.js.map +0 -1
- package/dist/rules/requireParamName.js +0 -36
- package/dist/rules/requireParamName.js.map +0 -1
- package/dist/rules/requireParamType.js +0 -59
- package/dist/rules/requireParamType.js.map +0 -1
- package/dist/rules/requireProperty.js +0 -35
- package/dist/rules/requireProperty.js.map +0 -1
- package/dist/rules/requirePropertyDescription.js +0 -21
- package/dist/rules/requirePropertyDescription.js.map +0 -1
- package/dist/rules/requirePropertyName.js +0 -21
- package/dist/rules/requirePropertyName.js.map +0 -1
- package/dist/rules/requirePropertyType.js +0 -21
- package/dist/rules/requirePropertyType.js.map +0 -1
- package/dist/rules/requireReturns.js +0 -131
- package/dist/rules/requireReturns.js.map +0 -1
- package/dist/rules/requireReturnsCheck.js +0 -66
- package/dist/rules/requireReturnsCheck.js.map +0 -1
- package/dist/rules/requireReturnsDescription.js +0 -43
- package/dist/rules/requireReturnsDescription.js.map +0 -1
- package/dist/rules/requireReturnsType.js +0 -36
- package/dist/rules/requireReturnsType.js.map +0 -1
- package/dist/rules/requireTemplate.js +0 -122
- package/dist/rules/requireTemplate.js.map +0 -1
- package/dist/rules/requireThrows.js +0 -67
- package/dist/rules/requireThrows.js.map +0 -1
- package/dist/rules/requireYields.js +0 -115
- package/dist/rules/requireYields.js.map +0 -1
- package/dist/rules/requireYieldsCheck.js +0 -105
- package/dist/rules/requireYieldsCheck.js.map +0 -1
- package/dist/rules/sortTags.js +0 -262
- package/dist/rules/sortTags.js.map +0 -1
- package/dist/rules/tagLines.js +0 -183
- package/dist/rules/tagLines.js.map +0 -1
- package/dist/rules/textEscaping.js +0 -102
- package/dist/rules/textEscaping.js.map +0 -1
- package/dist/rules/validTypes.js +0 -259
- package/dist/rules/validTypes.js.map +0 -1
- package/dist/tagNames.js +0 -144
- package/dist/tagNames.js.map +0 -1
- package/dist/utils/hasReturnValue.js +0 -265
- package/dist/utils/hasReturnValue.js.map +0 -1
|
@@ -1,384 +1,570 @@
|
|
|
1
|
-
|
|
2
|
-
const require_jsdocUtils = require('./jsdocUtils.cjs');
|
|
3
|
-
const __es_joy_jsdoccomment = require_rolldown_runtime.__toESM(require("@es-joy/jsdoccomment"));
|
|
4
|
-
const espree = require_rolldown_runtime.__toESM(require("espree"));
|
|
5
|
-
const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
|
|
6
|
-
const node_path = require_rolldown_runtime.__toESM(require("node:path"));
|
|
1
|
+
"use strict";
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getJsdocProcessorPlugin = void 0;
|
|
7
|
+
var _jsdocUtils = require("./jsdocUtils.cjs");
|
|
8
|
+
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
9
|
+
var espree = _interopRequireWildcard(require("espree"));
|
|
10
|
+
var _nodeFs = require("node:fs");
|
|
11
|
+
var _nodePath = require("node:path");
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
9
13
|
/**
|
|
10
|
-
* @import {
|
|
11
|
-
* Integer,
|
|
12
|
-
* JsdocBlockWithInline,
|
|
13
|
-
* } from './iterateJsdoc.js';
|
|
14
|
-
* @import {
|
|
15
|
-
* ESLint,
|
|
16
|
-
* Linter,
|
|
17
|
-
* } from 'eslint';
|
|
18
|
-
*/
|
|
19
|
-
|
|
14
|
+
* @import {
|
|
15
|
+
* Integer,
|
|
16
|
+
* JsdocBlockWithInline,
|
|
17
|
+
* } from './iterateJsdoc.js';
|
|
18
|
+
* @import {
|
|
19
|
+
* ESLint,
|
|
20
|
+
* Linter,
|
|
21
|
+
* } from 'eslint';
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
version
|
|
26
|
+
} = JSON.parse(
|
|
27
|
+
// @ts-expect-error `Buffer` is ok for `JSON.parse`
|
|
28
|
+
(0, _nodeFs.readFileSync)((0, _nodePath.join)(__dirname, '../package.json')));
|
|
29
|
+
|
|
30
|
+
// const zeroBasedLineIndexAdjust = -1;
|
|
20
31
|
const likelyNestedJSDocIndentSpace = 1;
|
|
21
32
|
const preTagSpaceLength = 1;
|
|
33
|
+
|
|
34
|
+
// If a space is present, we should ignore it
|
|
22
35
|
const firstLinePrefixLength = preTagSpaceLength;
|
|
23
36
|
const hasCaptionRegex = /^\s*<caption>([\s\S]*?)<\/caption>/v;
|
|
37
|
+
|
|
24
38
|
/**
|
|
25
|
-
* @param {string} str
|
|
26
|
-
* @returns {string}
|
|
27
|
-
*/
|
|
28
|
-
const escapeStringRegexp =
|
|
29
|
-
|
|
39
|
+
* @param {string} str
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
const escapeStringRegexp = str => {
|
|
43
|
+
return str.replaceAll(/[.*+?^$\{\}\(\)\|\[\]\\]/gv, '\\$&');
|
|
30
44
|
};
|
|
45
|
+
|
|
31
46
|
/**
|
|
32
|
-
* @param {string} str
|
|
33
|
-
* @param {string} ch
|
|
34
|
-
* @returns {Integer}
|
|
35
|
-
*/
|
|
47
|
+
* @param {string} str
|
|
48
|
+
* @param {string} ch
|
|
49
|
+
* @returns {Integer}
|
|
50
|
+
*/
|
|
36
51
|
const countChars = (str, ch) => {
|
|
37
|
-
|
|
52
|
+
return (str.match(new RegExp(escapeStringRegexp(ch), 'gv')) || []).length;
|
|
38
53
|
};
|
|
54
|
+
|
|
39
55
|
/**
|
|
40
|
-
* @param {string} text
|
|
41
|
-
* @returns {[
|
|
42
|
-
* Integer,
|
|
43
|
-
* Integer
|
|
44
|
-
* ]}
|
|
45
|
-
*/
|
|
46
|
-
const getLinesCols =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
* @param {string} text
|
|
57
|
+
* @returns {[
|
|
58
|
+
* Integer,
|
|
59
|
+
* Integer
|
|
60
|
+
* ]}
|
|
61
|
+
*/
|
|
62
|
+
const getLinesCols = text => {
|
|
63
|
+
const matchLines = countChars(text, '\n');
|
|
64
|
+
const colDelta = matchLines ? text.slice(text.lastIndexOf('\n') + 1).length : text.length;
|
|
65
|
+
return [matchLines, colDelta];
|
|
50
66
|
};
|
|
67
|
+
|
|
51
68
|
/**
|
|
52
|
-
* @typedef {number} Integer
|
|
53
|
-
*/
|
|
69
|
+
* @typedef {number} Integer
|
|
70
|
+
*/
|
|
71
|
+
|
|
54
72
|
/**
|
|
55
|
-
* @typedef {object} JsdocProcessorOptions
|
|
56
|
-
* @property {boolean} [captionRequired] Require captions for example tags
|
|
57
|
-
* @property {Integer} [paddedIndent] See docs
|
|
58
|
-
* @property {boolean} [checkDefaults] See docs
|
|
59
|
-
* @property {boolean} [checkParams] See docs
|
|
60
|
-
* @property {boolean} [checkExamples] See docs
|
|
61
|
-
* @property {boolean} [checkProperties] See docs
|
|
62
|
-
* @property {string} [matchingFileName] See docs
|
|
63
|
-
* @property {string} [matchingFileNameDefaults] See docs
|
|
64
|
-
* @property {string} [matchingFileNameParams] See docs
|
|
65
|
-
* @property {string} [matchingFileNameProperties] See docs
|
|
66
|
-
* @property {string|RegExp} [exampleCodeRegex] See docs
|
|
67
|
-
* @property {string|RegExp} [rejectExampleCodeRegex] See docs
|
|
68
|
-
* @property {string[]} [allowedLanguagesToProcess] See docs
|
|
69
|
-
* @property {"script"|"module"} [sourceType] See docs
|
|
70
|
-
* @property {import('eslint').Linter.ESTreeParser|import('eslint').Linter.NonESTreeParser} [parser] See docs
|
|
71
|
-
*/
|
|
73
|
+
* @typedef {object} JsdocProcessorOptions
|
|
74
|
+
* @property {boolean} [captionRequired] Require captions for example tags
|
|
75
|
+
* @property {Integer} [paddedIndent] See docs
|
|
76
|
+
* @property {boolean} [checkDefaults] See docs
|
|
77
|
+
* @property {boolean} [checkParams] See docs
|
|
78
|
+
* @property {boolean} [checkExamples] See docs
|
|
79
|
+
* @property {boolean} [checkProperties] See docs
|
|
80
|
+
* @property {string} [matchingFileName] See docs
|
|
81
|
+
* @property {string} [matchingFileNameDefaults] See docs
|
|
82
|
+
* @property {string} [matchingFileNameParams] See docs
|
|
83
|
+
* @property {string} [matchingFileNameProperties] See docs
|
|
84
|
+
* @property {string|RegExp} [exampleCodeRegex] See docs
|
|
85
|
+
* @property {string|RegExp} [rejectExampleCodeRegex] See docs
|
|
86
|
+
* @property {string[]} [allowedLanguagesToProcess] See docs
|
|
87
|
+
* @property {"script"|"module"} [sourceType] See docs
|
|
88
|
+
* @property {import('eslint').Linter.ESTreeParser|import('eslint').Linter.NonESTreeParser} [parser] See docs
|
|
89
|
+
*/
|
|
90
|
+
|
|
72
91
|
/**
|
|
73
|
-
* We use a function for the ability of the user to pass in a config, but
|
|
74
|
-
* without requiring all users of the plugin to do so.
|
|
75
|
-
* @param {JsdocProcessorOptions} [options]
|
|
76
|
-
* @returns {ESLint.Plugin}
|
|
77
|
-
*/
|
|
92
|
+
* We use a function for the ability of the user to pass in a config, but
|
|
93
|
+
* without requiring all users of the plugin to do so.
|
|
94
|
+
* @param {JsdocProcessorOptions} [options]
|
|
95
|
+
* @returns {ESLint.Plugin}
|
|
96
|
+
*/
|
|
78
97
|
const getJsdocProcessorPlugin = (options = {}) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* line: Integer,
|
|
137
|
-
* }
|
|
138
|
-
* }} cfg
|
|
139
|
-
*/
|
|
140
|
-
const checkSource = ({ cols = 0, defaultFileName, ext, filename, lines = 0, skipInit, source, sources = [], tag = { line: 0 }, targetTagName }) => {
|
|
141
|
-
if (!skipInit) sources.push({
|
|
142
|
-
nonJSPrefacingCols: cols,
|
|
143
|
-
nonJSPrefacingLines: lines,
|
|
144
|
-
string: source
|
|
145
|
-
});
|
|
146
|
-
/**
|
|
147
|
-
* @param {{
|
|
148
|
-
* nonJSPrefacingCols: Integer,
|
|
149
|
-
* nonJSPrefacingLines: Integer,
|
|
150
|
-
* string: string
|
|
151
|
-
* }} cfg
|
|
152
|
-
*/
|
|
153
|
-
const addSourceInfo = function({ nonJSPrefacingCols, nonJSPrefacingLines, string }) {
|
|
154
|
-
const src = paddedIndent ? string.replaceAll(new RegExp(`(^|\n) {${paddedIndent}}(?!$)`, "gv"), "\n") : string;
|
|
155
|
-
const file = filename || defaultFileName;
|
|
156
|
-
if (!("line" in tag)) tag.line = tag.source[0].number;
|
|
157
|
-
const codeStartLine = tag.line + nonJSPrefacingLines;
|
|
158
|
-
const codeStartCol = likelyNestedJSDocIndentSpace;
|
|
159
|
-
textsAndFileNames.push({
|
|
160
|
-
filename: file,
|
|
161
|
-
text: src
|
|
162
|
-
});
|
|
163
|
-
otherInfo.push({
|
|
164
|
-
codeStartCol,
|
|
165
|
-
codeStartLine,
|
|
166
|
-
commentLineCols,
|
|
167
|
-
ext,
|
|
168
|
-
nonJSPrefacingCols,
|
|
169
|
-
targetTagName
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
for (const targetSource of sources) addSourceInfo(targetSource);
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
* @param {string|null} filename
|
|
177
|
-
* @param {string} [ext] Since `eslint-plugin-markdown` v2, and
|
|
178
|
-
* ESLint 7, this is the default which other JS-fenced rules will used.
|
|
179
|
-
* Formerly "md" was the default.
|
|
180
|
-
* @returns {{
|
|
181
|
-
* defaultFileName: string|undefined,
|
|
182
|
-
* filename: string|null,
|
|
183
|
-
* ext: string
|
|
184
|
-
* }}
|
|
185
|
-
*/
|
|
186
|
-
const getFilenameInfo = (filename, ext = "md/*.js") => {
|
|
187
|
-
let defaultFileName;
|
|
188
|
-
if (!filename) if (typeof jsFileName === "string" && jsFileName.includes(".")) defaultFileName = jsFileName.replace(/\.[^.]*$/v, `.${ext}`);
|
|
189
|
-
else defaultFileName = `dummy.${ext}`;
|
|
190
|
-
return {
|
|
191
|
-
defaultFileName,
|
|
192
|
-
ext,
|
|
193
|
-
filename
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
if (checkDefaults) {
|
|
197
|
-
const filenameInfo = getFilenameInfo(matchingFileNameDefaults, "jsdoc-defaults");
|
|
198
|
-
require_jsdocUtils.forEachPreferredTag(jsdoc, "default", (tag, targetTagName) => {
|
|
199
|
-
if (!tag.description.trim()) return;
|
|
200
|
-
checkSource({
|
|
201
|
-
source: `(${require_jsdocUtils.getTagDescription(tag)})`,
|
|
202
|
-
targetTagName,
|
|
203
|
-
...filenameInfo
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if (checkParams) {
|
|
208
|
-
const filenameInfo = getFilenameInfo(matchingFileNameParams, "jsdoc-params");
|
|
209
|
-
require_jsdocUtils.forEachPreferredTag(jsdoc, "param", (tag, targetTagName) => {
|
|
210
|
-
if (!tag.default || !tag.default.trim()) return;
|
|
211
|
-
checkSource({
|
|
212
|
-
source: `(${tag.default})`,
|
|
213
|
-
targetTagName,
|
|
214
|
-
...filenameInfo
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
if (checkProperties) {
|
|
219
|
-
const filenameInfo = getFilenameInfo(matchingFileNameProperties, "jsdoc-properties");
|
|
220
|
-
require_jsdocUtils.forEachPreferredTag(jsdoc, "property", (tag, targetTagName) => {
|
|
221
|
-
if (!tag.default || !tag.default.trim()) return;
|
|
222
|
-
checkSource({
|
|
223
|
-
source: `(${tag.default})`,
|
|
224
|
-
targetTagName,
|
|
225
|
-
...filenameInfo
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
if (!checkExamples) return textsAndFileNames;
|
|
230
|
-
const tagName = require_jsdocUtils.getPreferredTagName(jsdoc, { tagName: "example" });
|
|
231
|
-
if (!require_jsdocUtils.hasTag(jsdoc, tagName)) return textsAndFileNames;
|
|
232
|
-
const matchingFilenameInfo = getFilenameInfo(matchingFileName);
|
|
233
|
-
require_jsdocUtils.forEachPreferredTag(jsdoc, "example", (tag, targetTagName) => {
|
|
234
|
-
let source = require_jsdocUtils.getTagDescription(tag);
|
|
235
|
-
const match = source.match(hasCaptionRegex);
|
|
236
|
-
if (captionRequired && (!match || !match[1].trim())) {
|
|
237
|
-
extraMessages.push({
|
|
238
|
-
column: commentLineCols[1] + 1,
|
|
239
|
-
line: 1 + commentLineCols[0] + (tag.line ?? tag.source[0].number),
|
|
240
|
-
message: `@${targetTagName} error - Caption is expected for examples.`,
|
|
241
|
-
ruleId: "jsdoc/example-missing-caption",
|
|
242
|
-
severity: 2
|
|
243
|
-
});
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
source = source.replace(hasCaptionRegex, "");
|
|
247
|
-
const [lines, cols] = match ? getLinesCols(match[0]) : [0, 0];
|
|
248
|
-
if (exampleCodeRegex && !exampleCodeRegExp.test(source) || rejectExampleCodeRegex && rejectExampleCodeRegExp.test(source)) return;
|
|
249
|
-
if (allowedLanguagesToProcess) {
|
|
250
|
-
const matches = /^\s*```(?<language>\S+)([\s\S]*)```\s*$/v.exec(source);
|
|
251
|
-
if (matches?.groups && !allowedLanguagesToProcess.includes(matches.groups.language.toLowerCase())) return;
|
|
252
|
-
}
|
|
253
|
-
const sources = [];
|
|
254
|
-
let skipInit = false;
|
|
255
|
-
if (exampleCodeRegex) {
|
|
256
|
-
let nonJSPrefacingCols = 0;
|
|
257
|
-
let nonJSPrefacingLines = 0;
|
|
258
|
-
let startingIndex = 0;
|
|
259
|
-
let lastStringCount = 0;
|
|
260
|
-
let exampleCode;
|
|
261
|
-
exampleCodeRegExp.lastIndex = 0;
|
|
262
|
-
while ((exampleCode = exampleCodeRegExp.exec(source)) !== null) {
|
|
263
|
-
const { "0": n0, "1": n1, index } = exampleCode;
|
|
264
|
-
const preMatch = source.slice(startingIndex, index);
|
|
265
|
-
const [preMatchLines, colDelta] = getLinesCols(preMatch);
|
|
266
|
-
let nonJSPreface;
|
|
267
|
-
let nonJSPrefaceLineCount;
|
|
268
|
-
if (n1) {
|
|
269
|
-
const idx = n0.indexOf(n1);
|
|
270
|
-
nonJSPreface = n0.slice(0, idx);
|
|
271
|
-
nonJSPrefaceLineCount = countChars(nonJSPreface, "\n");
|
|
272
|
-
} else {
|
|
273
|
-
nonJSPreface = "";
|
|
274
|
-
nonJSPrefaceLineCount = 0;
|
|
275
|
-
}
|
|
276
|
-
nonJSPrefacingLines += lastStringCount + preMatchLines + nonJSPrefaceLineCount;
|
|
277
|
-
if (nonJSPrefaceLineCount) {
|
|
278
|
-
const charsInLastLine = nonJSPreface.slice(nonJSPreface.lastIndexOf("\n") + 1).length;
|
|
279
|
-
nonJSPrefacingCols += charsInLastLine;
|
|
280
|
-
} else nonJSPrefacingCols += colDelta + nonJSPreface.length;
|
|
281
|
-
const string = n1 || n0;
|
|
282
|
-
sources.push({
|
|
283
|
-
nonJSPrefacingCols,
|
|
284
|
-
nonJSPrefacingLines,
|
|
285
|
-
string
|
|
286
|
-
});
|
|
287
|
-
startingIndex = exampleCodeRegExp.lastIndex;
|
|
288
|
-
lastStringCount = countChars(string, "\n");
|
|
289
|
-
if (!exampleCodeRegExp.global) break;
|
|
290
|
-
}
|
|
291
|
-
skipInit = true;
|
|
292
|
-
}
|
|
293
|
-
checkSource({
|
|
294
|
-
cols,
|
|
295
|
-
lines,
|
|
296
|
-
skipInit,
|
|
297
|
-
source,
|
|
298
|
-
sources,
|
|
299
|
-
tag,
|
|
300
|
-
targetTagName,
|
|
301
|
-
...matchingFilenameInfo
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
return textsAndFileNames;
|
|
305
|
-
};
|
|
306
|
-
return {
|
|
307
|
-
meta: {
|
|
308
|
-
name: "eslint-plugin-jsdoc/processor",
|
|
309
|
-
version
|
|
310
|
-
},
|
|
311
|
-
processors: { examples: {
|
|
312
|
-
meta: {
|
|
313
|
-
name: "eslint-plugin-jsdoc/preprocessor",
|
|
314
|
-
version
|
|
315
|
-
},
|
|
316
|
-
postprocess([jsMessages, ...messages], filename) {
|
|
317
|
-
for (const [idx, message] of messages.entries()) {
|
|
318
|
-
const { codeStartCol, codeStartLine, commentLineCols, nonJSPrefacingCols, targetTagName } = otherInfo[idx];
|
|
319
|
-
for (const msg of message) {
|
|
320
|
-
const { column, endColumn, endLine, fatal, line, message: messageText, ruleId, severity } = msg;
|
|
321
|
-
const [codeCtxLine, codeCtxColumn] = commentLineCols;
|
|
322
|
-
const startLine = codeCtxLine + codeStartLine + line;
|
|
323
|
-
const startCol = 1 + codeCtxColumn + codeStartCol + (line <= 1 ? nonJSPrefacingCols + firstLinePrefixLength : preTagSpaceLength) + column;
|
|
324
|
-
msg.message = "@" + targetTagName + " " + (severity === 2 ? "error" : "warning") + (ruleId ? " (" + ruleId + ")" : "") + ": " + (fatal ? "Fatal: " : "") + messageText;
|
|
325
|
-
msg.line = startLine;
|
|
326
|
-
msg.column = startCol;
|
|
327
|
-
msg.endLine = endLine ? startLine + endLine : startLine;
|
|
328
|
-
msg.endColumn = endColumn ? startCol - column + endColumn : startCol;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const ret = [...jsMessages].concat(...messages, ...extraMessages);
|
|
332
|
-
extraMessages = [];
|
|
333
|
-
return ret;
|
|
334
|
-
},
|
|
335
|
-
preprocess(text, filename) {
|
|
336
|
-
try {
|
|
337
|
-
let ast;
|
|
338
|
-
try {
|
|
339
|
-
ast = parser ? parser.parseForESLint(text, {
|
|
340
|
-
comment: true,
|
|
341
|
-
ecmaVersion: "latest",
|
|
342
|
-
sourceType
|
|
343
|
-
}).ast : espree.parse(text, {
|
|
344
|
-
comment: true,
|
|
345
|
-
ecmaVersion: "latest",
|
|
346
|
-
sourceType
|
|
347
|
-
});
|
|
348
|
-
} catch {
|
|
349
|
-
return [text];
|
|
350
|
-
}
|
|
351
|
-
/** @type {[number, number][]} */
|
|
352
|
-
const commentLineCols = [];
|
|
353
|
-
const jsdocComments = ast.comments.filter((comment) => {
|
|
354
|
-
return /^\*\s/v.test(comment.value);
|
|
355
|
-
}).map((comment) => {
|
|
356
|
-
const [start] = comment.range ?? [];
|
|
357
|
-
const textToStart = text.slice(0, start);
|
|
358
|
-
const [lines, cols] = getLinesCols(textToStart);
|
|
359
|
-
commentLineCols.push([lines, cols]);
|
|
360
|
-
return (0, __es_joy_jsdoccomment.parseComment)(comment);
|
|
361
|
-
});
|
|
362
|
-
return [text, ...jsdocComments.flatMap((jsdoc, idx) => {
|
|
363
|
-
return getTextsAndFileNames(jsdoc, filename, commentLineCols[idx]);
|
|
364
|
-
}).filter(
|
|
365
|
-
/**
|
|
366
|
-
* @returns {file is Linter.ProcessorFile}
|
|
367
|
-
*/
|
|
368
|
-
(file) => {
|
|
369
|
-
return file !== null && file !== void 0;
|
|
370
|
-
}
|
|
371
|
-
)];
|
|
372
|
-
} catch (error) {
|
|
373
|
-
console.log("err", filename, error);
|
|
374
|
-
}
|
|
375
|
-
return [];
|
|
376
|
-
},
|
|
377
|
-
supportsAutofix: false
|
|
378
|
-
} }
|
|
379
|
-
};
|
|
380
|
-
};
|
|
98
|
+
const {
|
|
99
|
+
allowedLanguagesToProcess = ['js', 'ts', 'javascript', 'typescript'],
|
|
100
|
+
captionRequired = false,
|
|
101
|
+
checkDefaults = false,
|
|
102
|
+
checkExamples = true,
|
|
103
|
+
checkParams = false,
|
|
104
|
+
checkProperties = false,
|
|
105
|
+
exampleCodeRegex = null,
|
|
106
|
+
matchingFileName = null,
|
|
107
|
+
matchingFileNameDefaults = null,
|
|
108
|
+
matchingFileNameParams = null,
|
|
109
|
+
matchingFileNameProperties = null,
|
|
110
|
+
paddedIndent = 0,
|
|
111
|
+
parser = undefined,
|
|
112
|
+
rejectExampleCodeRegex = null,
|
|
113
|
+
sourceType = 'module'
|
|
114
|
+
} = options;
|
|
115
|
+
|
|
116
|
+
/** @type {RegExp} */
|
|
117
|
+
let exampleCodeRegExp;
|
|
118
|
+
/** @type {RegExp} */
|
|
119
|
+
let rejectExampleCodeRegExp;
|
|
120
|
+
if (exampleCodeRegex) {
|
|
121
|
+
exampleCodeRegExp = typeof exampleCodeRegex === 'string' ? (0, _jsdocUtils.getRegexFromString)(exampleCodeRegex) : exampleCodeRegex;
|
|
122
|
+
}
|
|
123
|
+
if (rejectExampleCodeRegex) {
|
|
124
|
+
rejectExampleCodeRegExp = typeof rejectExampleCodeRegex === 'string' ? (0, _jsdocUtils.getRegexFromString)(rejectExampleCodeRegex) : rejectExampleCodeRegex;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @type {{
|
|
129
|
+
* targetTagName: string,
|
|
130
|
+
* ext: string,
|
|
131
|
+
* codeStartLine: number,
|
|
132
|
+
* codeStartCol: number,
|
|
133
|
+
* nonJSPrefacingCols: number,
|
|
134
|
+
* commentLineCols: [number, number]
|
|
135
|
+
* }[]}
|
|
136
|
+
*/
|
|
137
|
+
const otherInfo = [];
|
|
138
|
+
|
|
139
|
+
/** @type {import('eslint').Linter.LintMessage[]} */
|
|
140
|
+
let extraMessages = [];
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {JsdocBlockWithInline} jsdoc
|
|
144
|
+
* @param {string} jsFileName
|
|
145
|
+
* @param {[number, number]} commentLineCols
|
|
146
|
+
*/
|
|
147
|
+
const getTextsAndFileNames = (jsdoc, jsFileName, commentLineCols) => {
|
|
148
|
+
/**
|
|
149
|
+
* @type {{
|
|
150
|
+
* text: string,
|
|
151
|
+
* filename: string|null|undefined
|
|
152
|
+
* }[]}
|
|
153
|
+
*/
|
|
154
|
+
const textsAndFileNames = [];
|
|
381
155
|
|
|
382
|
-
|
|
156
|
+
/**
|
|
157
|
+
* @param {{
|
|
158
|
+
* filename: string|null,
|
|
159
|
+
* defaultFileName: string|undefined,
|
|
160
|
+
* source: string,
|
|
161
|
+
* targetTagName: string,
|
|
162
|
+
* rules?: import('eslint').Linter.RulesRecord|undefined,
|
|
163
|
+
* lines?: Integer,
|
|
164
|
+
* cols?: Integer,
|
|
165
|
+
* skipInit?: boolean,
|
|
166
|
+
* ext: string,
|
|
167
|
+
* sources?: {
|
|
168
|
+
* nonJSPrefacingCols: Integer,
|
|
169
|
+
* nonJSPrefacingLines: Integer,
|
|
170
|
+
* string: string,
|
|
171
|
+
* }[],
|
|
172
|
+
* tag?: import('comment-parser').Spec & {
|
|
173
|
+
* line?: Integer,
|
|
174
|
+
* }|{
|
|
175
|
+
* line: Integer,
|
|
176
|
+
* }
|
|
177
|
+
* }} cfg
|
|
178
|
+
*/
|
|
179
|
+
const checkSource = ({
|
|
180
|
+
cols = 0,
|
|
181
|
+
defaultFileName,
|
|
182
|
+
ext,
|
|
183
|
+
filename,
|
|
184
|
+
lines = 0,
|
|
185
|
+
skipInit,
|
|
186
|
+
source,
|
|
187
|
+
sources = [],
|
|
188
|
+
tag = {
|
|
189
|
+
line: 0
|
|
190
|
+
},
|
|
191
|
+
targetTagName
|
|
192
|
+
}) => {
|
|
193
|
+
if (!skipInit) {
|
|
194
|
+
sources.push({
|
|
195
|
+
nonJSPrefacingCols: cols,
|
|
196
|
+
nonJSPrefacingLines: lines,
|
|
197
|
+
string: source
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {{
|
|
203
|
+
* nonJSPrefacingCols: Integer,
|
|
204
|
+
* nonJSPrefacingLines: Integer,
|
|
205
|
+
* string: string
|
|
206
|
+
* }} cfg
|
|
207
|
+
*/
|
|
208
|
+
const addSourceInfo = function ({
|
|
209
|
+
nonJSPrefacingCols,
|
|
210
|
+
nonJSPrefacingLines,
|
|
211
|
+
string
|
|
212
|
+
}) {
|
|
213
|
+
const src = paddedIndent ? string.replaceAll(new RegExp(`(^|\n) {${paddedIndent}}(?!$)`, 'gv'), '\n') : string;
|
|
214
|
+
|
|
215
|
+
// Programmatic ESLint API: https://eslint.org/docs/developer-guide/nodejs-api
|
|
216
|
+
const file = filename || defaultFileName;
|
|
217
|
+
if (!('line' in tag)) {
|
|
218
|
+
tag.line = tag.source[0].number;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// NOTE: `tag.line` can be 0 if of form `/** @tag ... */`
|
|
222
|
+
const codeStartLine =
|
|
223
|
+
/**
|
|
224
|
+
* @type {import('comment-parser').Spec & {
|
|
225
|
+
* line: Integer,
|
|
226
|
+
* }}
|
|
227
|
+
*/
|
|
228
|
+
tag.line + nonJSPrefacingLines;
|
|
229
|
+
const codeStartCol = likelyNestedJSDocIndentSpace;
|
|
230
|
+
textsAndFileNames.push({
|
|
231
|
+
filename: file,
|
|
232
|
+
text: src
|
|
233
|
+
});
|
|
234
|
+
otherInfo.push({
|
|
235
|
+
codeStartCol,
|
|
236
|
+
codeStartLine,
|
|
237
|
+
commentLineCols,
|
|
238
|
+
ext,
|
|
239
|
+
nonJSPrefacingCols,
|
|
240
|
+
targetTagName
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
for (const targetSource of sources) {
|
|
244
|
+
addSourceInfo(targetSource);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
*
|
|
250
|
+
* @param {string|null} filename
|
|
251
|
+
* @param {string} [ext] Since `eslint-plugin-markdown` v2, and
|
|
252
|
+
* ESLint 7, this is the default which other JS-fenced rules will used.
|
|
253
|
+
* Formerly "md" was the default.
|
|
254
|
+
* @returns {{
|
|
255
|
+
* defaultFileName: string|undefined,
|
|
256
|
+
* filename: string|null,
|
|
257
|
+
* ext: string
|
|
258
|
+
* }}
|
|
259
|
+
*/
|
|
260
|
+
const getFilenameInfo = (filename, ext = 'md/*.js') => {
|
|
261
|
+
let defaultFileName;
|
|
262
|
+
if (!filename) {
|
|
263
|
+
if (typeof jsFileName === 'string' && jsFileName.includes('.')) {
|
|
264
|
+
defaultFileName = jsFileName.replace(/\.[^.]*$/v, `.${ext}`);
|
|
265
|
+
} else {
|
|
266
|
+
defaultFileName = `dummy.${ext}`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
defaultFileName,
|
|
271
|
+
ext,
|
|
272
|
+
filename
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
if (checkDefaults) {
|
|
276
|
+
const filenameInfo = getFilenameInfo(matchingFileNameDefaults, 'jsdoc-defaults');
|
|
277
|
+
(0, _jsdocUtils.forEachPreferredTag)(jsdoc, 'default', (tag, targetTagName) => {
|
|
278
|
+
if (!tag.description.trim()) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
checkSource({
|
|
282
|
+
source: `(${(0, _jsdocUtils.getTagDescription)(tag)})`,
|
|
283
|
+
targetTagName,
|
|
284
|
+
...filenameInfo
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (checkParams) {
|
|
289
|
+
const filenameInfo = getFilenameInfo(matchingFileNameParams, 'jsdoc-params');
|
|
290
|
+
(0, _jsdocUtils.forEachPreferredTag)(jsdoc, 'param', (tag, targetTagName) => {
|
|
291
|
+
if (!tag.default || !tag.default.trim()) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
checkSource({
|
|
295
|
+
source: `(${tag.default})`,
|
|
296
|
+
targetTagName,
|
|
297
|
+
...filenameInfo
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (checkProperties) {
|
|
302
|
+
const filenameInfo = getFilenameInfo(matchingFileNameProperties, 'jsdoc-properties');
|
|
303
|
+
(0, _jsdocUtils.forEachPreferredTag)(jsdoc, 'property', (tag, targetTagName) => {
|
|
304
|
+
if (!tag.default || !tag.default.trim()) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
checkSource({
|
|
308
|
+
source: `(${tag.default})`,
|
|
309
|
+
targetTagName,
|
|
310
|
+
...filenameInfo
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (!checkExamples) {
|
|
315
|
+
return textsAndFileNames;
|
|
316
|
+
}
|
|
317
|
+
const tagName = /** @type {string} */(0, _jsdocUtils.getPreferredTagName)(jsdoc, {
|
|
318
|
+
tagName: 'example'
|
|
319
|
+
});
|
|
320
|
+
if (!(0, _jsdocUtils.hasTag)(jsdoc, tagName)) {
|
|
321
|
+
return textsAndFileNames;
|
|
322
|
+
}
|
|
323
|
+
const matchingFilenameInfo = getFilenameInfo(matchingFileName);
|
|
324
|
+
(0, _jsdocUtils.forEachPreferredTag)(jsdoc, 'example', (tag, targetTagName) => {
|
|
325
|
+
let source = /** @type {string} */(0, _jsdocUtils.getTagDescription)(tag);
|
|
326
|
+
const match = source.match(hasCaptionRegex);
|
|
327
|
+
if (captionRequired && (!match || !match[1].trim())) {
|
|
328
|
+
extraMessages.push({
|
|
329
|
+
column: commentLineCols[1] + 1,
|
|
330
|
+
line: 1 + commentLineCols[0] + (tag.line ?? tag.source[0].number),
|
|
331
|
+
message: `@${targetTagName} error - Caption is expected for examples.`,
|
|
332
|
+
ruleId: 'jsdoc/example-missing-caption',
|
|
333
|
+
severity: 2
|
|
334
|
+
});
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
source = source.replace(hasCaptionRegex, '');
|
|
338
|
+
const [lines, cols] = match ? getLinesCols(match[0]) : [0, 0];
|
|
339
|
+
if (exampleCodeRegex && !exampleCodeRegExp.test(source) || rejectExampleCodeRegex && rejectExampleCodeRegExp.test(source)) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// If `allowedLanguagesToProcess` is falsy, all languages should be processed.
|
|
344
|
+
if (allowedLanguagesToProcess) {
|
|
345
|
+
const matches = /^\s*```(?<language>\S+)([\s\S]*)```\s*$/v.exec(source);
|
|
346
|
+
if (matches?.groups && !allowedLanguagesToProcess.includes(matches.groups.language.toLowerCase())) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const sources = [];
|
|
351
|
+
let skipInit = false;
|
|
352
|
+
if (exampleCodeRegex) {
|
|
353
|
+
let nonJSPrefacingCols = 0;
|
|
354
|
+
let nonJSPrefacingLines = 0;
|
|
355
|
+
let startingIndex = 0;
|
|
356
|
+
let lastStringCount = 0;
|
|
357
|
+
let exampleCode;
|
|
358
|
+
exampleCodeRegExp.lastIndex = 0;
|
|
359
|
+
while ((exampleCode = exampleCodeRegExp.exec(source)) !== null) {
|
|
360
|
+
const {
|
|
361
|
+
'0': n0,
|
|
362
|
+
'1': n1,
|
|
363
|
+
index
|
|
364
|
+
} = exampleCode;
|
|
365
|
+
|
|
366
|
+
// Count anything preceding user regex match (can affect line numbering)
|
|
367
|
+
const preMatch = source.slice(startingIndex, index);
|
|
368
|
+
const [preMatchLines, colDelta] = getLinesCols(preMatch);
|
|
369
|
+
let nonJSPreface;
|
|
370
|
+
let nonJSPrefaceLineCount;
|
|
371
|
+
if (n1) {
|
|
372
|
+
const idx = n0.indexOf(n1);
|
|
373
|
+
nonJSPreface = n0.slice(0, idx);
|
|
374
|
+
nonJSPrefaceLineCount = countChars(nonJSPreface, '\n');
|
|
375
|
+
} else {
|
|
376
|
+
nonJSPreface = '';
|
|
377
|
+
nonJSPrefaceLineCount = 0;
|
|
378
|
+
}
|
|
379
|
+
nonJSPrefacingLines += lastStringCount + preMatchLines + nonJSPrefaceLineCount;
|
|
380
|
+
|
|
381
|
+
// Ignore `preMatch` delta if newlines here
|
|
382
|
+
if (nonJSPrefaceLineCount) {
|
|
383
|
+
const charsInLastLine = nonJSPreface.slice(nonJSPreface.lastIndexOf('\n') + 1).length;
|
|
384
|
+
nonJSPrefacingCols += charsInLastLine;
|
|
385
|
+
} else {
|
|
386
|
+
nonJSPrefacingCols += colDelta + nonJSPreface.length;
|
|
387
|
+
}
|
|
388
|
+
const string = n1 || n0;
|
|
389
|
+
sources.push({
|
|
390
|
+
nonJSPrefacingCols,
|
|
391
|
+
nonJSPrefacingLines,
|
|
392
|
+
string
|
|
393
|
+
});
|
|
394
|
+
startingIndex = exampleCodeRegExp.lastIndex;
|
|
395
|
+
lastStringCount = countChars(string, '\n');
|
|
396
|
+
if (!exampleCodeRegExp.global) {
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
skipInit = true;
|
|
401
|
+
}
|
|
402
|
+
checkSource({
|
|
403
|
+
cols,
|
|
404
|
+
lines,
|
|
405
|
+
skipInit,
|
|
406
|
+
source,
|
|
407
|
+
sources,
|
|
408
|
+
tag,
|
|
409
|
+
targetTagName,
|
|
410
|
+
...matchingFilenameInfo
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
return textsAndFileNames;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// See https://eslint.org/docs/latest/extend/plugins#processors-in-plugins
|
|
417
|
+
// See https://eslint.org/docs/latest/extend/custom-processors
|
|
418
|
+
// From https://github.com/eslint/eslint/issues/14745#issuecomment-869457265
|
|
419
|
+
/*
|
|
420
|
+
{
|
|
421
|
+
"files": ["*.js", "*.ts"],
|
|
422
|
+
"processor": "jsdoc/example" // a pretended value here
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"files": [
|
|
426
|
+
"*.js/*_jsdoc-example.js",
|
|
427
|
+
"*.ts/*_jsdoc-example.js",
|
|
428
|
+
"*.js/*_jsdoc-example.ts"
|
|
429
|
+
],
|
|
430
|
+
"rules": {
|
|
431
|
+
// specific rules for examples in jsdoc only here
|
|
432
|
+
// And other rules for `.js` and `.ts` will also be enabled for them
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
*/
|
|
436
|
+
return {
|
|
437
|
+
meta: {
|
|
438
|
+
name: 'eslint-plugin-jsdoc/processor',
|
|
439
|
+
version
|
|
440
|
+
},
|
|
441
|
+
processors: {
|
|
442
|
+
examples: {
|
|
443
|
+
meta: {
|
|
444
|
+
name: 'eslint-plugin-jsdoc/preprocessor',
|
|
445
|
+
version
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* @param {import('eslint').Linter.LintMessage[][]} messages
|
|
449
|
+
* @param {string} filename
|
|
450
|
+
*/
|
|
451
|
+
postprocess([jsMessages, ...messages
|
|
452
|
+
// eslint-disable-next-line no-unused-vars -- Placeholder
|
|
453
|
+
], filename) {
|
|
454
|
+
for (const [idx, message] of messages.entries()) {
|
|
455
|
+
const {
|
|
456
|
+
codeStartCol,
|
|
457
|
+
codeStartLine,
|
|
458
|
+
commentLineCols,
|
|
459
|
+
nonJSPrefacingCols,
|
|
460
|
+
targetTagName
|
|
461
|
+
} = otherInfo[idx];
|
|
462
|
+
for (const msg of message) {
|
|
463
|
+
const {
|
|
464
|
+
column,
|
|
465
|
+
endColumn,
|
|
466
|
+
endLine,
|
|
467
|
+
fatal,
|
|
468
|
+
line,
|
|
469
|
+
message: messageText,
|
|
470
|
+
ruleId,
|
|
471
|
+
severity
|
|
472
|
+
|
|
473
|
+
// Todo: Make fixable
|
|
474
|
+
// fix
|
|
475
|
+
// fix: {range: [number, number], text: string}
|
|
476
|
+
// suggestions: {desc: , messageId:, fix: }[],
|
|
477
|
+
} = msg;
|
|
478
|
+
const [codeCtxLine, codeCtxColumn] = commentLineCols;
|
|
479
|
+
const startLine = codeCtxLine + codeStartLine + line;
|
|
480
|
+
|
|
481
|
+
// Seems to need one more now
|
|
482
|
+
const startCol = 1 + codeCtxColumn + codeStartCol + (
|
|
483
|
+
// This might not work for line 0, but line 0 is unlikely for examples
|
|
484
|
+
line <= 1 ? nonJSPrefacingCols + firstLinePrefixLength : preTagSpaceLength) + column;
|
|
485
|
+
msg.message = '@' + targetTagName + ' ' + (severity === 2 ? 'error' : 'warning') + (ruleId ? ' (' + ruleId + ')' : '') + ': ' + (fatal ? 'Fatal: ' : '') + messageText;
|
|
486
|
+
msg.line = startLine;
|
|
487
|
+
msg.column = startCol;
|
|
488
|
+
msg.endLine = endLine ? startLine + endLine : startLine;
|
|
489
|
+
// added `- column` to offset what `endColumn` already seemed to include
|
|
490
|
+
msg.endColumn = endColumn ? startCol - column + endColumn : startCol;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const ret = [...jsMessages].concat(...messages, ...extraMessages);
|
|
494
|
+
extraMessages = [];
|
|
495
|
+
return ret;
|
|
496
|
+
},
|
|
497
|
+
/**
|
|
498
|
+
* @param {string} text
|
|
499
|
+
* @param {string} filename
|
|
500
|
+
* @returns {(string | Linter.ProcessorFile)[]}
|
|
501
|
+
*/
|
|
502
|
+
preprocess(text, filename) {
|
|
503
|
+
try {
|
|
504
|
+
let ast;
|
|
505
|
+
|
|
506
|
+
// May be running a second time so catch and ignore
|
|
507
|
+
try {
|
|
508
|
+
ast = parser ?
|
|
509
|
+
// @ts-expect-error Should be present
|
|
510
|
+
parser.parseForESLint(text, {
|
|
511
|
+
comment: true,
|
|
512
|
+
ecmaVersion: 'latest',
|
|
513
|
+
sourceType
|
|
514
|
+
}).ast : espree.parse(text, {
|
|
515
|
+
comment: true,
|
|
516
|
+
ecmaVersion: 'latest',
|
|
517
|
+
sourceType
|
|
518
|
+
});
|
|
519
|
+
} catch {
|
|
520
|
+
return [text];
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** @type {[number, number][]} */
|
|
524
|
+
const commentLineCols = [];
|
|
525
|
+
const jsdocComments = /** @type {import('estree').Comment[]} */(
|
|
526
|
+
/**
|
|
527
|
+
* @type {import('estree').Program & {
|
|
528
|
+
* comments?: import('estree').Comment[]
|
|
529
|
+
* }}
|
|
530
|
+
*/
|
|
531
|
+
ast.comments).filter(comment => {
|
|
532
|
+
return /^\*\s/v.test(comment.value);
|
|
533
|
+
}).map(comment => {
|
|
534
|
+
const [start
|
|
535
|
+
/* c8 ignore next -- Unsupporting processors only? */] = comment.range ?? [];
|
|
536
|
+
const textToStart = text.slice(0, start);
|
|
537
|
+
const [lines, cols] = getLinesCols(textToStart);
|
|
538
|
+
|
|
539
|
+
// const lines = [...textToStart.matchAll(/\n/gv)].length
|
|
540
|
+
// const lastLinePos = textToStart.lastIndexOf('\n');
|
|
541
|
+
// const cols = lastLinePos === -1
|
|
542
|
+
// ? 0
|
|
543
|
+
// : textToStart.slice(lastLinePos).length;
|
|
544
|
+
commentLineCols.push([lines, cols]);
|
|
545
|
+
return (0, _jsdoccomment.parseComment)(comment);
|
|
546
|
+
});
|
|
547
|
+
return [text, ...jsdocComments.flatMap((jsdoc, idx) => {
|
|
548
|
+
return getTextsAndFileNames(jsdoc, filename, commentLineCols[idx]);
|
|
549
|
+
}).filter(
|
|
550
|
+
/**
|
|
551
|
+
* @returns {file is Linter.ProcessorFile}
|
|
552
|
+
*/
|
|
553
|
+
file => {
|
|
554
|
+
return file !== null && file !== undefined;
|
|
555
|
+
})];
|
|
556
|
+
/* c8 ignore next 6 */
|
|
557
|
+
} catch (error) {
|
|
558
|
+
// eslint-disable-next-line no-console -- Debugging
|
|
559
|
+
console.log('err', filename, error);
|
|
560
|
+
}
|
|
561
|
+
return [];
|
|
562
|
+
},
|
|
563
|
+
// Todo: Reenable
|
|
564
|
+
supportsAutofix: false
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
};
|
|
383
569
|
exports.getJsdocProcessorPlugin = getJsdocProcessorPlugin;
|
|
384
570
|
//# sourceMappingURL=getJsdocProcessorPlugin.cjs.map
|