summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js')
-rw-r--r--tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js100
1 files changed, 84 insertions, 16 deletions
diff --git a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js
index 591c0daa76..d376e811b9 100644
--- a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js
+++ b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js
@@ -105,12 +105,24 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
return iteratingAll && utils.hasATag(['callback', 'function', 'func', 'method']);
};
utils.stringify = (tagBlock, specRewire) => {
- return (0, _commentParser.stringify)(specRewire ? rewireSpecs(tagBlock) : tagBlock);
+ let block;
+ if (specRewire) {
+ block = rewireSpecs(tagBlock);
+ }
+ return (0, _commentParser.stringify)(specRewire ? block : tagBlock);
};
utils.reportJSDoc = (msg, tag, handler, specRewire, data) => {
report(msg, handler ? fixer => {
handler();
const replacement = utils.stringify(jsdoc, specRewire);
+ if (!replacement) {
+ const text = sourceCode.getText();
+ const lastLineBreakPos = text.slice(0, jsdocNode.range[0]).search(/\n[ \t]*$/u);
+ if (lastLineBreakPos > -1) {
+ return fixer.removeRange([lastLineBreakPos, jsdocNode.range[1]]);
+ }
+ return fixer.removeRange(/\s/u.test(text.charAt(jsdocNode.range[1])) ? [jsdocNode.range[0], jsdocNode.range[1] + 1] : jsdocNode.range);
+ }
return fixer.replaceText(jsdocNode, replacement);
} : null, tag, data);
};
@@ -165,6 +177,7 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
utils.getDescription = () => {
const descriptions = [];
let lastDescriptionLine = 0;
+ let tagsBegun = false;
jsdoc.source.some(({
tokens: {
description,
@@ -172,14 +185,17 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
end
}
}, idx) => {
+ if (tag) {
+ tagsBegun = true;
+ }
if (idx && (tag || end)) {
lastDescriptionLine = idx - 1;
- if (!tag && description) {
+ if (!tagsBegun && description) {
descriptions.push(description);
}
return true;
}
- if (idx || description) {
+ if (!tagsBegun && (idx || description)) {
descriptions.push(description || (descriptions.length ? '' : '\n'));
}
return false;
@@ -190,6 +206,45 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
lastDescriptionLine
};
};
+ utils.setBlockDescription = setter => {
+ const descLines = [];
+ let startIdx;
+ let endIdx;
+ let info;
+ jsdoc.source.some(({
+ tokens: {
+ description,
+ start,
+ delimiter,
+ postDelimiter,
+ tag,
+ end
+ }
+ }, idx) => {
+ if (delimiter === '/**') {
+ return false;
+ }
+ if (startIdx === undefined) {
+ startIdx = idx;
+ info = {
+ delimiter,
+ postDelimiter,
+ start
+ };
+ }
+ if (tag || end) {
+ endIdx = idx;
+ return true;
+ }
+ descLines.push(description);
+ return false;
+ });
+
+ /* istanbul ignore else -- Won't be called if missing */
+ if (descLines.length) {
+ jsdoc.source.splice(startIdx, endIdx - startIdx, ...setter(info, seedTokens, descLines));
+ }
+ };
utils.setDescriptionLines = (matcher, setter) => {
let finalIdx = 0;
jsdoc.source.some(({
@@ -233,10 +288,10 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
})
}];
};
- utils.removeTag = idx => {
- return utils.removeTagItem(idx);
- };
- utils.removeTagItem = (tagIndex, tagSourceOffset = 0) => {
+ utils.removeTag = (tagIndex, {
+ removeEmptyBlock = false,
+ tagSourceOffset = 0
+ } = {}) => {
const {
source: tagSource
} = jsdoc.tags[tagIndex];
@@ -246,12 +301,9 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
number
}, tagIdx) => {
const sourceIndex = jsdoc.source.findIndex(({
- number: srcNumber,
- tokens: {
- end
- }
+ number: srcNumber
}) => {
- return number === srcNumber && !end;
+ return number === srcNumber;
});
// istanbul ignore else
if (sourceIndex > -1) {
@@ -259,17 +311,33 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
tagSource.slice(tagIdx + 1).some(({
tokens: {
tag,
- end
+ end: ending
}
}) => {
- if (!tag && !end) {
+ if (!tag && !ending) {
spliceCount++;
return false;
}
return true;
});
- jsdoc.source.splice(sourceIndex + tagSourceOffset, spliceCount - tagSourceOffset);
- tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset);
+ const spliceIdx = sourceIndex + tagSourceOffset;
+ const {
+ delimiter,
+ end
+ } = jsdoc.source[spliceIdx].tokens;
+
+ /* istanbul ignore if -- Currently want to clear entirely if removing tags */
+ if (spliceIdx === 0 && jsdoc.tags.length >= 2 || !removeEmptyBlock && (end || delimiter === '/**')) {
+ const {
+ tokens
+ } = jsdoc.source[spliceIdx];
+ for (const item of ['postDelimiter', 'tag', 'postTag', 'type', 'postType', 'name', 'postName', 'description']) {
+ tokens[item] = '';
+ }
+ } else {
+ jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
+ tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
+ }
lastIndex = sourceIndex;
return true;
}