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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkExamples.js","names":[],"sources":["../../src/rules/checkExamples.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport eslint, {\n ESLint,\n} from 'eslint';\nimport semver from 'semver';\n\nconst {\n // @ts-expect-error Older ESLint\n CLIEngine,\n} = eslint;\n\nconst zeroBasedLineIndexAdjust = -1;\nconst likelyNestedJSDocIndentSpace = 1;\nconst preTagSpaceLength = 1;\n\n// If a space is present, we should ignore it\nconst firstLinePrefixLength = preTagSpaceLength;\n\nconst hasCaptionRegex = /^\\s*<caption>([\\s\\S]*?)<\\/caption>/v;\n\n/**\n * @param {string} str\n * @returns {string}\n */\nconst escapeStringRegexp = (str) => {\n return str.replaceAll(/[.*+?^$\\{\\}\\(\\)\\|\\[\\]\\\\]/gv, '\\\\$&');\n};\n\n/**\n * @param {string} str\n * @param {string} ch\n * @returns {import('../iterateJsdoc.js').Integer}\n */\nconst countChars = (str, ch) => {\n return (str.match(new RegExp(escapeStringRegexp(ch), 'gv')) || []).length;\n};\n\n/** @type {import('eslint').Linter.RulesRecord} */\nconst defaultMdRules = {\n // \"always\" newline rule at end unlikely in sample code\n 'eol-last': 0,\n\n // Wouldn't generally expect example paths to resolve relative to JS file\n 'import/no-unresolved': 0,\n\n // Snippets likely too short to always include import/export info\n 'import/unambiguous': 0,\n\n 'jsdoc/require-file-overview': 0,\n\n // The end of a multiline comment would end the comment the example is in.\n 'jsdoc/require-jsdoc': 0,\n\n // Unlikely to have inadvertent debugging within examples\n 'no-console': 0,\n\n // Often wish to start `@example` code after newline; also may use\n // empty lines for spacing\n 'no-multiple-empty-lines': 0,\n\n // Many variables in examples will be `undefined`\n 'no-undef': 0,\n\n // Common to define variables for clarity without always using them\n 'no-unused-vars': 0,\n\n // See import/no-unresolved\n 'node/no-missing-import': 0,\n 'node/no-missing-require': 0,\n\n // Can generally look nicer to pad a little even if code imposes more stringency\n 'padded-blocks': 0,\n};\n\n/** @type {import('eslint').Linter.RulesRecord} */\nconst defaultExpressionRules = {\n ...defaultMdRules,\n 'chai-friendly/no-unused-expressions': 'off',\n 'no-empty-function': 'off',\n 'no-new': 'off',\n 'no-unused-expressions': 'off',\n quotes: [\n 'error', 'double',\n ],\n semi: [\n 'error', 'never',\n ],\n strict: 'off',\n};\n\n/**\n * @param {string} text\n * @returns {[\n * import('../iterateJsdoc.js').Integer,\n * import('../iterateJsdoc.js').Integer\n * ]}\n */\nconst getLinesCols = (text) => {\n const matchLines = countChars(text, '\\n');\n\n const colDelta = matchLines ?\n text.slice(text.lastIndexOf('\\n') + 1).length :\n text.length;\n\n return [\n matchLines, colDelta,\n ];\n};\n\nexport default iterateJsdoc(({\n context,\n globalState,\n report,\n utils,\n}) => {\n if (semver.gte(ESLint.version, '8.0.0')) {\n report(\n 'This rule does not work for ESLint 8+; you should disable this rule and use' +\n 'the processor mentioned in the docs.',\n null,\n {\n column: 1,\n line: 1,\n },\n );\n\n return;\n }\n\n if (!globalState.has('checkExamples-matchingFileName')) {\n globalState.set('checkExamples-matchingFileName', new Map());\n }\n\n const matchingFileNameMap = /** @type {Map<string, string>} */ (\n globalState.get('checkExamples-matchingFileName')\n );\n\n const options = context.options[0] || {};\n let {\n exampleCodeRegex = null,\n rejectExampleCodeRegex = null,\n } = options;\n const {\n allowInlineConfig = true,\n baseConfig = {},\n captionRequired = false,\n checkDefaults = false,\n checkEslintrc = true,\n checkParams = false,\n checkProperties = false,\n configFile,\n matchingFileName = null,\n matchingFileNameDefaults = null,\n matchingFileNameParams = null,\n matchingFileNameProperties = null,\n noDefaultExampleRules = false,\n paddedIndent = 0,\n reportUnusedDisableDirectives = true,\n } = options;\n\n // Make this configurable?\n /**\n * @type {never[]}\n */\n const rulePaths = [];\n\n const mdRules = noDefaultExampleRules ? undefined : defaultMdRules;\n\n const expressionRules = noDefaultExampleRules ? undefined : defaultExpressionRules;\n\n if (exampleCodeRegex) {\n exampleCodeRegex = utils.getRegexFromString(exampleCodeRegex);\n }\n\n if (rejectExampleCodeRegex) {\n rejectExampleCodeRegex = utils.getRegexFromString(rejectExampleCodeRegex);\n }\n\n /**\n * @param {{\n * filename: string,\n * defaultFileName: string|undefined,\n * source: string,\n * targetTagName: string,\n * rules?: import('eslint').Linter.RulesRecord|undefined,\n * lines?: import('../iterateJsdoc.js').Integer,\n * cols?: import('../iterateJsdoc.js').Integer,\n * skipInit?: boolean,\n * sources?: {\n * nonJSPrefacingCols: import('../iterateJsdoc.js').Integer,\n * nonJSPrefacingLines: import('../iterateJsdoc.js').Integer,\n * string: string,\n * }[],\n * tag?: import('comment-parser').Spec & {\n * line?: import('../iterateJsdoc.js').Integer,\n * }|{\n * line: import('../iterateJsdoc.js').Integer,\n * }\n * }} cfg\n */\n const checkSource = ({\n cols = 0,\n defaultFileName,\n filename,\n lines = 0,\n rules = expressionRules,\n skipInit,\n source,\n sources = [],\n tag = {\n line: 0,\n },\n targetTagName,\n }) => {\n if (!skipInit) {\n sources.push({\n nonJSPrefacingCols: cols,\n nonJSPrefacingLines: lines,\n string: source,\n });\n }\n\n /**\n * @param {{\n * nonJSPrefacingCols: import('../iterateJsdoc.js').Integer,\n * nonJSPrefacingLines: import('../iterateJsdoc.js').Integer,\n * string: string\n * }} cfg\n */\n const checkRules = function ({\n nonJSPrefacingCols,\n nonJSPrefacingLines,\n string,\n }) {\n const cliConfig = {\n allowInlineConfig,\n baseConfig,\n configFile,\n reportUnusedDisableDirectives,\n rulePaths,\n rules,\n useEslintrc: checkEslintrc,\n };\n const cliConfigStr = JSON.stringify(cliConfig);\n\n const src = paddedIndent ?\n string.replaceAll(new RegExp(`(^|\\n) {${paddedIndent}}(?!$)`, 'gv'), '\\n') :\n string;\n\n // Programmatic ESLint API: https://eslint.org/docs/developer-guide/nodejs-api\n const fileNameMapKey = filename ?\n 'a' + cliConfigStr + filename :\n 'b' + cliConfigStr + defaultFileName;\n const file = filename || defaultFileName;\n let cliFile;\n if (matchingFileNameMap.has(fileNameMapKey)) {\n cliFile = matchingFileNameMap.get(fileNameMapKey);\n } else {\n const cli = new CLIEngine(cliConfig);\n let config;\n if (filename || checkEslintrc) {\n config = cli.getConfigForFile(file);\n }\n\n // We need a new instance to ensure that the rules that may only\n // be available to `file` (if it has its own `.eslintrc`),\n // will be defined.\n cliFile = new CLIEngine({\n allowInlineConfig,\n baseConfig: {\n ...baseConfig,\n ...config,\n },\n configFile,\n reportUnusedDisableDirectives,\n rulePaths,\n rules,\n useEslintrc: false,\n });\n matchingFileNameMap.set(fileNameMapKey, cliFile);\n }\n\n const {\n results: [\n {\n messages,\n },\n ],\n } = cliFile.executeOnText(src);\n\n if (!('line' in tag)) {\n tag.line = tag.source[0].number;\n }\n\n // NOTE: `tag.line` can be 0 if of form `/** @tag ... */`\n const codeStartLine = /**\n * @type {import('comment-parser').Spec & {\n * line: import('../iterateJsdoc.js').Integer,\n * }}\n */ (tag).line + nonJSPrefacingLines;\n const codeStartCol = likelyNestedJSDocIndentSpace;\n\n for (const {\n column,\n line,\n message,\n ruleId,\n severity,\n } of messages) {\n const startLine = codeStartLine + line + zeroBasedLineIndexAdjust;\n const startCol = codeStartCol + (\n\n // This might not work for line 0, but line 0 is unlikely for examples\n line <= 1 ? nonJSPrefacingCols + firstLinePrefixLength : preTagSpaceLength\n ) + column;\n\n report(\n '@' + targetTagName + ' ' + (severity === 2 ? 'error' : 'warning') +\n (ruleId ? ' (' + ruleId + ')' : '') + ': ' +\n message,\n null,\n {\n column: startCol,\n line: startLine,\n },\n );\n }\n };\n\n for (const targetSource of sources) {\n checkRules(targetSource);\n }\n };\n\n /**\n *\n * @param {string} filename\n * @param {string} [ext] Since `eslint-plugin-markdown` v2, and\n * ESLint 7, this is the default which other JS-fenced rules will used.\n * Formerly \"md\" was the default.\n * @returns {{defaultFileName: string|undefined, filename: string}}\n */\n const getFilenameInfo = (filename, ext = 'md/*.js') => {\n let defaultFileName;\n if (!filename) {\n const jsFileName = context.getFilename();\n if (typeof jsFileName === 'string' && jsFileName.includes('.')) {\n defaultFileName = jsFileName.replace(/\\.[^.]*$/v, `.${ext}`);\n } else {\n defaultFileName = `dummy.${ext}`;\n }\n }\n\n return {\n defaultFileName,\n filename,\n };\n };\n\n if (checkDefaults) {\n const filenameInfo = getFilenameInfo(matchingFileNameDefaults, 'jsdoc-defaults');\n utils.forEachPreferredTag('default', (tag, targetTagName) => {\n if (!tag.description.trim()) {\n return;\n }\n\n checkSource({\n source: `(${utils.getTagDescription(tag)})`,\n targetTagName,\n ...filenameInfo,\n });\n });\n }\n\n if (checkParams) {\n const filenameInfo = getFilenameInfo(matchingFileNameParams, 'jsdoc-params');\n utils.forEachPreferredTag('param', (tag, targetTagName) => {\n if (!tag.default || !tag.default.trim()) {\n return;\n }\n\n checkSource({\n source: `(${tag.default})`,\n targetTagName,\n ...filenameInfo,\n });\n });\n }\n\n if (checkProperties) {\n const filenameInfo = getFilenameInfo(matchingFileNameProperties, 'jsdoc-properties');\n utils.forEachPreferredTag('property', (tag, targetTagName) => {\n if (!tag.default || !tag.default.trim()) {\n return;\n }\n\n checkSource({\n source: `(${tag.default})`,\n targetTagName,\n ...filenameInfo,\n });\n });\n }\n\n const tagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'example',\n }));\n if (!utils.hasTag(tagName)) {\n return;\n }\n\n const matchingFilenameInfo = getFilenameInfo(matchingFileName);\n\n utils.forEachPreferredTag('example', (tag, targetTagName) => {\n let source = /** @type {string} */ (utils.getTagDescription(tag));\n const match = source.match(hasCaptionRegex);\n\n if (captionRequired && (!match || !match[1].trim())) {\n report('Caption is expected for examples.', null, tag);\n }\n\n source = source.replace(hasCaptionRegex, '');\n const [\n lines,\n cols,\n ] = match ? getLinesCols(match[0]) : [\n 0, 0,\n ];\n\n if (exampleCodeRegex && !exampleCodeRegex.test(source) ||\n rejectExampleCodeRegex && rejectExampleCodeRegex.test(source)\n ) {\n return;\n }\n\n const sources = [];\n let skipInit = false;\n if (exampleCodeRegex) {\n let nonJSPrefacingCols = 0;\n let nonJSPrefacingLines = 0;\n\n let startingIndex = 0;\n let lastStringCount = 0;\n\n let exampleCode;\n exampleCodeRegex.lastIndex = 0;\n while ((exampleCode = exampleCodeRegex.exec(source)) !== null) {\n const {\n '0': n0,\n '1': n1,\n index,\n } = exampleCode;\n\n // Count anything preceding user regex match (can affect line numbering)\n const preMatch = source.slice(startingIndex, index);\n\n const [\n preMatchLines,\n colDelta,\n ] = getLinesCols(preMatch);\n\n let nonJSPreface;\n let nonJSPrefaceLineCount;\n if (n1) {\n const idx = n0.indexOf(n1);\n nonJSPreface = n0.slice(0, idx);\n nonJSPrefaceLineCount = countChars(nonJSPreface, '\\n');\n } else {\n nonJSPreface = '';\n nonJSPrefaceLineCount = 0;\n }\n\n nonJSPrefacingLines += lastStringCount + preMatchLines + nonJSPrefaceLineCount;\n\n // Ignore `preMatch` delta if newlines here\n if (nonJSPrefaceLineCount) {\n const charsInLastLine = nonJSPreface.slice(nonJSPreface.lastIndexOf('\\n') + 1).length;\n\n nonJSPrefacingCols += charsInLastLine;\n } else {\n nonJSPrefacingCols += colDelta + nonJSPreface.length;\n }\n\n const string = n1 || n0;\n sources.push({\n nonJSPrefacingCols,\n nonJSPrefacingLines,\n string,\n });\n startingIndex = exampleCodeRegex.lastIndex;\n lastStringCount = countChars(string, '\\n');\n if (!exampleCodeRegex.global) {\n break;\n }\n }\n\n skipInit = true;\n }\n\n checkSource({\n cols,\n lines,\n rules: mdRules,\n skipInit,\n source,\n sources,\n tag,\n targetTagName,\n ...matchingFilenameInfo,\n });\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-examples.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowInlineConfig: {\n default: true,\n type: 'boolean',\n },\n baseConfig: {\n type: 'object',\n },\n captionRequired: {\n default: false,\n type: 'boolean',\n },\n checkDefaults: {\n default: false,\n type: 'boolean',\n },\n checkEslintrc: {\n default: true,\n type: 'boolean',\n },\n checkParams: {\n default: false,\n type: 'boolean',\n },\n checkProperties: {\n default: false,\n type: 'boolean',\n },\n configFile: {\n type: 'string',\n },\n exampleCodeRegex: {\n type: 'string',\n },\n matchingFileName: {\n type: 'string',\n },\n matchingFileNameDefaults: {\n type: 'string',\n },\n matchingFileNameParams: {\n type: 'string',\n },\n matchingFileNameProperties: {\n type: 'string',\n },\n noDefaultExampleRules: {\n default: false,\n type: 'boolean',\n },\n paddedIndent: {\n default: 0,\n type: 'integer',\n },\n rejectExampleCodeRegex: {\n type: 'string',\n },\n reportUnusedDisableDirectives: {\n default: true,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;AAMA,MAAM,EAEJ,WACD,GAAG;AAEJ,MAAM,2BAA2B;AACjC,MAAM,+BAA+B;AACrC,MAAM,oBAAoB;AAG1B,MAAM,wBAAwB;AAE9B,MAAM,kBAAkB;;;;;AAMxB,MAAM,qBAAqB,CAAC,QAAQ;AAClC,QAAO,IAAI,WAAW,8BAA8B,OAAO;AAC5D;;;;;;AAOD,MAAM,aAAa,CAAC,KAAK,OAAO;AAC9B,SAAQ,IAAI,MAAM,IAAI,OAAO,mBAAmB,GAAG,EAAE,MAAM,IAAI,CAAE,GAAE;AACpE;;AAGD,MAAM,iBAAiB;CAErB,YAAY;CAGZ,wBAAwB;CAGxB,sBAAsB;CAEtB,+BAA+B;CAG/B,uBAAuB;CAGvB,cAAc;CAId,2BAA2B;CAG3B,YAAY;CAGZ,kBAAkB;CAGlB,0BAA0B;CAC1B,2BAA2B;CAG3B,iBAAiB;AAClB;;AAGD,MAAM,yBAAyB;CAC7B,GAAG;CACH,uCAAuC;CACvC,qBAAqB;CACrB,UAAU;CACV,yBAAyB;CACzB,QAAQ,CACN,SAAS,QACV;CACD,MAAM,CACJ,SAAS,OACV;CACD,QAAQ;AACT;;;;;;;;AASD,MAAM,eAAe,CAAC,SAAS;CAC7B,MAAM,aAAa,WAAW,MAAM,KAAK;CAEzC,MAAM,WAAW,aACf,KAAK,MAAM,KAAK,YAAY,KAAK,GAAG,EAAE,CAAC,SACvC,KAAK;AAEP,QAAO,CACL,YAAY,QACb;AACF;AAED,4BAAe,aAAa,CAAC,EAC3B,SACA,aACA,QACA,OACD,KAAK;AACJ,KAAI,OAAO,IAAI,OAAO,SAAS,QAAQ,EAAE;EACvC,OACE,mHAEA,MACA;GACE,QAAQ;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AAK;EACN;EACD,QAAQ,CACN;GACE,sBAAsB;GACtB,YAAY;IACV,mBAAmB;KACjB,SAAS;KACT,MAAM;IACP;IACD,YAAY,EACV,MAAM,SACP;IACD,iBAAiB;KACf,SAAS;KACT,MAAM;IACP;IACD,eAAe;KACb,SAAS;KACT,MAAM;IACP;IACD,eAAe;KACb,SAAS;KACT,MAAM;IACP;IACD,aAAa;KACX,SAAS;KACT,MAAM;IACP;IACD,iBAAiB;KACf,SAAS;KACT,MAAM;IACP;IACD,YAAY,EACV,MAAM,SACP;IACD,kBAAkB,EAChB,MAAM,SACP;IACD,kBAAkB,EAChB,MAAM,SACP;IACD,0BAA0B,EACxB,MAAM,SACP;IACD,wBAAwB,EACtB,MAAM,SACP;IACD,4BAA4B,EAC1B,MAAM,SACP;IACD,uBAAuB;KACrB,SAAS;KACT,MAAM;IACP;IACD,cAAc;KACZ,SAAS;KACT,MAAM;IACP;IACD,wBAAwB,EACtB,MAAM,SACP;IACD,+BAA+B;KAC7B,SAAS;KACT,MAAM;IACP;GACF;GACD,MAAM;EACP,CACF;EACD,MAAM;CACP;AACF,EAAC"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import iterateJsdoc from "../iterateJsdoc.js";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/checkIndentation.js
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} str
|
|
6
|
-
* @param {string[]} excludeTags
|
|
7
|
-
* @returns {string}
|
|
8
|
-
*/
|
|
9
|
-
const maskExcludedContent = (str, excludeTags) => {
|
|
10
|
-
const regContent = new RegExp(`([ \\t]+\\*)[ \\t]@(?:${excludeTags.join("|")})(?=[ \\n])([\\w\\|\\W]*?\\n)(?=[ \\t]*\\*(?:[ \\t]*@\\w+\\s|\\/))`, "gv");
|
|
11
|
-
return str.replace(regContent, (_match, margin, code) => {
|
|
12
|
-
return (margin + "\n").repeat(code.match(/\n/gv).length);
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} str
|
|
17
|
-
* @returns {string}
|
|
18
|
-
*/
|
|
19
|
-
const maskCodeBlocks = (str) => {
|
|
20
|
-
const regContent = /([ \t]+\*)[ \t]```[^\n]*?([\w\|\W]*?\n)(?=[ \t]*\*(?:[ \t]*(?:```|@\w+\s)|\/))/gv;
|
|
21
|
-
return str.replaceAll(regContent, (_match, margin, code) => {
|
|
22
|
-
return (margin + "\n").repeat(code.match(/\n/gv).length);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var checkIndentation_default = iterateJsdoc(({ context, jsdocNode, report, sourceCode }) => {
|
|
26
|
-
const options = context.options[0] || {};
|
|
27
|
-
const { excludeTags = ["example"] } = options;
|
|
28
|
-
const reg = /^(?:\/?\**|[ \t]*)\*[ \t]{2}/gmv;
|
|
29
|
-
const textWithoutCodeBlocks = maskCodeBlocks(sourceCode.getText(jsdocNode));
|
|
30
|
-
const text = excludeTags.length ? maskExcludedContent(textWithoutCodeBlocks, excludeTags) : textWithoutCodeBlocks;
|
|
31
|
-
if (reg.test(text)) {
|
|
32
|
-
const lineBreaks = text.slice(0, reg.lastIndex).match(/\n/gv) || [];
|
|
33
|
-
report("There must be no indentation.", null, { line: lineBreaks.length });
|
|
34
|
-
}
|
|
35
|
-
}, {
|
|
36
|
-
iterateAllJsdocs: true,
|
|
37
|
-
meta: {
|
|
38
|
-
docs: {
|
|
39
|
-
description: "Reports invalid padding inside JSDoc blocks.",
|
|
40
|
-
url: "https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-indentation.md#repos-sticky-header"
|
|
41
|
-
},
|
|
42
|
-
schema: [{
|
|
43
|
-
additionalProperties: false,
|
|
44
|
-
properties: { excludeTags: {
|
|
45
|
-
items: {
|
|
46
|
-
pattern: "^\\S+$",
|
|
47
|
-
type: "string"
|
|
48
|
-
},
|
|
49
|
-
type: "array"
|
|
50
|
-
} },
|
|
51
|
-
type: "object"
|
|
52
|
-
}],
|
|
53
|
-
type: "layout"
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { checkIndentation_default as default };
|
|
59
|
-
//# sourceMappingURL=checkIndentation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkIndentation.js","names":[],"sources":["../../src/rules/checkIndentation.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * @param {string} str\n * @param {string[]} excludeTags\n * @returns {string}\n */\nconst maskExcludedContent = (str, excludeTags) => {\n const regContent = new RegExp(`([ \\\\t]+\\\\*)[ \\\\t]@(?:${excludeTags.join('|')})(?=[ \\\\n])([\\\\w\\\\|\\\\W]*?\\\\n)(?=[ \\\\t]*\\\\*(?:[ \\\\t]*@\\\\w+\\\\s|\\\\/))`, 'gv');\n\n return str.replace(regContent, (_match, margin, code) => {\n return (margin + '\\n').repeat(code.match(/\\n/gv).length);\n });\n};\n\n/**\n * @param {string} str\n * @returns {string}\n */\nconst maskCodeBlocks = (str) => {\n const regContent = /([ \\t]+\\*)[ \\t]```[^\\n]*?([\\w\\|\\W]*?\\n)(?=[ \\t]*\\*(?:[ \\t]*(?:```|@\\w+\\s)|\\/))/gv;\n\n return str.replaceAll(regContent, (_match, margin, code) => {\n return (margin + '\\n').repeat(code.match(/\\n/gv).length);\n });\n};\n\nexport default iterateJsdoc(({\n context,\n jsdocNode,\n report,\n sourceCode,\n}) => {\n const options = context.options[0] || {};\n const /** @type {{excludeTags: string[]}} */ {\n excludeTags = [\n 'example',\n ],\n } = options;\n\n const reg = /^(?:\\/?\\**|[ \\t]*)\\*[ \\t]{2}/gmv;\n const textWithoutCodeBlocks = maskCodeBlocks(sourceCode.getText(jsdocNode));\n const text = excludeTags.length ? maskExcludedContent(textWithoutCodeBlocks, excludeTags) : textWithoutCodeBlocks;\n\n if (reg.test(text)) {\n const lineBreaks = text.slice(0, reg.lastIndex).match(/\\n/gv) || [];\n report('There must be no indentation.', null, {\n line: lineBreaks.length,\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports invalid padding inside JSDoc blocks.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-indentation.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n excludeTags: {\n items: {\n pattern: '^\\\\S+$',\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":";;;;;;;;AAOA,MAAM,sBAAsB,CAAC,KAAK,gBAAgB;CAChD,MAAM,aAAa,IAAI,OAAO,CAAC,sBAAsB,EAAE,YAAY,KAAK,IAAI,CAAC,kEAAkE,CAAC,EAAE;AAElJ,QAAO,IAAI,QAAQ,YAAY,CAAC,QAAQ,QAAQ,SAAS;AACvD,UAAQ,SAAS,MAAM,OAAO,KAAK,MAAM,OAAO,CAAC,OAAO;CACzD,EAAC;AACH;;;;;AAMD,MAAM,iBAAiB,CAAC,QAAQ;CAC9B,MAAM,aAAa;AAEnB,QAAO,IAAI,WAAW,YAAY,CAAC,QAAQ,QAAQ,SAAS;AAC1D,UAAQ,SAAS,MAAM,OAAO,KAAK,MAAM,OAAO,CAAC,OAAO;CACzD,EAAC;AACH;AAED,+BAAe,aAAa,CAAC,EAC3B,SACA,WACA,QACA,YACD,KAAK;CACJ,MAAM,UAAU,QAAQ,QAAQ,MAAM,CAAE;CACxC,MAA6C,EAC3C,cAAc,CACZ,SACD,GACF,GAAG;CAEJ,MAAM,MAAM;CACZ,MAAM,wBAAwB,eAAe,WAAW,QAAQ,UAAU,CAAC;CAC3E,MAAM,OAAO,YAAY,SAAS,oBAAoB,uBAAuB,YAAY,GAAG;AAE5F,KAAI,IAAI,KAAK,KAAK,EAAE;EAClB,MAAM,aAAa,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,OAAO,IAAI,CAAE;EACnE,OAAO,iCAAiC,MAAM,EAC5C,MAAM,WAAW,OAClB,EAAC;CACH;AACF,GAAE;CACD,kBAAkB;CAClB,MAAM;EACJ,MAAM;GACJ,aAAa;GACb,KAAK;EACN;EACD,QAAQ,CACN;GACE,sBAAsB;GACtB,YAAY,EACV,aAAa;IACX,OAAO;KACL,SAAS;KACT,MAAM;IACP;IACD,MAAM;GACP,EACF;GACD,MAAM;EACP,CACF;EACD,MAAM;CACP;AACF,EAAC"}
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import iterateJsdoc from "../iterateJsdoc.js";
|
|
2
|
-
import alignTransform_default from "../alignTransform.js";
|
|
3
|
-
import { transforms } from "comment-parser";
|
|
4
|
-
|
|
5
|
-
//#region src/rules/checkLineAlignment.js
|
|
6
|
-
const { flow: commentFlow } = transforms;
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {{
|
|
9
|
-
* postDelimiter: import('../iterateJsdoc.js').Integer,
|
|
10
|
-
* postHyphen: import('../iterateJsdoc.js').Integer,
|
|
11
|
-
* postName: import('../iterateJsdoc.js').Integer,
|
|
12
|
-
* postTag: import('../iterateJsdoc.js').Integer,
|
|
13
|
-
* postType: import('../iterateJsdoc.js').Integer,
|
|
14
|
-
* }} CustomSpacings
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
18
|
-
* @param {import('comment-parser').Spec & {
|
|
19
|
-
* line: import('../iterateJsdoc.js').Integer
|
|
20
|
-
* }} tag
|
|
21
|
-
* @param {CustomSpacings} customSpacings
|
|
22
|
-
*/
|
|
23
|
-
const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {"tag"|"type"|"name"|"description"} ContentProp
|
|
26
|
-
*/
|
|
27
|
-
/** @type {("postDelimiter"|"postTag"|"postType"|"postName")[]} */
|
|
28
|
-
let spacerProps;
|
|
29
|
-
/** @type {ContentProp[]} */
|
|
30
|
-
let contentProps;
|
|
31
|
-
const mightHaveNamepath = utils.tagMightHaveNamepath(tag.tag);
|
|
32
|
-
if (mightHaveNamepath) {
|
|
33
|
-
spacerProps = [
|
|
34
|
-
"postDelimiter",
|
|
35
|
-
"postTag",
|
|
36
|
-
"postType",
|
|
37
|
-
"postName"
|
|
38
|
-
];
|
|
39
|
-
contentProps = [
|
|
40
|
-
"tag",
|
|
41
|
-
"type",
|
|
42
|
-
"name",
|
|
43
|
-
"description"
|
|
44
|
-
];
|
|
45
|
-
} else {
|
|
46
|
-
spacerProps = [
|
|
47
|
-
"postDelimiter",
|
|
48
|
-
"postTag",
|
|
49
|
-
"postType"
|
|
50
|
-
];
|
|
51
|
-
contentProps = [
|
|
52
|
-
"tag",
|
|
53
|
-
"type",
|
|
54
|
-
"description"
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
const { tokens } = tag.source[0];
|
|
58
|
-
/**
|
|
59
|
-
* @param {import('../iterateJsdoc.js').Integer} idx
|
|
60
|
-
* @param {(notRet: boolean, contentProp: ContentProp) => void} [callbck]
|
|
61
|
-
*/
|
|
62
|
-
const followedBySpace = (idx, callbck) => {
|
|
63
|
-
const nextIndex = idx + 1;
|
|
64
|
-
return spacerProps.slice(nextIndex).some((spacerProp, innerIdx) => {
|
|
65
|
-
const contentProp = contentProps[nextIndex + innerIdx];
|
|
66
|
-
const spacePropVal = tokens[spacerProp];
|
|
67
|
-
const ret = spacePropVal;
|
|
68
|
-
if (callbck) callbck(!ret, contentProp);
|
|
69
|
-
return ret && (callbck || !contentProp);
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const postHyphenSpacing = customSpacings?.postHyphen ?? 1;
|
|
73
|
-
const exactHyphenSpacing = new RegExp(`^\\s*-\\s{${postHyphenSpacing},${postHyphenSpacing}}(?!\\s)`, "v");
|
|
74
|
-
const hasNoHyphen = !/^\s*-(?!$)(?=\s)/v.test(tokens.description);
|
|
75
|
-
const hasExactHyphenSpacing = exactHyphenSpacing.test(tokens.description);
|
|
76
|
-
const ok = !spacerProps.some((spacerProp, idx) => {
|
|
77
|
-
const contentProp = contentProps[idx];
|
|
78
|
-
const contentPropVal = tokens[contentProp];
|
|
79
|
-
const spacerPropVal = tokens[spacerProp];
|
|
80
|
-
const spacing = customSpacings?.[spacerProp] || 1;
|
|
81
|
-
return spacerPropVal.length !== spacing && spacerPropVal.length !== 0 || spacerPropVal && !contentPropVal && followedBySpace(idx);
|
|
82
|
-
}) && (hasNoHyphen || hasExactHyphenSpacing);
|
|
83
|
-
if (ok) return;
|
|
84
|
-
const fix = () => {
|
|
85
|
-
for (const [idx, spacerProp] of spacerProps.entries()) {
|
|
86
|
-
const contentProp = contentProps[idx];
|
|
87
|
-
const contentPropVal = tokens[contentProp];
|
|
88
|
-
if (contentPropVal) {
|
|
89
|
-
const spacing = customSpacings?.[spacerProp] || 1;
|
|
90
|
-
tokens[spacerProp] = "".padStart(spacing, " ");
|
|
91
|
-
followedBySpace(idx, (hasSpace, contentPrp) => {
|
|
92
|
-
if (hasSpace) tokens[contentPrp] = "";
|
|
93
|
-
});
|
|
94
|
-
} else tokens[spacerProp] = "";
|
|
95
|
-
}
|
|
96
|
-
if (!hasExactHyphenSpacing) {
|
|
97
|
-
const hyphenSpacing = /^\s*-\s+/v;
|
|
98
|
-
tokens.description = tokens.description.replace(hyphenSpacing, "-" + "".padStart(postHyphenSpacing, " "));
|
|
99
|
-
}
|
|
100
|
-
utils.setTag(tag, tokens);
|
|
101
|
-
};
|
|
102
|
-
utils.reportJSDoc("Expected JSDoc block lines to not be aligned.", tag, fix, true);
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* @param {object} cfg
|
|
106
|
-
* @param {CustomSpacings} cfg.customSpacings
|
|
107
|
-
* @param {string} cfg.indent
|
|
108
|
-
* @param {import('comment-parser').Block} cfg.jsdoc
|
|
109
|
-
* @param {import('eslint').Rule.Node & {
|
|
110
|
-
* range: [number, number]
|
|
111
|
-
* }} cfg.jsdocNode
|
|
112
|
-
* @param {boolean} cfg.preserveMainDescriptionPostDelimiter
|
|
113
|
-
* @param {import('../iterateJsdoc.js').Report} cfg.report
|
|
114
|
-
* @param {string[]} cfg.tags
|
|
115
|
-
* @param {import('../iterateJsdoc.js').Utils} cfg.utils
|
|
116
|
-
* @param {string} cfg.wrapIndent
|
|
117
|
-
* @param {boolean} cfg.disableWrapIndent
|
|
118
|
-
* @returns {void}
|
|
119
|
-
*/
|
|
120
|
-
const checkAlignment = ({ customSpacings, disableWrapIndent, indent, jsdoc, jsdocNode, preserveMainDescriptionPostDelimiter, report, tags, utils, wrapIndent }) => {
|
|
121
|
-
const transform = commentFlow(alignTransform_default({
|
|
122
|
-
customSpacings,
|
|
123
|
-
disableWrapIndent,
|
|
124
|
-
indent,
|
|
125
|
-
preserveMainDescriptionPostDelimiter,
|
|
126
|
-
tags,
|
|
127
|
-
wrapIndent
|
|
128
|
-
}));
|
|
129
|
-
const transformedJsdoc = transform(jsdoc);
|
|
130
|
-
const comment = "/*" + jsdocNode.value + "*/";
|
|
131
|
-
const formatted = utils.stringify(transformedJsdoc).trimStart();
|
|
132
|
-
if (comment !== formatted) report(
|
|
133
|
-
"Expected JSDoc block lines to be aligned.",
|
|
134
|
-
/** @type {import('eslint').Rule.ReportFixer} */
|
|
135
|
-
(fixer) => {
|
|
136
|
-
return fixer.replaceText(jsdocNode, formatted);
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
};
|
|
140
|
-
var checkLineAlignment_default = iterateJsdoc(({ context, indent, jsdoc, jsdocNode, report, utils }) => {
|
|
141
|
-
const { customSpacings, disableWrapIndent = false, preserveMainDescriptionPostDelimiter, tags: applicableTags = [
|
|
142
|
-
"param",
|
|
143
|
-
"arg",
|
|
144
|
-
"argument",
|
|
145
|
-
"property",
|
|
146
|
-
"prop",
|
|
147
|
-
"returns",
|
|
148
|
-
"return",
|
|
149
|
-
"template"
|
|
150
|
-
], wrapIndent = "" } = context.options[1] || {};
|
|
151
|
-
if (context.options[0] === "always") {
|
|
152
|
-
if (!jsdocNode.value.includes("\n")) return;
|
|
153
|
-
checkAlignment({
|
|
154
|
-
customSpacings,
|
|
155
|
-
disableWrapIndent,
|
|
156
|
-
indent,
|
|
157
|
-
jsdoc,
|
|
158
|
-
jsdocNode,
|
|
159
|
-
preserveMainDescriptionPostDelimiter,
|
|
160
|
-
report,
|
|
161
|
-
tags: applicableTags,
|
|
162
|
-
utils,
|
|
163
|
-
wrapIndent
|
|
164
|
-
});
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const foundTags = utils.getPresentTags(applicableTags);
|
|
168
|
-
if (context.options[0] !== "any") for (const tag of foundTags) checkNotAlignedPerTag(utils, tag, customSpacings);
|
|
169
|
-
for (const tag of foundTags) if (tag.source.length > 1) {
|
|
170
|
-
let idx = 0;
|
|
171
|
-
for (const { tokens } of tag.source.slice(1)) {
|
|
172
|
-
idx++;
|
|
173
|
-
if (!tokens.description || tokens.type || tokens.name) continue;
|
|
174
|
-
if (!disableWrapIndent && tokens.postDelimiter.slice(1) !== wrapIndent) {
|
|
175
|
-
utils.reportJSDoc("Expected wrap indent", { line: tag.source[0].number + idx }, () => {
|
|
176
|
-
tokens.postDelimiter = tokens.postDelimiter.charAt(0) + wrapIndent;
|
|
177
|
-
});
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}, {
|
|
183
|
-
iterateAllJsdocs: true,
|
|
184
|
-
meta: {
|
|
185
|
-
docs: {
|
|
186
|
-
description: "Reports invalid alignment of JSDoc block lines.",
|
|
187
|
-
url: "https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-line-alignment.md#repos-sticky-header"
|
|
188
|
-
},
|
|
189
|
-
fixable: "whitespace",
|
|
190
|
-
schema: [{
|
|
191
|
-
enum: [
|
|
192
|
-
"always",
|
|
193
|
-
"never",
|
|
194
|
-
"any"
|
|
195
|
-
],
|
|
196
|
-
type: "string"
|
|
197
|
-
}, {
|
|
198
|
-
additionalProperties: false,
|
|
199
|
-
properties: {
|
|
200
|
-
customSpacings: {
|
|
201
|
-
additionalProperties: false,
|
|
202
|
-
properties: {
|
|
203
|
-
postDelimiter: { type: "integer" },
|
|
204
|
-
postHyphen: { type: "integer" },
|
|
205
|
-
postName: { type: "integer" },
|
|
206
|
-
postTag: { type: "integer" },
|
|
207
|
-
postType: { type: "integer" }
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
disableWrapIndent: { type: "boolean" },
|
|
211
|
-
preserveMainDescriptionPostDelimiter: {
|
|
212
|
-
default: false,
|
|
213
|
-
type: "boolean"
|
|
214
|
-
},
|
|
215
|
-
tags: {
|
|
216
|
-
items: { type: "string" },
|
|
217
|
-
type: "array"
|
|
218
|
-
},
|
|
219
|
-
wrapIndent: { type: "string" }
|
|
220
|
-
},
|
|
221
|
-
type: "object"
|
|
222
|
-
}],
|
|
223
|
-
type: "layout"
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
//#endregion
|
|
228
|
-
export { checkLineAlignment_default as default };
|
|
229
|
-
//# sourceMappingURL=checkLineAlignment.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkLineAlignment.js","names":["alignTransform"],"sources":["../../src/rules/checkLineAlignment.js"],"sourcesContent":["import alignTransform from '../alignTransform.js';\nimport iterateJsdoc from '../iterateJsdoc.js';\nimport {\n transforms,\n} from 'comment-parser';\n\nconst {\n flow: commentFlow,\n} = transforms;\n\n/**\n * @typedef {{\n * postDelimiter: import('../iterateJsdoc.js').Integer,\n * postHyphen: import('../iterateJsdoc.js').Integer,\n * postName: import('../iterateJsdoc.js').Integer,\n * postTag: import('../iterateJsdoc.js').Integer,\n * postType: import('../iterateJsdoc.js').Integer,\n * }} CustomSpacings\n */\n\n/**\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @param {import('comment-parser').Spec & {\n * line: import('../iterateJsdoc.js').Integer\n * }} tag\n * @param {CustomSpacings} customSpacings\n */\nconst checkNotAlignedPerTag = (utils, tag, customSpacings) => {\n /*\n start +\n delimiter +\n postDelimiter +\n tag +\n postTag +\n type +\n postType +\n name +\n postName +\n description +\n end +\n lineEnd\n */\n\n /**\n * @typedef {\"tag\"|\"type\"|\"name\"|\"description\"} ContentProp\n */\n\n /** @type {(\"postDelimiter\"|\"postTag\"|\"postType\"|\"postName\")[]} */\n let spacerProps;\n /** @type {ContentProp[]} */\n let contentProps;\n const mightHaveNamepath = utils.tagMightHaveNamepath(tag.tag);\n if (mightHaveNamepath) {\n spacerProps = [\n 'postDelimiter', 'postTag', 'postType', 'postName',\n ];\n contentProps = [\n 'tag', 'type', 'name', 'description',\n ];\n } else {\n spacerProps = [\n 'postDelimiter', 'postTag', 'postType',\n ];\n contentProps = [\n 'tag', 'type', 'description',\n ];\n }\n\n const {\n tokens,\n } = tag.source[0];\n\n /**\n * @param {import('../iterateJsdoc.js').Integer} idx\n * @param {(notRet: boolean, contentProp: ContentProp) => void} [callbck]\n */\n const followedBySpace = (idx, callbck) => {\n const nextIndex = idx + 1;\n\n return spacerProps.slice(nextIndex).some((spacerProp, innerIdx) => {\n const contentProp = contentProps[nextIndex + innerIdx];\n\n const spacePropVal = tokens[spacerProp];\n\n const ret = spacePropVal;\n\n if (callbck) {\n callbck(!ret, contentProp);\n }\n\n return ret && (callbck || !contentProp);\n });\n };\n\n const postHyphenSpacing = customSpacings?.postHyphen ?? 1;\n const exactHyphenSpacing = new RegExp(`^\\\\s*-\\\\s{${postHyphenSpacing},${postHyphenSpacing}}(?!\\\\s)`, 'v');\n const hasNoHyphen = !(/^\\s*-(?!$)(?=\\s)/v).test(tokens.description);\n const hasExactHyphenSpacing = exactHyphenSpacing.test(\n tokens.description,\n );\n\n // If checking alignment on multiple lines, need to check other `source`\n // items\n // Go through `post*` spacing properties and exit to indicate problem if\n // extra spacing detected\n const ok = !spacerProps.some((spacerProp, idx) => {\n const contentProp = contentProps[idx];\n const contentPropVal = tokens[contentProp];\n const spacerPropVal = tokens[spacerProp];\n const spacing = customSpacings?.[spacerProp] || 1;\n\n // There will be extra alignment if...\n\n // 1. The spaces don't match the space it should have (1 or custom spacing) OR\n return spacerPropVal.length !== spacing && spacerPropVal.length !== 0 ||\n\n // 2. There is a (single) space, no immediate content, and yet another\n // space is found subsequently (not separated by intervening content)\n spacerPropVal && !contentPropVal && followedBySpace(idx);\n }) && (hasNoHyphen || hasExactHyphenSpacing);\n if (ok) {\n return;\n }\n\n const fix = () => {\n for (const [\n idx,\n spacerProp,\n ] of spacerProps.entries()) {\n const contentProp = contentProps[idx];\n const contentPropVal = tokens[contentProp];\n\n if (contentPropVal) {\n const spacing = customSpacings?.[spacerProp] || 1;\n tokens[spacerProp] = ''.padStart(spacing, ' ');\n followedBySpace(idx, (hasSpace, contentPrp) => {\n if (hasSpace) {\n tokens[contentPrp] = '';\n }\n });\n } else {\n tokens[spacerProp] = '';\n }\n }\n\n if (!hasExactHyphenSpacing) {\n const hyphenSpacing = /^\\s*-\\s+/v;\n tokens.description = tokens.description.replace(\n hyphenSpacing, '-' + ''.padStart(postHyphenSpacing, ' '),\n );\n }\n\n utils.setTag(tag, tokens);\n };\n\n utils.reportJSDoc('Expected JSDoc block lines to not be aligned.', tag, fix, true);\n};\n\n/**\n * @param {object} cfg\n * @param {CustomSpacings} cfg.customSpacings\n * @param {string} cfg.indent\n * @param {import('comment-parser').Block} cfg.jsdoc\n * @param {import('eslint').Rule.Node & {\n * range: [number, number]\n * }} cfg.jsdocNode\n * @param {boolean} cfg.preserveMainDescriptionPostDelimiter\n * @param {import('../iterateJsdoc.js').Report} cfg.report\n * @param {string[]} cfg.tags\n * @param {import('../iterateJsdoc.js').Utils} cfg.utils\n * @param {string} cfg.wrapIndent\n * @param {boolean} cfg.disableWrapIndent\n * @returns {void}\n */\nconst checkAlignment = ({\n customSpacings,\n disableWrapIndent,\n indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags,\n utils,\n wrapIndent,\n}) => {\n const transform = commentFlow(\n alignTransform({\n customSpacings,\n disableWrapIndent,\n indent,\n preserveMainDescriptionPostDelimiter,\n tags,\n wrapIndent,\n }),\n );\n const transformedJsdoc = transform(jsdoc);\n\n const comment = '/*' +\n /**\n * @type {import('eslint').Rule.Node & {\n * range: [number, number], value: string\n * }}\n */ (jsdocNode).value + '*/';\n\n const formatted = utils.stringify(transformedJsdoc)\n .trimStart();\n\n if (comment !== formatted) {\n report(\n 'Expected JSDoc block lines to be aligned.',\n /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {\n return fixer.replaceText(jsdocNode, formatted);\n },\n );\n }\n};\n\nexport default iterateJsdoc(({\n context,\n indent,\n jsdoc,\n jsdocNode,\n report,\n utils,\n}) => {\n const {\n customSpacings,\n disableWrapIndent = false,\n preserveMainDescriptionPostDelimiter,\n tags: applicableTags = [\n 'param', 'arg', 'argument', 'property', 'prop', 'returns', 'return', 'template',\n ],\n wrapIndent = '',\n } = context.options[1] || {};\n\n if (context.options[0] === 'always') {\n // Skip if it contains only a single line.\n if (!(\n /**\n * @type {import('eslint').Rule.Node & {\n * range: [number, number], value: string\n * }}\n */\n (jsdocNode).value.includes('\\n')\n )) {\n return;\n }\n\n checkAlignment({\n customSpacings,\n disableWrapIndent,\n indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags: applicableTags,\n utils,\n wrapIndent,\n });\n\n return;\n }\n\n const foundTags = utils.getPresentTags(applicableTags);\n if (context.options[0] !== 'any') {\n for (const tag of foundTags) {\n checkNotAlignedPerTag(\n utils,\n /**\n * @type {import('comment-parser').Spec & {\n * line: import('../iterateJsdoc.js').Integer\n * }}\n */\n (tag),\n customSpacings,\n );\n }\n }\n\n for (const tag of foundTags) {\n if (tag.source.length > 1) {\n let idx = 0;\n for (const {\n tokens,\n // Avoid the tag line\n } of tag.source.slice(1)) {\n idx++;\n\n if (\n !tokens.description ||\n // Avoid first lines after multiline type\n tokens.type ||\n tokens.name\n ) {\n continue;\n }\n\n // Don't include a single separating space/tab\n if (!disableWrapIndent && tokens.postDelimiter.slice(1) !== wrapIndent) {\n utils.reportJSDoc('Expected wrap indent', {\n line: tag.source[0].number + idx,\n }, () => {\n tokens.postDelimiter = tokens.postDelimiter.charAt(0) + wrapIndent;\n });\n return;\n }\n }\n }\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports invalid alignment of JSDoc block lines.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-line-alignment.md#repos-sticky-header',\n },\n fixable: 'whitespace',\n schema: [\n {\n enum: [\n 'always', 'never', 'any',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n customSpacings: {\n additionalProperties: false,\n properties: {\n postDelimiter: {\n type: 'integer',\n },\n postHyphen: {\n type: 'integer',\n },\n postName: {\n type: 'integer',\n },\n postTag: {\n type: 'integer',\n },\n postType: {\n type: 'integer',\n },\n },\n },\n disableWrapIndent: {\n type: 'boolean',\n },\n preserveMainDescriptionPostDelimiter: {\n default: false,\n type: 'boolean',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n wrapIndent: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":";;;;;AAMA,MAAM,EACJ,MAAM,aACP,GAAG;;;;;;;;;;;;;;;;;AAmBJ,MAAM,wBAAwB,CAAC,OAAO,KAAK,mBAAmB;;;;;CAqB5D,IAAI;;CAEJ,IAAI;CACJ,MAAM,oBAAoB,MAAM,qBAAqB,IAAI,IAAI;AAC7D,KAAI,mBAAmB;EACrB,cAAc;GACZ;GAAiB;GAAW;GAAY;EACzC;EACD,eAAe;GACb;GAAO;GAAQ;GAAQ;EACxB;CACF,OAAM;EACL,cAAc;GACZ;GAAiB;GAAW;EAC7B;EACD,eAAe;GACb;GAAO;GAAQ;EAChB;CACF;CAED,MAAM,EACJ,QACD,GAAG,IAAI,OAAO;;;;;CAMf,MAAM,kBAAkB,CAAC,KAAK,YAAY;EACxC,MAAM,YAAY,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CAAC,qBAAqB,OAAO,cAAc,MAAM,EAAE,KAAK,YAAY;IACtE,MAAM,YAAY,wBAAwB,EACxC,MAAM,IAAI,OAAO,GAAG,SAAS,IAC9B,GAAE,MAAM;KACP,OAAO,gBAAgB,OAAO,cAAc,OAAO,EAAE,GAAG;IACzD,EAAC;AACF;GACD;EACF;CACF;AAEJ,GAAE;CACD,kBAAkB;CAClB,MAAM;EACJ,MAAM;GACJ,aAAa;GACb,KAAK;EACN;EACD,SAAS;EACT,QAAQ,CACN;GACE,MAAM;IACJ;IAAU;IAAS;GACpB;GACD,MAAM;EACP,GACD;GACE,sBAAsB;GACtB,YAAY;IACV,gBAAgB;KACd,sBAAsB;KACtB,YAAY;MACV,eAAe,EACb,MAAM,UACP;MACD,YAAY,EACV,MAAM,UACP;MACD,UAAU,EACR,MAAM,UACP;MACD,SAAS,EACP,MAAM,UACP;MACD,UAAU,EACR,MAAM,UACP;KACF;IACF;IACD,mBAAmB,EACjB,MAAM,UACP;IACD,sCAAsC;KACpC,SAAS;KACT,MAAM;IACP;IACD,MAAM;KACJ,OAAO,EACL,MAAM,SACP;KACD,MAAM;IACP;IACD,YAAY,EACV,MAAM,SACP;GACF;GACD,MAAM;EACP,CACF;EACD,MAAM;CACP;AACF,EAAC"}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import iterateJsdoc from "../iterateJsdoc.js";
|
|
2
|
-
|
|
3
|
-
//#region src/rules/checkParamNames.js
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} targetTagName
|
|
6
|
-
* @param {boolean} allowExtraTrailingParamDocs
|
|
7
|
-
* @param {boolean} checkDestructured
|
|
8
|
-
* @param {boolean} checkRestProperty
|
|
9
|
-
* @param {RegExp} checkTypesRegex
|
|
10
|
-
* @param {boolean} disableExtraPropertyReporting
|
|
11
|
-
* @param {boolean} disableMissingParamChecks
|
|
12
|
-
* @param {boolean} enableFixer
|
|
13
|
-
* @param {import('../jsdocUtils.js').ParamNameInfo[]} functionParameterNames
|
|
14
|
-
* @param {import('comment-parser').Block} jsdoc
|
|
15
|
-
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
16
|
-
* @param {import('../iterateJsdoc.js').Report} report
|
|
17
|
-
* @returns {boolean}
|
|
18
|
-
*/
|
|
19
|
-
const validateParameterNames = (targetTagName, allowExtraTrailingParamDocs, checkDestructured, checkRestProperty, checkTypesRegex, disableExtraPropertyReporting, disableMissingParamChecks, enableFixer, functionParameterNames, jsdoc, utils, report) => {
|
|
20
|
-
const paramTags = Object.entries(jsdoc.tags).filter(([, tag]) => {
|
|
21
|
-
return tag.tag === targetTagName;
|
|
22
|
-
});
|
|
23
|
-
const paramTagsNonNested = paramTags.filter(([, tag]) => {
|
|
24
|
-
return !tag.name.includes(".");
|
|
25
|
-
});
|
|
26
|
-
let dotted = 0;
|
|
27
|
-
let thisOffset = 0;
|
|
28
|
-
return paramTags.some(([, tag], index) => {
|
|
29
|
-
/** @type {import('../iterateJsdoc.js').Integer} */
|
|
30
|
-
let tagsIndex;
|
|
31
|
-
const dupeTagInfo = paramTags.find(([tgsIndex, tg], idx) => {
|
|
32
|
-
tagsIndex = Number(tgsIndex);
|
|
33
|
-
return tg.name === tag.name && idx !== index;
|
|
34
|
-
});
|
|
35
|
-
if (dupeTagInfo) {
|
|
36
|
-
utils.reportJSDoc(`Duplicate @${targetTagName} "${tag.name}"`, dupeTagInfo[1], enableFixer ? () => {
|
|
37
|
-
utils.removeTag(tagsIndex);
|
|
38
|
-
} : null);
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
if (tag.name.includes(".")) {
|
|
42
|
-
dotted++;
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
let functionParameterName = functionParameterNames[index - dotted + thisOffset];
|
|
46
|
-
if (functionParameterName === "this" && tag.name.trim() !== "this") {
|
|
47
|
-
++thisOffset;
|
|
48
|
-
functionParameterName = functionParameterNames[index - dotted + thisOffset];
|
|
49
|
-
}
|
|
50
|
-
if (!functionParameterName) {
|
|
51
|
-
if (allowExtraTrailingParamDocs) return false;
|
|
52
|
-
report(`@${targetTagName} "${tag.name}" does not match an existing function parameter.`, null, tag);
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
if (typeof functionParameterName === "object" && "name" in functionParameterName && Array.isArray(functionParameterName.name)) {
|
|
56
|
-
const actualName = tag.name.trim();
|
|
57
|
-
const expectedName = functionParameterName.name[index];
|
|
58
|
-
if (actualName === expectedName) {
|
|
59
|
-
thisOffset--;
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
report(`Expected @${targetTagName} name to be "${expectedName}". Got "${actualName}".`, null, tag);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(functionParameterName)) {
|
|
66
|
-
if (!checkDestructured) return false;
|
|
67
|
-
if (tag.type && tag.type.search(checkTypesRegex) === -1) return false;
|
|
68
|
-
const [parameterName, { annotationParamName, hasPropertyRest, names: properties, rests }] = functionParameterName;
|
|
69
|
-
if (annotationParamName !== void 0) {
|
|
70
|
-
const name = tag.name.trim();
|
|
71
|
-
if (name !== annotationParamName) report(`@${targetTagName} "${name}" does not match parameter name "${annotationParamName}"`, null, tag);
|
|
72
|
-
}
|
|
73
|
-
const tagName = parameterName === void 0 ? tag.name.trim() : parameterName;
|
|
74
|
-
const expectedNames = properties.map((name) => {
|
|
75
|
-
return `${tagName}.${name}`;
|
|
76
|
-
});
|
|
77
|
-
const actualNames = paramTags.map(([, paramTag]) => {
|
|
78
|
-
return paramTag.name.trim();
|
|
79
|
-
});
|
|
80
|
-
const actualTypes = paramTags.map(([, paramTag]) => {
|
|
81
|
-
return paramTag.type;
|
|
82
|
-
});
|
|
83
|
-
const missingProperties = [];
|
|
84
|
-
/** @type {string[]} */
|
|
85
|
-
const notCheckingNames = [];
|
|
86
|
-
for (const [idx, name] of expectedNames.entries()) {
|
|
87
|
-
if (notCheckingNames.some((notCheckingName) => {
|
|
88
|
-
return name.startsWith(notCheckingName);
|
|
89
|
-
})) continue;
|
|
90
|
-
const actualNameIdx = actualNames.findIndex((actualName) => {
|
|
91
|
-
return utils.comparePaths(name)(actualName);
|
|
92
|
-
});
|
|
93
|
-
if (actualNameIdx === -1) {
|
|
94
|
-
if (!checkRestProperty && rests[idx]) continue;
|
|
95
|
-
const missingIndex = actualNames.findIndex((actualName) => {
|
|
96
|
-
return utils.pathDoesNotBeginWith(name, actualName);
|
|
97
|
-
});
|
|
98
|
-
const line = tag.source[0].number - 1 + (missingIndex > -1 ? missingIndex : actualNames.length);
|
|
99
|
-
missingProperties.push({
|
|
100
|
-
name,
|
|
101
|
-
tagPlacement: { line: line === 0 ? 1 : line }
|
|
102
|
-
});
|
|
103
|
-
} else if (actualTypes[actualNameIdx].search(checkTypesRegex) === -1 && actualTypes[actualNameIdx] !== "") notCheckingNames.push(name);
|
|
104
|
-
}
|
|
105
|
-
const hasMissing = missingProperties.length;
|
|
106
|
-
if (hasMissing) for (const { name: missingProperty, tagPlacement } of missingProperties) report(`Missing @${targetTagName} "${missingProperty}"`, null, tagPlacement);
|
|
107
|
-
if (!hasPropertyRest || checkRestProperty) {
|
|
108
|
-
/** @type {[string, import('comment-parser').Spec][]} */
|
|
109
|
-
const extraProperties = [];
|
|
110
|
-
for (const [idx, name] of actualNames.entries()) {
|
|
111
|
-
const match = name.startsWith(tag.name.trim() + ".");
|
|
112
|
-
if (match && !expectedNames.some(utils.comparePaths(name)) && !utils.comparePaths(name)(tag.name) && (!disableExtraPropertyReporting || properties.some((prop) => {
|
|
113
|
-
return prop.split(".").length >= name.split(".").length - 1;
|
|
114
|
-
}))) extraProperties.push([name, paramTags[idx][1]]);
|
|
115
|
-
}
|
|
116
|
-
if (extraProperties.length) {
|
|
117
|
-
for (const [extraProperty, tg] of extraProperties) report(`@${targetTagName} "${extraProperty}" does not exist on ${tag.name}`, null, tg);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return hasMissing;
|
|
122
|
-
}
|
|
123
|
-
let funcParamName;
|
|
124
|
-
if (typeof functionParameterName === "object") {
|
|
125
|
-
const { name } = functionParameterName;
|
|
126
|
-
funcParamName = name;
|
|
127
|
-
} else funcParamName = functionParameterName;
|
|
128
|
-
if (funcParamName !== tag.name.trim()) {
|
|
129
|
-
const actualNames = paramTagsNonNested.map(([, { name }]) => {
|
|
130
|
-
return name.trim();
|
|
131
|
-
});
|
|
132
|
-
const expectedNames = functionParameterNames.map((item, idx) => {
|
|
133
|
-
if (item?.[1]?.names) return actualNames[idx];
|
|
134
|
-
return item;
|
|
135
|
-
}).filter((item) => {
|
|
136
|
-
return item !== "this";
|
|
137
|
-
});
|
|
138
|
-
if (disableMissingParamChecks) {
|
|
139
|
-
const usedExpectedNames = expectedNames.map((a) => {
|
|
140
|
-
return a?.toString();
|
|
141
|
-
}).filter((expectedName) => {
|
|
142
|
-
return expectedName && actualNames.includes(expectedName);
|
|
143
|
-
});
|
|
144
|
-
const usedInOrder = actualNames.every((actualName, idx) => {
|
|
145
|
-
return actualName === usedExpectedNames[idx];
|
|
146
|
-
});
|
|
147
|
-
if (usedInOrder) return false;
|
|
148
|
-
}
|
|
149
|
-
report(`Expected @${targetTagName} names to be "${expectedNames.map((expectedName) => {
|
|
150
|
-
return typeof expectedName === "object" && "name" in expectedName && expectedName.restElement ? "..." + expectedName.name : expectedName;
|
|
151
|
-
}).join(", ")}". Got "${actualNames.join(", ")}".`, null, tag);
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* @param {string} targetTagName
|
|
159
|
-
* @param {boolean} _allowExtraTrailingParamDocs
|
|
160
|
-
* @param {{
|
|
161
|
-
* name: string,
|
|
162
|
-
* idx: import('../iterateJsdoc.js').Integer
|
|
163
|
-
* }[]} jsdocParameterNames
|
|
164
|
-
* @param {import('comment-parser').Block} jsdoc
|
|
165
|
-
* @param {Function} report
|
|
166
|
-
* @returns {boolean}
|
|
167
|
-
*/
|
|
168
|
-
const validateParameterNamesDeep = (targetTagName, _allowExtraTrailingParamDocs, jsdocParameterNames, jsdoc, report) => {
|
|
169
|
-
/** @type {string} */
|
|
170
|
-
let lastRealParameter;
|
|
171
|
-
return jsdocParameterNames.some(({ idx, name: jsdocParameterName }) => {
|
|
172
|
-
const isPropertyPath = jsdocParameterName.includes(".");
|
|
173
|
-
if (isPropertyPath) {
|
|
174
|
-
if (!lastRealParameter) {
|
|
175
|
-
report(`@${targetTagName} path declaration ("${jsdocParameterName}") appears before any real parameter.`, null, jsdoc.tags[idx]);
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
let pathRootNodeName = jsdocParameterName.slice(0, jsdocParameterName.indexOf("."));
|
|
179
|
-
if (pathRootNodeName.endsWith("[]")) pathRootNodeName = pathRootNodeName.slice(0, -2);
|
|
180
|
-
if (pathRootNodeName !== lastRealParameter) {
|
|
181
|
-
report(`@${targetTagName} path declaration ("${jsdocParameterName}") root node name ("${pathRootNodeName}") does not match previous real parameter name ("${lastRealParameter}").`, null, jsdoc.tags[idx]);
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
} else lastRealParameter = jsdocParameterName;
|
|
185
|
-
return false;
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
const allowedNodes = [
|
|
189
|
-
"ArrowFunctionExpression",
|
|
190
|
-
"FunctionDeclaration",
|
|
191
|
-
"FunctionExpression",
|
|
192
|
-
"TSDeclareFunction",
|
|
193
|
-
"TSMethodSignature"
|
|
194
|
-
];
|
|
195
|
-
var checkParamNames_default = iterateJsdoc(({ context, jsdoc, node, report, utils }) => {
|
|
196
|
-
const { allowExtraTrailingParamDocs, checkDestructured = true, checkRestProperty = false, checkTypesPattern = "/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/", disableExtraPropertyReporting = false, disableMissingParamChecks = false, enableFixer = false, useDefaultObjectProperties = false } = context.options[0] || {};
|
|
197
|
-
if (!allowedNodes.includes(
|
|
198
|
-
/** @type {import('estree').Node} */
|
|
199
|
-
node.type
|
|
200
|
-
)) return;
|
|
201
|
-
const checkTypesRegex = utils.getRegexFromString(checkTypesPattern);
|
|
202
|
-
const jsdocParameterNamesDeep = utils.getJsdocTagsDeep("param");
|
|
203
|
-
if (!jsdocParameterNamesDeep || !jsdocParameterNamesDeep.length) return;
|
|
204
|
-
const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties);
|
|
205
|
-
const targetTagName = utils.getPreferredTagName({ tagName: "param" });
|
|
206
|
-
const isError = validateParameterNames(targetTagName, allowExtraTrailingParamDocs, checkDestructured, checkRestProperty, checkTypesRegex, disableExtraPropertyReporting, disableMissingParamChecks, enableFixer, functionParameterNames, jsdoc, utils, report);
|
|
207
|
-
if (isError || !checkDestructured) return;
|
|
208
|
-
validateParameterNamesDeep(targetTagName, allowExtraTrailingParamDocs, jsdocParameterNamesDeep, jsdoc, report);
|
|
209
|
-
}, {
|
|
210
|
-
contextDefaults: allowedNodes,
|
|
211
|
-
meta: {
|
|
212
|
-
docs: {
|
|
213
|
-
description: "Ensures that parameter names in JSDoc match those in the function declaration.",
|
|
214
|
-
url: "https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-param-names.md#repos-sticky-header"
|
|
215
|
-
},
|
|
216
|
-
fixable: "code",
|
|
217
|
-
schema: [{
|
|
218
|
-
additionalProperties: false,
|
|
219
|
-
properties: {
|
|
220
|
-
allowExtraTrailingParamDocs: { type: "boolean" },
|
|
221
|
-
checkDestructured: { type: "boolean" },
|
|
222
|
-
checkRestProperty: { type: "boolean" },
|
|
223
|
-
checkTypesPattern: { type: "string" },
|
|
224
|
-
disableExtraPropertyReporting: { type: "boolean" },
|
|
225
|
-
disableMissingParamChecks: { type: "boolean" },
|
|
226
|
-
enableFixer: { type: "boolean" },
|
|
227
|
-
useDefaultObjectProperties: { type: "boolean" }
|
|
228
|
-
},
|
|
229
|
-
type: "object"
|
|
230
|
-
}],
|
|
231
|
-
type: "suggestion"
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
//#endregion
|
|
236
|
-
export { checkParamNames_default as default };
|
|
237
|
-
//# sourceMappingURL=checkParamNames.js.map
|