eslint-plugin-jsdoc 48.0.5 → 48.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alignTransform.cjs +6 -4
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.cjs +13 -5
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/informativeDocs.cjs +4 -0
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/package.json +13 -13
- package/src/alignTransform.js +5 -3
- package/src/rules/checkLineAlignment.js +9 -1
- package/src/rules/informativeDocs.js +7 -0
package/dist/alignTransform.cjs
CHANGED
|
@@ -146,6 +146,7 @@ const space = len => {
|
|
|
146
146
|
* indent: string,
|
|
147
147
|
* preserveMainDescriptionPostDelimiter: boolean,
|
|
148
148
|
* wrapIndent: string,
|
|
149
|
+
* disableWrapIndent: boolean,
|
|
149
150
|
* }} cfg
|
|
150
151
|
* @returns {(
|
|
151
152
|
* block: import('comment-parser').Block
|
|
@@ -156,7 +157,8 @@ const alignTransform = ({
|
|
|
156
157
|
tags,
|
|
157
158
|
indent,
|
|
158
159
|
preserveMainDescriptionPostDelimiter,
|
|
159
|
-
wrapIndent
|
|
160
|
+
wrapIndent,
|
|
161
|
+
disableWrapIndent
|
|
160
162
|
}) => {
|
|
161
163
|
let intoTags = false;
|
|
162
164
|
/** @type {Width} */
|
|
@@ -285,7 +287,7 @@ const alignTransform = ({
|
|
|
285
287
|
// Not align.
|
|
286
288
|
if (shouldAlign(tags, index, source)) {
|
|
287
289
|
alignTokens(tokens, typelessInfo);
|
|
288
|
-
if (indentTag) {
|
|
290
|
+
if (!disableWrapIndent && indentTag) {
|
|
289
291
|
tokens.postDelimiter += wrapIndent;
|
|
290
292
|
}
|
|
291
293
|
}
|
|
@@ -306,9 +308,9 @@ const alignTransform = ({
|
|
|
306
308
|
return rewireSource({
|
|
307
309
|
...fields,
|
|
308
310
|
source: source.map((line, index) => {
|
|
309
|
-
const indentTag = tagIndentMode && !line.tokens.tag && line.tokens.description;
|
|
311
|
+
const indentTag = !disableWrapIndent && tagIndentMode && !line.tokens.tag && line.tokens.description;
|
|
310
312
|
const ret = update(line, index, source, typelessInfo, indentTag);
|
|
311
|
-
if (line.tokens.tag) {
|
|
313
|
+
if (!disableWrapIndent && line.tokens.tag) {
|
|
312
314
|
tagIndentMode = true;
|
|
313
315
|
}
|
|
314
316
|
return ret;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alignTransform.cjs","names":["_commentParser","require","rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","getTypelessInfo","fields","hasNoTypes","every","maxNamedTagLength","map","filter","maxUnnamedTagLength","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","wrapIndent","intoTags","alignTokens","typelessInfo","nothingAfter","delim","description","postName","postType","postTag","untypedNameAdjustment","untypedTypeAdjustment","spacings","postDelimiter","update","line","indentTag","isEmpty","end","postHyphenSpacing","postHyphen","hyphenSpacing","reduce","tagIndentMode","ret","_default","exports","default","module"],"sources":["../src/alignTransform.js"],"sourcesContent":["/**\n * Transform based on https://github.com/syavorsky/comment-parser/blob/master/src/transforms/align.ts\n *\n * It contains some customizations to align based on the tags, and some custom options.\n */\n\nimport {\n // `comment-parser/primitives` export\n util,\n} from 'comment-parser';\n\n/**\n * @typedef {{\n * hasNoTypes: boolean,\n * maxNamedTagLength: import('./iterateJsdoc.js').Integer,\n * maxUnnamedTagLength: import('./iterateJsdoc.js').Integer\n * }} TypelessInfo\n */\n\nconst {\n rewireSource,\n} = util;\n\n/**\n * @typedef {{\n * name: import('./iterateJsdoc.js').Integer,\n * start: import('./iterateJsdoc.js').Integer,\n * tag: import('./iterateJsdoc.js').Integer,\n * type: import('./iterateJsdoc.js').Integer\n * }} Width\n */\n\n/** @type {Width} */\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\n\n/**\n * @param {string[]} tags\n * @param {import('./iterateJsdoc.js').Integer} index\n * @param {import('comment-parser').Line[]} source\n * @returns {boolean}\n */\nconst shouldAlign = (tags, index, source) => {\n const tag = source[index].tokens.tag.replace('@', '');\n const includesTag = tags.includes(tag);\n\n if (includesTag) {\n return true;\n }\n\n if (tag !== '') {\n return false;\n }\n\n for (let iterator = index; iterator >= 0; iterator--) {\n const previousTag = source[iterator].tokens.tag.replace('@', '');\n\n if (previousTag !== '') {\n if (tags.includes(previousTag)) {\n return true;\n }\n\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * @param {string[]} tags\n * @returns {(\n * width: Width,\n * line: {\n * tokens: import('comment-parser').Tokens\n * },\n * index: import('./iterateJsdoc.js').Integer,\n * source: import('comment-parser').Line[]\n * ) => Width}\n */\nconst getWidth = (tags) => {\n return (width, {\n tokens,\n }, index, source) => {\n if (!shouldAlign(tags, index, source)) {\n return width;\n }\n\n return {\n name: Math.max(width.name, tokens.name.length),\n start: tokens.delimiter === '/**' ? tokens.start.length : width.start,\n tag: Math.max(width.tag, tokens.tag.length),\n type: Math.max(width.type, tokens.type.length),\n };\n };\n};\n\n/**\n * @param {{\n * description: string;\n * tags: import('comment-parser').Spec[];\n * problems: import('comment-parser').Problem[];\n * }} fields\n * @returns {TypelessInfo}\n */\nconst getTypelessInfo = (fields) => {\n const hasNoTypes = fields.tags.every(({\n type,\n }) => {\n return !type;\n });\n const maxNamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? -1 : tag.length;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n const maxUnnamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? tag.length : -1;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n return {\n hasNoTypes,\n maxNamedTagLength,\n maxUnnamedTagLength,\n };\n};\n\n/**\n * @param {import('./iterateJsdoc.js').Integer} len\n * @returns {string}\n */\nconst space = (len) => {\n return ''.padStart(len, ' ');\n};\n\n/**\n * @param {{\n * customSpacings: import('../src/rules/checkLineAlignment.js').CustomSpacings,\n * tags: string[],\n * indent: string,\n * preserveMainDescriptionPostDelimiter: boolean,\n * wrapIndent: string,\n * }} cfg\n * @returns {(\n * block: import('comment-parser').Block\n * ) => import('comment-parser').Block}\n */\nconst alignTransform = ({\n customSpacings,\n tags,\n indent,\n preserveMainDescriptionPostDelimiter,\n wrapIndent,\n}) => {\n let intoTags = false;\n /** @type {Width} */\n let width;\n\n /**\n * @param {import('comment-parser').Tokens} tokens\n * @param {TypelessInfo} typelessInfo\n * @returns {import('comment-parser').Tokens}\n */\n const alignTokens = (tokens, typelessInfo) => {\n const nothingAfter = {\n delim: false,\n name: false,\n tag: false,\n type: false,\n };\n\n if (tokens.description === '') {\n nothingAfter.name = true;\n tokens.postName = '';\n\n if (tokens.name === '') {\n nothingAfter.type = true;\n tokens.postType = '';\n\n if (tokens.type === '') {\n nothingAfter.tag = true;\n tokens.postTag = '';\n\n /* c8 ignore next: Never happens because the !intoTags return. But it's here for consistency with the original align transform */\n if (tokens.tag === '') {\n nothingAfter.delim = true;\n }\n }\n }\n }\n\n let untypedNameAdjustment = 0;\n let untypedTypeAdjustment = 0;\n if (typelessInfo.hasNoTypes) {\n nothingAfter.tag = true;\n tokens.postTag = '';\n if (tokens.name === '') {\n untypedNameAdjustment = typelessInfo.maxNamedTagLength - tokens.tag.length;\n } else {\n untypedNameAdjustment = typelessInfo.maxNamedTagLength > typelessInfo.maxUnnamedTagLength ? 0 :\n Math.max(0, typelessInfo.maxUnnamedTagLength - (tokens.tag.length + tokens.name.length + 1));\n untypedTypeAdjustment = typelessInfo.maxNamedTagLength - tokens.tag.length;\n }\n }\n\n // Todo: Avoid fixing alignment of blocks with multiline wrapping of type\n if (tokens.tag === '' && tokens.type) {\n return tokens;\n }\n\n const spacings = {\n postDelimiter: customSpacings?.postDelimiter || 1,\n postName: customSpacings?.postName || 1,\n postTag: customSpacings?.postTag || 1,\n postType: customSpacings?.postType || 1,\n };\n\n tokens.postDelimiter = nothingAfter.delim ? '' : space(spacings.postDelimiter);\n\n if (!nothingAfter.tag) {\n tokens.postTag = space(width.tag - tokens.tag.length + spacings.postTag);\n }\n\n if (!nothingAfter.type) {\n tokens.postType = space(width.type - tokens.type.length + spacings.postType + untypedTypeAdjustment);\n }\n\n if (!nothingAfter.name) {\n // If post name is empty for all lines (name width 0), don't add post name spacing.\n tokens.postName = width.name === 0 ? '' : space(width.name - tokens.name.length + spacings.postName + untypedNameAdjustment);\n }\n\n return tokens;\n };\n\n /**\n * @param {import('comment-parser').Line} line\n * @param {import('./iterateJsdoc.js').Integer} index\n * @param {import('comment-parser').Line[]} source\n * @param {TypelessInfo} typelessInfo\n * @param {string|false} indentTag\n * @returns {import('comment-parser').Line}\n */\n const update = (line, index, source, typelessInfo, indentTag) => {\n /** @type {import('comment-parser').Tokens} */\n const tokens = {\n ...line.tokens,\n };\n\n if (tokens.tag !== '') {\n intoTags = true;\n }\n\n const isEmpty =\n tokens.tag === '' &&\n tokens.name === '' &&\n tokens.type === '' &&\n tokens.description === '';\n\n // dangling '*/'\n if (tokens.end === '*/' && isEmpty) {\n tokens.start = indent + ' ';\n\n return {\n ...line,\n tokens,\n };\n }\n\n switch (tokens.delimiter) {\n case '/**':\n tokens.start = indent;\n break;\n case '*':\n tokens.start = indent + ' ';\n break;\n default:\n tokens.delimiter = '';\n\n // compensate delimiter\n tokens.start = indent + ' ';\n }\n\n if (!intoTags) {\n if (tokens.description === '') {\n tokens.postDelimiter = '';\n } else if (!preserveMainDescriptionPostDelimiter) {\n tokens.postDelimiter = ' ';\n }\n\n return {\n ...line,\n tokens,\n };\n }\n\n const postHyphenSpacing = customSpacings?.postHyphen ?? 1;\n const hyphenSpacing = /^\\s*-\\s+/u;\n tokens.description = tokens.description.replace(\n hyphenSpacing, '-' + ''.padStart(postHyphenSpacing, ' '),\n );\n\n // Not align.\n if (shouldAlign(tags, index, source)) {\n alignTokens(tokens, typelessInfo);\n if (indentTag) {\n tokens.postDelimiter += wrapIndent;\n }\n }\n\n return {\n ...line,\n tokens,\n };\n };\n\n return ({\n source,\n ...fields\n }) => {\n width = source.reduce(getWidth(tags), {\n ...zeroWidth,\n });\n\n const typelessInfo = getTypelessInfo(fields);\n\n let tagIndentMode = false;\n\n return rewireSource({\n ...fields,\n source: source.map((line, index) => {\n const indentTag = tagIndentMode && !line.tokens.tag && line.tokens.description;\n const ret = update(line, index, source, typelessInfo, indentTag);\n\n if (line.tokens.tag) {\n tagIndentMode = true;\n }\n\n return ret;\n }),\n });\n };\n};\n\nexport default alignTransform;\n"],"mappings":";;;;;;AAMA,IAAAA,cAAA,GAAAC,OAAA;AANA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM;EACJC;AACF,CAAC,GAAGC,mBAAI;;AAER;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMC,SAAS,GAAG;EAChBC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE,CAAC;EACRC,GAAG,EAAE,CAAC;EACNC,IAAI,EAAE;AACR,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAACC,IAAI,EAAEC,KAAK,EAAEC,MAAM,KAAK;EAC3C,MAAML,GAAG,GAAGK,MAAM,CAACD,KAAK,CAAC,CAACE,MAAM,CAACN,GAAG,CAACO,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;EACrD,MAAMC,WAAW,GAAGL,IAAI,CAACM,QAAQ,CAACT,GAAG,CAAC;EAEtC,IAAIQ,WAAW,EAAE;IACf,OAAO,IAAI;EACb;EAEA,IAAIR,GAAG,KAAK,EAAE,EAAE;IACd,OAAO,KAAK;EACd;EAEA,KAAK,IAAIU,QAAQ,GAAGN,KAAK,EAAEM,QAAQ,IAAI,CAAC,EAAEA,QAAQ,EAAE,EAAE;IACpD,MAAMC,W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MAAM,EAAE+B,YAAY,EAAEa,SAAS,CAAC;QAEhE,IAAID,IAAI,CAAC1C,MAAM,CAACN,GAAG,EAAE;UACnBwD,aAAa,GAAG,IAAI;QACtB;QAEA,OAAOC,GAAG;MACZ,CAAC;IACH,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa/B,cAAc;AAAAgC,MAAA,CAAAF,OAAA,GAAAA,OAAA,CAAAC,OAAA"}
|
|
1
|
+
{"version":3,"file":"alignTransform.cjs","names":["_commentParser","require","rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","getTypelessInfo","fields","hasNoTypes","every","maxNamedTagLength","map","filter","maxUnnamedTagLength","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","wrapIndent","disableWrapIndent","intoTags","alignTokens","typelessInfo","nothingAfter","delim","description","postName","postType","postTag","untypedNameAdjustment","untypedTypeAdjustment","spacings","postDelimiter","update","line","indentTag","isEmpty","end","postHyphenSpacing","postHyphen","hyphenSpacing","reduce","tagIndentMode","ret","_default","exports","default","module"],"sources":["../src/alignTransform.js"],"sourcesContent":["/**\n * Transform based on https://github.com/syavorsky/comment-parser/blob/master/src/transforms/align.ts\n *\n * It contains some customizations to align based on the tags, and some custom options.\n */\n\nimport {\n // `comment-parser/primitives` export\n util,\n} from 'comment-parser';\n\n/**\n * @typedef {{\n * hasNoTypes: boolean,\n * maxNamedTagLength: import('./iterateJsdoc.js').Integer,\n * maxUnnamedTagLength: import('./iterateJsdoc.js').Integer\n * }} TypelessInfo\n */\n\nconst {\n rewireSource,\n} = util;\n\n/**\n * @typedef {{\n * name: import('./iterateJsdoc.js').Integer,\n * start: import('./iterateJsdoc.js').Integer,\n * tag: import('./iterateJsdoc.js').Integer,\n * type: import('./iterateJsdoc.js').Integer\n * }} Width\n */\n\n/** @type {Width} */\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\n\n/**\n * @param {string[]} tags\n * @param {import('./iterateJsdoc.js').Integer} index\n * @param {import('comment-parser').Line[]} source\n * @returns {boolean}\n */\nconst shouldAlign = (tags, index, source) => {\n const tag = source[index].tokens.tag.replace('@', '');\n const includesTag = tags.includes(tag);\n\n if (includesTag) {\n return true;\n }\n\n if (tag !== '') {\n return false;\n }\n\n for (let iterator = index; iterator >= 0; iterator--) {\n const previousTag = source[iterator].tokens.tag.replace('@', '');\n\n if (previousTag !== '') {\n if (tags.includes(previousTag)) {\n return true;\n }\n\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * @param {string[]} tags\n * @returns {(\n * width: Width,\n * line: {\n * tokens: import('comment-parser').Tokens\n * },\n * index: import('./iterateJsdoc.js').Integer,\n * source: import('comment-parser').Line[]\n * ) => Width}\n */\nconst getWidth = (tags) => {\n return (width, {\n tokens,\n }, index, source) => {\n if (!shouldAlign(tags, index, source)) {\n return width;\n }\n\n return {\n name: Math.max(width.name, tokens.name.length),\n start: tokens.delimiter === '/**' ? tokens.start.length : width.start,\n tag: Math.max(width.tag, tokens.tag.length),\n type: Math.max(width.type, tokens.type.length),\n };\n };\n};\n\n/**\n * @param {{\n * description: string;\n * tags: import('comment-parser').Spec[];\n * problems: import('comment-parser').Problem[];\n * }} fields\n * @returns {TypelessInfo}\n */\nconst getTypelessInfo = (fields) => {\n const hasNoTypes = fields.tags.every(({\n type,\n }) => {\n return !type;\n });\n const maxNamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? -1 : tag.length;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n const maxUnnamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? tag.length : -1;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n return {\n hasNoTypes,\n maxNamedTagLength,\n maxUnnamedTagLength,\n };\n};\n\n/**\n * @param {import('./iterateJsdoc.js').Integer} len\n * @returns {string}\n */\nconst space = (len) => {\n return ''.padStart(len, ' ');\n};\n\n/**\n * @param {{\n * customSpacings: import('../src/rules/checkLineAlignment.js').CustomSpacings,\n * tags: string[],\n * indent: string,\n * preserveMainDescriptionPostDelimiter: boolean,\n * wrapIndent: string,\n * disableWrapIndent: boolean,\n * }} cfg\n * @returns {(\n * block: import('comment-parser').Block\n * ) => import('comment-parser').Block}\n */\nconst alignTransform = ({\n customSpacings,\n tags,\n indent,\n preserveMainDescriptionPostDelimiter,\n wrapIndent,\n disableWrapIndent,\n}) => {\n let intoTags = false;\n /** @type {Width} */\n let width;\n\n /**\n * @param {import('comment-parser').Tokens} tokens\n * @param {TypelessInfo} typelessInfo\n * @returns {import('comment-parser').Tokens}\n */\n const alignTokens = (tokens, typelessInfo) => {\n const nothingAfter = {\n delim: false,\n name: false,\n tag: false,\n type: false,\n };\n\n if (tokens.description === '') {\n nothingAfter.name = true;\n tokens.postName = '';\n\n if (tokens.name === '') {\n nothingAfter.type = true;\n tokens.postType = '';\n\n if (tokens.type === '') {\n nothingAfter.tag = true;\n tokens.postTag = '';\n\n /* c8 ignore next: Never happens because the !intoTags return. But it's here for consistency with the original align transform */\n if (tokens.tag === '') {\n nothingAfter.delim = true;\n }\n }\n }\n }\n\n let untypedNameAdjustment = 0;\n let untypedTypeAdjustment = 0;\n if (typelessInfo.hasNoTypes) {\n nothingAfter.tag = true;\n tokens.postTag = '';\n if (tokens.name === '') {\n untypedNameAdjustment = typelessInfo.maxNamedTagLength - tokens.tag.length;\n } else {\n untypedNameAdjustment = typelessInfo.maxNamedTagLength > typelessInfo.maxUnnamedTagLength ? 0 :\n Math.max(0, typelessInfo.maxUnnamedTagLength - (tokens.tag.length + tokens.name.length + 1));\n untypedTypeAdjustment = typelessInfo.maxNamedTagLength - tokens.tag.length;\n }\n }\n\n // Todo: Avoid fixing alignment of blocks with multiline wrapping of type\n if (tokens.tag === '' && tokens.type) {\n return tokens;\n }\n\n const spacings = {\n postDelimiter: customSpacings?.postDelimiter || 1,\n postName: customSpacings?.postName || 1,\n postTag: customSpacings?.postTag || 1,\n postType: customSpacings?.postType || 1,\n };\n\n tokens.postDelimiter = nothingAfter.delim ? '' : space(spacings.postDelimiter);\n\n if (!nothingAfter.tag) {\n tokens.postTag = space(width.tag - tokens.tag.length + spacings.postTag);\n }\n\n if (!nothingAfter.type) {\n tokens.postType = space(width.type - tokens.type.length + spacings.postType + untypedTypeAdjustment);\n }\n\n if (!nothingAfter.name) {\n // If post name is empty for all lines (name width 0), don't add post name spacing.\n tokens.postName = width.name === 0 ? '' : space(width.name - tokens.name.length + spacings.postName + untypedNameAdjustment);\n }\n\n return tokens;\n };\n\n /**\n * @param {import('comment-parser').Line} line\n * @param {import('./iterateJsdoc.js').Integer} index\n * @param {import('comment-parser').Line[]} source\n * @param {TypelessInfo} typelessInfo\n * @param {string|false} indentTag\n * @returns {import('comment-parser').Line}\n */\n const update = (line, index, source, typelessInfo, indentTag) => {\n /** @type {import('comment-parser').Tokens} */\n const tokens = {\n ...line.tokens,\n };\n\n if (tokens.tag !== '') {\n intoTags = true;\n }\n\n const isEmpty =\n tokens.tag === '' &&\n tokens.name === '' &&\n tokens.type === '' &&\n tokens.description === '';\n\n // dangling '*/'\n if (tokens.end === '*/' && isEmpty) {\n tokens.start = indent + ' ';\n\n return {\n ...line,\n tokens,\n };\n }\n\n switch (tokens.delimiter) {\n case '/**':\n tokens.start = indent;\n break;\n case '*':\n tokens.start = indent + ' ';\n break;\n default:\n tokens.delimiter = '';\n\n // compensate delimiter\n tokens.start = indent + ' ';\n }\n\n if (!intoTags) {\n if (tokens.description === '') {\n tokens.postDelimiter = '';\n } else if (!preserveMainDescriptionPostDelimiter) {\n tokens.postDelimiter = ' ';\n }\n\n return {\n ...line,\n tokens,\n };\n }\n\n const postHyphenSpacing = customSpacings?.postHyphen ?? 1;\n const hyphenSpacing = /^\\s*-\\s+/u;\n tokens.description = tokens.description.replace(\n hyphenSpacing, '-' + ''.padStart(postHyphenSpacing, ' '),\n );\n\n // Not align.\n if (shouldAlign(tags, index, source)) {\n alignTokens(tokens, typelessInfo);\n if (!disableWrapIndent && indentTag) {\n tokens.postDelimiter += wrapIndent;\n }\n }\n\n return {\n ...line,\n tokens,\n };\n };\n\n return ({\n source,\n ...fields\n }) => {\n width = source.reduce(getWidth(tags), {\n ...zeroWidth,\n });\n\n const typelessInfo = getTypelessInfo(fields);\n\n let tagIndentMode = false;\n\n return rewireSource({\n ...fields,\n source: source.map((line, index) => {\n const indentTag = !disableWrapIndent && tagIndentMode && !line.tokens.tag && line.tokens.description;\n const ret = update(line, index, source, typelessInfo, indentTag);\n\n if (!disableWrapIndent && line.tokens.tag) {\n tagIndentMode = true;\n }\n\n return ret;\n }),\n });\n };\n};\n\nexport default alignTransform;\n"],"mappings":";;;;;;AAMA,IAAAA,cAAA,GAAAC,OAAA;AANA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM;EACJC;AACF,CAAC,GAAGC,mBAAI;;AAER;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMC,SAAS,GAAG;EAChBC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE,CAAC;EACRC,GAAG,EAAE,CAAC;EACNC,IAAI,EAAE;AACR,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAACC,IAAI,EAAEC,KAAK,EAAEC,MAAM,KAAK;EAC3C,MAAML,GAAG,GAAGK,MAAM,CAACD,KAAK,CAAC,CAACE,MAAM,CAACN,GAAG,CAACO,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;EACrD,MAAMC,WAAW,GAAGL,IAAI,CAACM,QAAQ,CAACT,GAAG,CAAC;EAEtC,IAAIQ,WAAW,EAAE;IACf,OAAO,IAAI;EACb;EAEA,IAAIR,GAAG,KAAK,EAAE,EAAE;IACd,OAAO,KAAK;EACd;EAEA,KAAK,IA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a,IAAI,CAACR,IAAI,CAAC3C,MAAM,CAACN,GAAG,IAAIiD,IAAI,CAAC3C,MAAM,CAACkC,WAAW;QACpG,MAAMkB,GAAG,GAAGV,MAAM,CAACC,IAAI,EAAE7C,KAAK,EAAEC,MAAM,EAAEgC,YAAY,EAAEa,SAAS,CAAC;QAEhE,IAAI,CAAChB,iBAAiB,IAAIe,IAAI,CAAC3C,MAAM,CAACN,GAAG,EAAE;UACzCyD,aAAa,GAAG,IAAI;QACtB;QAEA,OAAOC,GAAG;MACZ,CAAC;IACH,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEahC,cAAc;AAAAiC,MAAA,CAAAF,OAAA,GAAAA,OAAA,CAAAC,OAAA"}
|
|
@@ -145,6 +145,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
|
|
|
145
145
|
* @param {string[]} cfg.tags
|
|
146
146
|
* @param {import('../iterateJsdoc.js').Utils} cfg.utils
|
|
147
147
|
* @param {string} cfg.wrapIndent
|
|
148
|
+
* @param {boolean} cfg.disableWrapIndent
|
|
148
149
|
* @returns {void}
|
|
149
150
|
*/
|
|
150
151
|
const checkAlignment = ({
|
|
@@ -156,14 +157,16 @@ const checkAlignment = ({
|
|
|
156
157
|
report,
|
|
157
158
|
tags,
|
|
158
159
|
utils,
|
|
159
|
-
wrapIndent
|
|
160
|
+
wrapIndent,
|
|
161
|
+
disableWrapIndent
|
|
160
162
|
}) => {
|
|
161
163
|
const transform = commentFlow((0, _alignTransform.default)({
|
|
162
164
|
customSpacings,
|
|
163
165
|
indent,
|
|
164
166
|
preserveMainDescriptionPostDelimiter,
|
|
165
167
|
tags,
|
|
166
|
-
wrapIndent
|
|
168
|
+
wrapIndent,
|
|
169
|
+
disableWrapIndent
|
|
167
170
|
}));
|
|
168
171
|
const transformedJsdoc = transform(jsdoc);
|
|
169
172
|
const comment = '/*' +
|
|
@@ -192,7 +195,8 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
192
195
|
tags: applicableTags = ['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return'],
|
|
193
196
|
preserveMainDescriptionPostDelimiter,
|
|
194
197
|
customSpacings,
|
|
195
|
-
wrapIndent = ''
|
|
198
|
+
wrapIndent = '',
|
|
199
|
+
disableWrapIndent = false
|
|
196
200
|
} = context.options[1] || {};
|
|
197
201
|
if (context.options[0] === 'always') {
|
|
198
202
|
// Skip if it contains only a single line.
|
|
@@ -214,7 +218,8 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
214
218
|
report,
|
|
215
219
|
tags: applicableTags,
|
|
216
220
|
utils,
|
|
217
|
-
wrapIndent
|
|
221
|
+
wrapIndent,
|
|
222
|
+
disableWrapIndent
|
|
218
223
|
});
|
|
219
224
|
return;
|
|
220
225
|
}
|
|
@@ -245,7 +250,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
// Don't include a single separating space/tab
|
|
248
|
-
if (tokens.postDelimiter.slice(1) !== wrapIndent) {
|
|
253
|
+
if (!disableWrapIndent && tokens.postDelimiter.slice(1) !== wrapIndent) {
|
|
249
254
|
utils.reportJSDoc('Expected wrap indent', {
|
|
250
255
|
line: tag.source[0].number + idx
|
|
251
256
|
}, () => {
|
|
@@ -302,6 +307,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
302
307
|
},
|
|
303
308
|
wrapIndent: {
|
|
304
309
|
type: 'string'
|
|
310
|
+
},
|
|
311
|
+
disableWrapIndent: {
|
|
312
|
+
type: 'boolean'
|
|
305
313
|
}
|
|
306
314
|
},
|
|
307
315
|
type: 'object'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkLineAlignment.cjs","names":["_alignTransform","_interopRequireDefault","require","_iterateJsdoc","_commentParser","obj","__esModule","default","flow","commentFlow","transforms","checkNotAlignedPerTag","utils","tag","customSpacings","spacerProps","contentProps","mightHaveNamepath","tagMightHaveNamepath","tokens","source","followedBySpace","idx","callbck","nextIndex","slice","some","spacerProp","innerIdx","contentProp","spacePropVal","ret","postHyphenSpacing","postHyphen","exactHyphenSpacing","RegExp","hasNoHyphen","test","description","hasExactHyphenSpacing","ok","contentPropVal","spacerPropVal","spacing","length","fix","entries","padStart","hasSpace","contentPrp","hyphenSpacing","replace","setTag","reportJSDoc","checkAlignment","indent","jsdoc","jsdocNode","preserveMainDescriptionPostDelimiter","report","tags","wrapIndent","transform","alignTransform","transformedJsdoc","comment","value","formatted","stringify","trimStart","fixer","replaceText","_default","exports","iterateJsdoc","context","applicableTags","options","includes","foundTags","getPresentTags","type","name","postDelimiter","line","number","charAt","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","additionalProperties","properties","postName","postTag","postType","items","module"],"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)`, 'u');\n const hasNoHyphen = !(/^\\s*-(?!$)(?=\\s)/u).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+/u;\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 * @returns {void}\n */\nconst checkAlignment = ({\n customSpacings,\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 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 indent,\n jsdoc,\n jsdocNode,\n report,\n context,\n utils,\n}) => {\n const {\n tags: applicableTags = [\n 'param', 'arg', 'argument', 'property', 'prop', 'returns', 'return',\n ],\n preserveMainDescriptionPostDelimiter,\n customSpacings,\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 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 (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 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":";;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEwB,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAExB,MAAM;EACJG,IAAI,EAAEC;AACR,CAAC,GAAGC,yBAAU;;AAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,GAAGA,CAACC,KAAK,EAAEC,GAAG,EAAEC,cAAc,KAAK;EAC5D;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAEE;AACF;AACA;;EAEE;EACA,IAAIC,WAAW;EACf;EACA,IAAIC,YAAY;EAChB,MAAMC,iBAAiB,GAAGL,KAAK,CAACM,oBAAoB,CAACL,GAAG,CAACA,GAAG,CAAC;EAC7D,IAAII,iBAAiB,EAAE;IACrBF,WAAW,GAAG,CACZ,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,CACnD;IACDC,YAAY,GAAG,CACb,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aA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E;UACpCnD,OAAO,EAAE,KAAK;UACd0E,IAAI,EAAE;QACR,CAAC;QACDrB,IAAI,EAAE;UACJuC,KAAK,EAAE;YACLlB,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDpB,UAAU,EAAE;UACVoB,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAmB,MAAA,CAAA3B,OAAA,GAAAA,OAAA,CAAAlE,OAAA"}
|
|
1
|
+
{"version":3,"file":"checkLineAlignment.cjs","names":["_alignTransform","_interopRequireDefault","require","_iterateJsdoc","_commentParser","obj","__esModule","default","flow","commentFlow","transforms","checkNotAlignedPerTag","utils","tag","customSpacings","spacerProps","contentProps","mightHaveNamepath","tagMightHaveNamepath","tokens","source","followedBySpace","idx","callbck","nextIndex","slice","some","spacerProp","innerIdx","contentProp","spacePropVal","ret","postHyphenSpacing","postHyphen","exactHyphenSpacing","RegExp","hasNoHyphen","test","description","hasExactHyphenSpacing","ok","contentPropVal","spacerPropVal","spacing","length","fix","entries","padStart","hasSpace","contentPrp","hyphenSpacing","replace","setTag","reportJSDoc","checkAlignment","indent","jsdoc","jsdocNode","preserveMainDescriptionPostDelimiter","report","tags","wrapIndent","disableWrapIndent","transform","alignTransform","transformedJsdoc","comment","value","formatted","stringify","trimStart","fixer","replaceText","_default","exports","iterateJsdoc","context","applicableTags","options","includes","foundTags","getPresentTags","type","name","postDelimiter","line","number","charAt","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","additionalProperties","properties","postName","postTag","postType","items","module"],"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)`, 'u');\n const hasNoHyphen = !(/^\\s*-(?!$)(?=\\s)/u).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+/u;\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 indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags,\n utils,\n wrapIndent,\n disableWrapIndent,\n}) => {\n const transform = commentFlow(\n alignTransform({\n customSpacings,\n indent,\n preserveMainDescriptionPostDelimiter,\n tags,\n wrapIndent,\n disableWrapIndent,\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 indent,\n jsdoc,\n jsdocNode,\n report,\n context,\n utils,\n}) => {\n const {\n tags: applicableTags = [\n 'param', 'arg', 'argument', 'property', 'prop', 'returns', 'return',\n ],\n preserveMainDescriptionPostDelimiter,\n customSpacings,\n wrapIndent = '',\n disableWrapIndent = false,\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 indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags: applicableTags,\n utils,\n wrapIndent,\n disableWrapIndent,\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 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 disableWrapIndent: {\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEwB,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,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CAAC;UACF;QACF;MACF;IACF;EACF;AACF,CAAC,EAAE;EACD2B,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJpD,WAAW,EAAE,iDAAiD;MAC9DqD,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,YAAY;IACrBC,MAAM,EAAE,CACN;MACEC,IAAI,EAAE,CACJ,QAAQ,EAAE,OAAO,EAAE,KAAK,CACzB;MACDZ,IAAI,EAAE;IACR,CAAC,EACD;MACEa,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVlF,cAAc,EAAE;UACdiF,oBAAoB,EAAE,KAAK;UAC3BC,UAAU,EAAE;YACVZ,aAAa,EAAE;cACbF,IAAI,EAAE;YACR,CAAC;YACDjD,UAAU,EAAE;cACViD,IAAI,EAAE;YACR,CAAC;YACDe,QAAQ,EAAE;cACRf,IAAI,EAAE;YACR,CAAC;YACDgB,OAAO,EAAE;cACPhB,IAAI,EAAE;YACR,CAAC;YACDiB,QAAQ,EAAE;cACRjB,IAAI,EAAE;YACR;UACF;QACF,CAAC;QACDxB,oCAAoC,EAAE;UACpCnD,OAAO,EAAE,KAAK;UACd2E,IAAI,EAAE;QACR,CAAC;QACDtB,IAAI,EAAE;UACJwC,KAAK,EAAE;YACLlB,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDrB,UAAU,EAAE;UACVqB,IAAI,EAAE;QACR,CAAC;QACDpB,iBAAiB,EAAE;UACjBoB,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAmB,MAAA,CAAA3B,OAAA,GAAAA,OAAA,CAAAnE,OAAA"}
|
|
@@ -28,6 +28,10 @@ const getNamesFromNode = node => {
|
|
|
28
28
|
case 'TSAbstractPropertyDefinition':
|
|
29
29
|
return [...getNamesFromNode( /** @type {import('@typescript-eslint/types').TSESTree.Node} */node.parent.parent), ...getNamesFromNode( /** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
30
30
|
node.key)];
|
|
31
|
+
case 'ExportDefaultDeclaration':
|
|
32
|
+
case 'ExportNamedDeclaration':
|
|
33
|
+
return getNamesFromNode( /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */
|
|
34
|
+
node.declaration);
|
|
31
35
|
case 'ClassDeclaration':
|
|
32
36
|
case 'ClassExpression':
|
|
33
37
|
case 'FunctionDeclaration':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"informativeDocs.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_areDocsInformative","obj","__esModule","default","defaultAliases","a","defaultUselessWords","getNamesFromNode","node","type","parent","key","id","name","declarations","init","filter","Boolean","_default","exports","iterateJsdoc","context","jsdoc","report","utils","aliases","excludedTags","uselessWords","options","nodeNames","descriptionIsRedundant","text","extraName","textTrimmed","trim","areDocsInformative","join","description","lastDescriptionLine","getDescription","descriptionReported","tag","tags","includes","reportJSDoc","line","iterateAllJsdocs","meta","docs","url","schema","additionalProperties","properties","patternProperties","items","module"],"sources":["../../src/rules/informativeDocs.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n areDocsInformative,\n} from 'are-docs-informative';\n\nconst defaultAliases = {\n a: [\n 'an', 'our',\n ],\n};\n\nconst defaultUselessWords = [\n 'a', 'an', 'i', 'in', 'of', 's', 'the',\n];\n\n/* eslint-disable complexity -- Temporary */\n\n/**\n * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null|undefined} node\n * @returns {string[]}\n */\nconst getNamesFromNode = (node) => {\n switch (node?.type) {\n case 'AccessorProperty':\n case 'MethodDefinition':\n case 'PropertyDefinition':\n case 'TSAbstractAccessorProperty':\n case 'TSAbstractMethodDefinition':\n case 'TSAbstractPropertyDefinition':\n return [\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node.parent\n ).parent,\n ),\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.key),\n ),\n ];\n case 'ClassDeclaration':\n case 'ClassExpression':\n case 'FunctionDeclaration':\n case 'FunctionExpression':\n case 'TSModuleDeclaration':\n case 'TSMethodSignature':\n case 'TSDeclareFunction':\n case 'TSEnumDeclaration':\n case 'TSEnumMember':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.ClassDeclaration} */\n (node).id,\n );\n case 'Identifier':\n return [\n node.name,\n ];\n case 'Property':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.key),\n );\n case 'VariableDeclaration':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.declarations[0]),\n );\n case 'VariableDeclarator':\n return [\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.id),\n ),\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.init),\n ),\n ].filter(Boolean);\n default:\n return [];\n }\n};\n/* eslint-enable complexity -- Temporary */\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n node,\n report,\n utils,\n}) => {\n const /** @type {{aliases: {[key: string]: string[]}, excludedTags: string[], uselessWords: string[]}} */ {\n aliases = defaultAliases,\n excludedTags = [],\n uselessWords = defaultUselessWords,\n } = context.options[0] || {};\n const nodeNames = getNamesFromNode(node);\n\n /**\n * @param {string} text\n * @param {string} extraName\n * @returns {boolean}\n */\n const descriptionIsRedundant = (text, extraName = '') => {\n const textTrimmed = text.trim();\n return Boolean(textTrimmed) && !areDocsInformative(textTrimmed, [\n extraName, nodeNames,\n ].filter(Boolean).join(' '), {\n aliases,\n uselessWords,\n });\n };\n\n const {\n description,\n lastDescriptionLine,\n } = utils.getDescription();\n let descriptionReported = false;\n\n for (const tag of jsdoc.tags) {\n if (excludedTags.includes(tag.tag)) {\n continue;\n }\n\n if (descriptionIsRedundant(tag.description, tag.name)) {\n utils.reportJSDoc(\n 'This tag description only repeats the name it describes.',\n tag,\n );\n }\n\n descriptionReported ||= tag.description === description &&\n /** @type {import('comment-parser').Spec & {line: import('../iterateJsdoc.js').Integer}} */\n (tag).line === lastDescriptionLine;\n }\n\n if (!descriptionReported && descriptionIsRedundant(description)) {\n report('This description only repeats the name it describes.');\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description:\n 'This rule reports doc comments that only restate their attached name.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n aliases: {\n patternProperties: {\n '.*': {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n },\n excludedTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n uselessWords: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AAE8B,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE9B,MAAMG,cAAc,GAAG;EACrBC,CAAC,EAAE,CACD,IAAI,EAAE,KAAK;AAEf,CAAC;AAED,MAAMC,mBAAmB,GAAG,CAC1B,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CACvC;;AAED;;AAEA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAIC,IAAI,IAAK;EACjC,QAAQA,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEC,IAAI;IAClB,KAAK,kBAAkB;IACvB,KAAK,kBAAkB;IACvB,KAAK,oBAAoB;IACzB,KAAK,4BAA4B;IACjC,KAAK,4BAA4B;IACjC,KAAK,8BAA8B;MACjC,OAAO,CACL,GAAGF,gBAAgB,EACjB,+DACEC,IAAI,CAACE,MAAM,CACXA,MACJ,CAAC,EACD,GAAGH,gBAAgB,EACjB;MACCC,IAAI,CAACG,GACR,CAAC,CACF;IACH,KAAK,kBAAkB;IACvB,KAAK,iBAAiB;IACtB,KAAK,qBAAqB;IAC1B,KAAK,oBAAoB;IACzB,KAAK,qBAAqB;IAC1B,KAAK,mBAAmB;IACxB,KAAK,mBAAmB;IACxB,KAAK,mBAAmB;IACxB,KAAK,cAAc;IACnB,KAAK,wBAAwB;IAC7B,KAAK,wBAAwB;MAC3B,
|
|
1
|
+
{"version":3,"file":"informativeDocs.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_areDocsInformative","obj","__esModule","default","defaultAliases","a","defaultUselessWords","getNamesFromNode","node","type","parent","key","declaration","id","name","declarations","init","filter","Boolean","_default","exports","iterateJsdoc","context","jsdoc","report","utils","aliases","excludedTags","uselessWords","options","nodeNames","descriptionIsRedundant","text","extraName","textTrimmed","trim","areDocsInformative","join","description","lastDescriptionLine","getDescription","descriptionReported","tag","tags","includes","reportJSDoc","line","iterateAllJsdocs","meta","docs","url","schema","additionalProperties","properties","patternProperties","items","module"],"sources":["../../src/rules/informativeDocs.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n areDocsInformative,\n} from 'are-docs-informative';\n\nconst defaultAliases = {\n a: [\n 'an', 'our',\n ],\n};\n\nconst defaultUselessWords = [\n 'a', 'an', 'i', 'in', 'of', 's', 'the',\n];\n\n/* eslint-disable complexity -- Temporary */\n\n/**\n * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null|undefined} node\n * @returns {string[]}\n */\nconst getNamesFromNode = (node) => {\n switch (node?.type) {\n case 'AccessorProperty':\n case 'MethodDefinition':\n case 'PropertyDefinition':\n case 'TSAbstractAccessorProperty':\n case 'TSAbstractMethodDefinition':\n case 'TSAbstractPropertyDefinition':\n return [\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node.parent\n ).parent,\n ),\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.key),\n ),\n ];\n\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */\n (node).declaration\n );\n case 'ClassDeclaration':\n case 'ClassExpression':\n case 'FunctionDeclaration':\n case 'FunctionExpression':\n case 'TSModuleDeclaration':\n case 'TSMethodSignature':\n case 'TSDeclareFunction':\n case 'TSEnumDeclaration':\n case 'TSEnumMember':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.ClassDeclaration} */\n (node).id,\n );\n case 'Identifier':\n return [\n node.name,\n ];\n case 'Property':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.key),\n );\n case 'VariableDeclaration':\n return getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.declarations[0]),\n );\n case 'VariableDeclarator':\n return [\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.id),\n ),\n ...getNamesFromNode(\n /** @type {import('@typescript-eslint/types').TSESTree.Node} */\n (node.init),\n ),\n ].filter(Boolean);\n default:\n return [];\n }\n};\n/* eslint-enable complexity -- Temporary */\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n node,\n report,\n utils,\n}) => {\n const /** @type {{aliases: {[key: string]: string[]}, excludedTags: string[], uselessWords: string[]}} */ {\n aliases = defaultAliases,\n excludedTags = [],\n uselessWords = defaultUselessWords,\n } = context.options[0] || {};\n const nodeNames = getNamesFromNode(node);\n\n /**\n * @param {string} text\n * @param {string} extraName\n * @returns {boolean}\n */\n const descriptionIsRedundant = (text, extraName = '') => {\n const textTrimmed = text.trim();\n return Boolean(textTrimmed) && !areDocsInformative(textTrimmed, [\n extraName, nodeNames,\n ].filter(Boolean).join(' '), {\n aliases,\n uselessWords,\n });\n };\n\n const {\n description,\n lastDescriptionLine,\n } = utils.getDescription();\n let descriptionReported = false;\n\n for (const tag of jsdoc.tags) {\n if (excludedTags.includes(tag.tag)) {\n continue;\n }\n\n if (descriptionIsRedundant(tag.description, tag.name)) {\n utils.reportJSDoc(\n 'This tag description only repeats the name it describes.',\n tag,\n );\n }\n\n descriptionReported ||= tag.description === description &&\n /** @type {import('comment-parser').Spec & {line: import('../iterateJsdoc.js').Integer}} */\n (tag).line === lastDescriptionLine;\n }\n\n if (!descriptionReported && descriptionIsRedundant(description)) {\n report('This description only repeats the name it describes.');\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description:\n 'This rule reports doc comments that only restate their attached name.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n aliases: {\n patternProperties: {\n '.*': {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n },\n excludedTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n uselessWords: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AAE8B,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE9B,MAAMG,cAAc,GAAG;EACrBC,CAAC,EAAE,CACD,IAAI,EAAE,KAAK;AAEf,CAAC;AAED,MAAMC,mBAAmB,GAAG,CAC1B,GAAG,EAAE,IAAI,EAAE,GAAG,EAA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AmB,KAAKC,GAAG,CAACJ,WAAW,KAAKA,WAAW,IACrD;IACCI,GAAG,CAAEI,IAAI,KAAKP,mBAAmB;EACtC;EAEA,IAAI,CAACE,mBAAmB,IAAIV,sBAAsB,CAACO,WAAW,CAAC,EAAE;IAC/Dd,MAAM,CAAC,sDAAsD,CAAC;EAChE;AACF,CAAC,EAAE;EACDuB,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJX,WAAW,EACT,uEAAuE;MACzEY,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV3B,OAAO,EAAE;UACP4B,iBAAiB,EAAE;YACjB,IAAI,EAAE;cACJC,KAAK,EAAE;gBACL9C,IAAI,EAAE;cACR,CAAC;cACDA,IAAI,EAAE;YACR;UACF;QACF,CAAC;QACDkB,YAAY,EAAE;UACZ4B,KAAK,EAAE;YACL9C,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDmB,YAAY,EAAE;UACZ2B,KAAK,EAAE;YACL9C,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA+C,MAAA,CAAApC,OAAA,GAAAA,OAAA,CAAAjB,OAAA"}
|
package/package.json
CHANGED
|
@@ -5,25 +5,25 @@
|
|
|
5
5
|
"url": "http://gajus.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@es-joy/jsdoccomment": "~0.
|
|
8
|
+
"@es-joy/jsdoccomment": "~0.42.0",
|
|
9
9
|
"are-docs-informative": "^0.0.2",
|
|
10
10
|
"comment-parser": "1.4.1",
|
|
11
11
|
"debug": "^4.3.4",
|
|
12
12
|
"escape-string-regexp": "^4.0.0",
|
|
13
13
|
"esquery": "^1.5.0",
|
|
14
14
|
"is-builtin-module": "^3.2.1",
|
|
15
|
-
"semver": "^7.
|
|
15
|
+
"semver": "^7.6.0",
|
|
16
16
|
"spdx-expression-parse": "^4.0.0"
|
|
17
17
|
},
|
|
18
18
|
"description": "JSDoc linting rules for ESLint.",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/cli": "^7.23.
|
|
21
|
-
"@babel/core": "^7.23.
|
|
22
|
-
"@babel/eslint-parser": "^7.23.
|
|
23
|
-
"@babel/node": "^7.
|
|
20
|
+
"@babel/cli": "^7.23.9",
|
|
21
|
+
"@babel/core": "^7.23.9",
|
|
22
|
+
"@babel/eslint-parser": "^7.23.10",
|
|
23
|
+
"@babel/node": "^7.23.9",
|
|
24
24
|
"@babel/plugin-syntax-class-properties": "^7.12.13",
|
|
25
25
|
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
|
|
26
|
-
"@babel/preset-env": "^7.23.
|
|
26
|
+
"@babel/preset-env": "^7.23.9",
|
|
27
27
|
"@es-joy/escodegen": "^3.5.1",
|
|
28
28
|
"@es-joy/jsdoc-eslint-parser": "^0.21.1",
|
|
29
29
|
"@hkdobrev/run-if-changed": "^0.3.1",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@types/json-schema": "^7.0.15",
|
|
39
39
|
"@types/lodash.defaultsdeep": "^4.6.9",
|
|
40
40
|
"@types/mocha": "^10.0.6",
|
|
41
|
-
"@types/node": "^20.11.
|
|
41
|
+
"@types/node": "^20.11.16",
|
|
42
42
|
"@types/semver": "^7.5.6",
|
|
43
43
|
"@types/spdx-expression-parse": "^3.0.5",
|
|
44
|
-
"@typescript-eslint/parser": "^6.
|
|
44
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
45
45
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
46
46
|
"babel-plugin-istanbul": "^6.1.1",
|
|
47
47
|
"c8": "^9.1.0",
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
"decamelize": "^5.0.1",
|
|
52
52
|
"eslint": "9.0.0-alpha.0",
|
|
53
53
|
"eslint-config-canonical": "~42.8.1",
|
|
54
|
-
"espree": "^
|
|
54
|
+
"espree": "^10.0.0",
|
|
55
55
|
"gitdown": "^3.1.5",
|
|
56
56
|
"glob": "^10.3.10",
|
|
57
57
|
"globals": "^13.24.0",
|
|
58
|
-
"husky": "^
|
|
58
|
+
"husky": "^9.0.10",
|
|
59
59
|
"jsdoc-type-pratt-parser": "^4.0.0",
|
|
60
60
|
"json-schema": "^0.4.0",
|
|
61
|
-
"lint-staged": "^15.2.
|
|
61
|
+
"lint-staged": "^15.2.2",
|
|
62
62
|
"lodash.defaultsdeep": "^4.6.1",
|
|
63
63
|
"mocha": "^10.2.0",
|
|
64
64
|
"open-editor": "^3.0.0",
|
|
@@ -141,5 +141,5 @@
|
|
|
141
141
|
"test-cov": "cross-env TIMING=1 c8 --reporter text npm run test-no-cov",
|
|
142
142
|
"test-index": "npm run test-no-cov -- test/rules/index.js"
|
|
143
143
|
},
|
|
144
|
-
"version": "48.0
|
|
144
|
+
"version": "48.1.0"
|
|
145
145
|
}
|
package/src/alignTransform.js
CHANGED
|
@@ -151,6 +151,7 @@ const space = (len) => {
|
|
|
151
151
|
* indent: string,
|
|
152
152
|
* preserveMainDescriptionPostDelimiter: boolean,
|
|
153
153
|
* wrapIndent: string,
|
|
154
|
+
* disableWrapIndent: boolean,
|
|
154
155
|
* }} cfg
|
|
155
156
|
* @returns {(
|
|
156
157
|
* block: import('comment-parser').Block
|
|
@@ -162,6 +163,7 @@ const alignTransform = ({
|
|
|
162
163
|
indent,
|
|
163
164
|
preserveMainDescriptionPostDelimiter,
|
|
164
165
|
wrapIndent,
|
|
166
|
+
disableWrapIndent,
|
|
165
167
|
}) => {
|
|
166
168
|
let intoTags = false;
|
|
167
169
|
/** @type {Width} */
|
|
@@ -314,7 +316,7 @@ const alignTransform = ({
|
|
|
314
316
|
// Not align.
|
|
315
317
|
if (shouldAlign(tags, index, source)) {
|
|
316
318
|
alignTokens(tokens, typelessInfo);
|
|
317
|
-
if (indentTag) {
|
|
319
|
+
if (!disableWrapIndent && indentTag) {
|
|
318
320
|
tokens.postDelimiter += wrapIndent;
|
|
319
321
|
}
|
|
320
322
|
}
|
|
@@ -340,10 +342,10 @@ const alignTransform = ({
|
|
|
340
342
|
return rewireSource({
|
|
341
343
|
...fields,
|
|
342
344
|
source: source.map((line, index) => {
|
|
343
|
-
const indentTag = tagIndentMode && !line.tokens.tag && line.tokens.description;
|
|
345
|
+
const indentTag = !disableWrapIndent && tagIndentMode && !line.tokens.tag && line.tokens.description;
|
|
344
346
|
const ret = update(line, index, source, typelessInfo, indentTag);
|
|
345
347
|
|
|
346
|
-
if (line.tokens.tag) {
|
|
348
|
+
if (!disableWrapIndent && line.tokens.tag) {
|
|
347
349
|
tagIndentMode = true;
|
|
348
350
|
}
|
|
349
351
|
|
|
@@ -169,6 +169,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
|
|
|
169
169
|
* @param {string[]} cfg.tags
|
|
170
170
|
* @param {import('../iterateJsdoc.js').Utils} cfg.utils
|
|
171
171
|
* @param {string} cfg.wrapIndent
|
|
172
|
+
* @param {boolean} cfg.disableWrapIndent
|
|
172
173
|
* @returns {void}
|
|
173
174
|
*/
|
|
174
175
|
const checkAlignment = ({
|
|
@@ -181,6 +182,7 @@ const checkAlignment = ({
|
|
|
181
182
|
tags,
|
|
182
183
|
utils,
|
|
183
184
|
wrapIndent,
|
|
185
|
+
disableWrapIndent,
|
|
184
186
|
}) => {
|
|
185
187
|
const transform = commentFlow(
|
|
186
188
|
alignTransform({
|
|
@@ -189,6 +191,7 @@ const checkAlignment = ({
|
|
|
189
191
|
preserveMainDescriptionPostDelimiter,
|
|
190
192
|
tags,
|
|
191
193
|
wrapIndent,
|
|
194
|
+
disableWrapIndent,
|
|
192
195
|
}),
|
|
193
196
|
);
|
|
194
197
|
const transformedJsdoc = transform(jsdoc);
|
|
@@ -228,6 +231,7 @@ export default iterateJsdoc(({
|
|
|
228
231
|
preserveMainDescriptionPostDelimiter,
|
|
229
232
|
customSpacings,
|
|
230
233
|
wrapIndent = '',
|
|
234
|
+
disableWrapIndent = false,
|
|
231
235
|
} = context.options[1] || {};
|
|
232
236
|
|
|
233
237
|
if (context.options[0] === 'always') {
|
|
@@ -253,6 +257,7 @@ export default iterateJsdoc(({
|
|
|
253
257
|
tags: applicableTags,
|
|
254
258
|
utils,
|
|
255
259
|
wrapIndent,
|
|
260
|
+
disableWrapIndent,
|
|
256
261
|
});
|
|
257
262
|
|
|
258
263
|
return;
|
|
@@ -293,7 +298,7 @@ export default iterateJsdoc(({
|
|
|
293
298
|
}
|
|
294
299
|
|
|
295
300
|
// Don't include a single separating space/tab
|
|
296
|
-
if (tokens.postDelimiter.slice(1) !== wrapIndent) {
|
|
301
|
+
if (!disableWrapIndent && tokens.postDelimiter.slice(1) !== wrapIndent) {
|
|
297
302
|
utils.reportJSDoc('Expected wrap indent', {
|
|
298
303
|
line: tag.source[0].number + idx,
|
|
299
304
|
}, () => {
|
|
@@ -355,6 +360,9 @@ export default iterateJsdoc(({
|
|
|
355
360
|
wrapIndent: {
|
|
356
361
|
type: 'string',
|
|
357
362
|
},
|
|
363
|
+
disableWrapIndent: {
|
|
364
|
+
type: 'boolean',
|
|
365
|
+
},
|
|
358
366
|
},
|
|
359
367
|
type: 'object',
|
|
360
368
|
},
|
|
@@ -38,6 +38,13 @@ const getNamesFromNode = (node) => {
|
|
|
38
38
|
(node.key),
|
|
39
39
|
),
|
|
40
40
|
];
|
|
41
|
+
|
|
42
|
+
case 'ExportDefaultDeclaration':
|
|
43
|
+
case 'ExportNamedDeclaration':
|
|
44
|
+
return getNamesFromNode(
|
|
45
|
+
/** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */
|
|
46
|
+
(node).declaration
|
|
47
|
+
);
|
|
41
48
|
case 'ClassDeclaration':
|
|
42
49
|
case 'ClassExpression':
|
|
43
50
|
case 'FunctionDeclaration':
|