1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = iterateJsdoc;
- exports.getSettings = void 0;
- Object.defineProperty(exports, "parseComment", {
- enumerable: true,
- get: function () {
- return _jsdoccomment.parseComment;
- }
- });
- var _jsdocUtils = _interopRequireDefault(require("./jsdocUtils.js"));
- var _jsdoccomment = require("@es-joy/jsdoccomment");
- var _commentParser = require("comment-parser");
- var _esquery = _interopRequireDefault(require("esquery"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- const {
- rewireSpecs,
- seedTokens
- } = _commentParser.util;
- const globalState = new Map();
- const getBasicUtils = (context, {
- tagNamePreference,
- mode
- }) => {
-
- const utils = {};
-
- utils.reportSettings = message => {
- context.report({
- loc: {
- end: {
- column: 1,
- line: 1
- },
- start: {
- column: 1,
- line: 1
- }
- },
- message
- });
- };
-
- utils.parseClosureTemplateTag = tag => {
- return _jsdocUtils.default.parseClosureTemplateTag(tag);
- };
- utils.pathDoesNotBeginWith = _jsdocUtils.default.pathDoesNotBeginWith;
-
- utils.getPreferredTagNameObject = ({
- tagName
- }) => {
- const ret = _jsdocUtils.default.getPreferredTagName(context, mode, tagName, tagNamePreference);
- const isObject = ret && typeof ret === 'object';
- if (ret === false || isObject && !ret.replacement) {
- return {
- blocked: true,
- tagName
- };
- }
- return ret;
- };
- return utils;
- };
- const getUtils = (node, jsdoc, jsdocNode, settings, report, context, sc, iteratingAll, ruleConfig, indent) => {
-
- const ancestors = node ? sc.getAncestors ? sc.getAncestors(node) : context.getAncestors() : [];
-
- const {
- sourceCode = context.getSourceCode()
- } = context;
- const utils = getBasicUtils(context, settings);
- const {
- tagNamePreference,
- overrideReplacesDocs,
- ignoreReplacesDocs,
- implementsReplacesDocs,
- augmentsExtendsReplacesDocs,
- maxLines,
- minLines,
- mode
- } = settings;
-
- utils.isIteratingFunction = () => {
- return !iteratingAll || ['MethodDefinition', 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'].includes(String(node && node.type));
- };
-
- utils.isVirtualFunction = () => {
- return Boolean(iteratingAll) && utils.hasATag(['callback', 'function', 'func', 'method']);
- };
-
- utils.stringify = (tagBlock, specRewire) => {
- 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);
- };
-
- utils.getRegexFromString = (str, requiredFlags) => {
- return _jsdocUtils.default.getRegexFromString(str, requiredFlags);
- };
-
- utils.getTagDescription = (tg, returnArray) => {
-
- const descriptions = [];
- tg.source.some(({
- tokens: {
- end,
- lineEnd,
- postDelimiter,
- tag,
- postTag,
- name,
- type,
- description
- }
- }) => {
- const desc = (tag && postTag || !tag && !name && !type && postDelimiter || ''
-
- ).slice(1) + (description || '') + (lineEnd || '');
- if (end) {
- if (desc) {
- descriptions.push(desc);
- }
- return true;
- }
- descriptions.push(desc);
- return false;
- });
- return returnArray ? descriptions : descriptions.join('\n');
- };
-
- utils.setTagDescription = (tg, matcher, setter) => {
- let finalIdx = 0;
- tg.source.some(({
- tokens: {
- description
- }
- }, idx) => {
- if (description && matcher.test(description)) {
- tg.source[idx].tokens.description = setter(description);
- finalIdx = idx;
- return true;
- }
- return false;
- });
- return finalIdx;
- };
-
- utils.getDescription = () => {
-
- const descriptions = [];
- let lastDescriptionLine = 0;
- let tagsBegun = false;
- jsdoc.source.some(({
- tokens: {
- description,
- tag,
- end
- }
- }, idx) => {
- if (tag) {
- tagsBegun = true;
- }
- if (idx && (tag || end)) {
- lastDescriptionLine = idx - 1;
- if (!tagsBegun && description) {
- descriptions.push(description);
- }
- return true;
- }
- if (!tagsBegun && (idx || description)) {
- descriptions.push(description || (descriptions.length ? '' : '\n'));
- }
- return false;
- });
- return {
- description: descriptions.join('\n'),
- descriptions,
- 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;
- });
-
- if (descLines.length) {
- jsdoc.source.splice( startIdx, endIdx - ( startIdx), ...setter(
-
- info, seedTokens, descLines));
- }
- };
-
- utils.setDescriptionLines = (matcher, setter) => {
- let finalIdx = 0;
- jsdoc.source.some(({
- tokens: {
- description,
- tag,
- end
- }
- }, idx) => {
-
- if (idx && (tag || end)) {
- return true;
- }
- if (description && matcher.test(description)) {
- jsdoc.source[idx].tokens.description = setter(description);
- finalIdx = idx;
- return true;
- }
- return false;
- });
- return finalIdx;
- };
-
- utils.changeTag = (tag, ...tokens) => {
- for (const [idx, src] of tag.source.entries()) {
- src.tokens = {
- ...src.tokens,
- ...tokens[idx]
- };
- }
- };
-
- utils.setTag = (tag, tokens) => {
- tag.source = [{
- number: tag.line,
-
- source: '',
- tokens: seedTokens({
- delimiter: '*',
- postDelimiter: ' ',
- start: indent + ' ',
- tag: '@' + tag.tag,
- ...tokens
- })
- }];
- };
-
- utils.removeTag = (tagIndex, {
- removeEmptyBlock = false,
- tagSourceOffset = 0
- } = {}) => {
- const {
- source: tagSource
- } = jsdoc.tags[tagIndex];
-
- let lastIndex;
- const firstNumber = jsdoc.source[0].number;
- tagSource.some(({
- number
- }, tagIdx) => {
- const sourceIndex = jsdoc.source.findIndex(({
- number: srcNumber
- }) => {
- return number === srcNumber;
- });
-
- if (sourceIndex > -1) {
- let spliceCount = 1;
- tagSource.slice(tagIdx + 1).some(({
- tokens: {
- tag,
- end: ending
- }
- }) => {
- if (!tag && !ending) {
- spliceCount++;
- return false;
- }
- return true;
- });
- const spliceIdx = sourceIndex + tagSourceOffset;
- const {
- delimiter,
- end
- } = jsdoc.source[spliceIdx].tokens;
-
- 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;
- }
-
- return false;
- });
- for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
- src.number = firstNumber + ( lastIndex) + idx;
- }
-
-
-
-
- };
-
- utils.addTag = (targetTagName, number = ((_jsdoc$tags => (_jsdoc$tags = jsdoc.tags[jsdoc.tags.length - 1]) === null || _jsdoc$tags === void 0 || (_jsdoc$tags = _jsdoc$tags.source[0]) === null || _jsdoc$tags === void 0 ? void 0 : _jsdoc$tags.number)() ?? jsdoc.source.findIndex(({
- tokens: {
- tag
- }
- }) => {
- return tag;
- }) - 1) + 1, tokens = {}) => {
- jsdoc.source.splice(number, 0, {
- number,
- source: '',
- tokens: seedTokens({
- delimiter: '*',
- postDelimiter: ' ',
- start: indent + ' ',
- tag: `@${targetTagName}`,
- ...tokens
- })
- });
- for (const src of jsdoc.source.slice(number + 1)) {
- src.number++;
- }
- };
-
- utils.getFirstLine = () => {
- let firstLine;
- for (const {
- number,
- tokens: {
- tag
- }
- } of jsdoc.source) {
- if (tag) {
- firstLine = number;
- break;
- }
- }
- return firstLine;
- };
-
- utils.seedTokens = seedTokens;
-
- utils.emptyTokens = tokens => {
- for (const prop of ['start', 'postDelimiter', 'tag', 'type', 'postType', 'postTag', 'name', 'postName', 'description', 'end', 'lineEnd']) {
- tokens[(
-
- prop)] = '';
- }
- };
-
- utils.addLine = (sourceIndex, tokens) => {
- var _jsdoc$source;
- const number = (((_jsdoc$source = jsdoc.source[sourceIndex - 1]) === null || _jsdoc$source === void 0 ? void 0 : _jsdoc$source.number) || 0) + 1;
- jsdoc.source.splice(sourceIndex, 0, {
- number,
- source: '',
- tokens: seedTokens(tokens)
- });
- for (const src of jsdoc.source.slice(number + 1)) {
- src.number++;
- }
-
-
- };
-
- utils.addLines = (tagIndex, tagSourceOffset, numLines) => {
- const {
- source: tagSource
- } = jsdoc.tags[tagIndex];
-
- let lastIndex;
- const firstNumber = jsdoc.source[0].number;
- tagSource.some(({
- number
- }) => {
- const makeLine = () => {
- return {
- number,
- source: '',
- tokens: seedTokens({
- delimiter: '*',
- start: indent + ' '
- })
- };
- };
- const makeLines = () => {
- return Array.from({
- length: numLines
- }, makeLine);
- };
- const sourceIndex = jsdoc.source.findIndex(({
- number: srcNumber,
- tokens: {
- end
- }
- }) => {
- return number === srcNumber && !end;
- });
-
- if (sourceIndex > -1) {
- const lines = makeLines();
- jsdoc.source.splice(sourceIndex + tagSourceOffset, 0, ...lines);
-
- lastIndex = sourceIndex;
- return true;
- }
-
- return false;
- });
- for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
- src.number = firstNumber + ( lastIndex) + idx;
- }
- };
-
- utils.makeMultiline = () => {
- const {
- source: [{
- tokens
- }]
- } = jsdoc;
- const {
- postDelimiter,
- description,
- lineEnd,
- tag,
- name,
- type
- } = tokens;
- let {
- tokens: {
- postName,
- postTag,
- postType
- }
- } = jsdoc.source[0];
-
- if (!description) {
- if (postName) {
- postName = '';
- } else if (postType) {
- postType = '';
- } else if (postTag) {
- postTag = '';
- }
- }
- utils.emptyTokens(tokens);
- utils.addLine(1, {
- delimiter: '*',
-
-
- description: description.trimEnd(),
- name,
- postDelimiter,
- postName,
- postTag,
- postType,
- start: indent + ' ',
- tag,
- type
- });
- utils.addLine(2, {
- end: '*/',
- lineEnd,
- start: indent + ' '
- });
- };
-
- utils.flattenRoots = _jsdocUtils.default.flattenRoots;
-
- utils.getFunctionParameterNames = useDefaultObjectProperties => {
- return _jsdocUtils.default.getFunctionParameterNames(node, useDefaultObjectProperties);
- };
-
- utils.hasParams = () => {
- return _jsdocUtils.default.hasParams( node);
- };
-
- utils.isGenerator = () => {
- return node !== null && Boolean(
-
- node.generator || node.type === 'MethodDefinition' && node.value.generator || ['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type) &&
- (
-
- node.declaration).generator);
- };
-
- utils.isConstructor = () => {
- return _jsdocUtils.default.isConstructor( node);
- };
-
- utils.getJsdocTagsDeep = tagName => {
- const name = utils.getPreferredTagName({
- tagName
- });
- if (!name) {
- return false;
- }
- return _jsdocUtils.default.getJsdocTagsDeep(jsdoc, name);
- };
-
- utils.getPreferredTagName = ({
- tagName,
- skipReportingBlockedTag = false,
- allowObjectReturn = false,
- defaultMessage = `Unexpected tag \`@${tagName}\``
- }) => {
- const ret = _jsdocUtils.default.getPreferredTagName(context, mode, tagName, tagNamePreference);
- const isObject = ret && typeof ret === 'object';
- if (utils.hasTag(tagName) && (ret === false || isObject && !ret.replacement)) {
- if (skipReportingBlockedTag) {
- return {
- blocked: true,
- tagName
- };
- }
- const message = isObject && ret.message || defaultMessage;
- report(message, null, utils.getTags(tagName)[0]);
- return false;
- }
- return isObject && !allowObjectReturn ? ret.replacement : ret;
- };
-
- utils.isValidTag = (name, definedTags) => {
- return _jsdocUtils.default.isValidTag(context, mode, name, definedTags);
- };
-
- utils.hasATag = names => {
- return _jsdocUtils.default.hasATag(jsdoc, names);
- };
-
- utils.hasTag = name => {
- return _jsdocUtils.default.hasTag(jsdoc, name);
- };
-
- utils.comparePaths = name => {
- return _jsdocUtils.default.comparePaths(name);
- };
-
- utils.dropPathSegmentQuotes = name => {
- return _jsdocUtils.default.dropPathSegmentQuotes(name);
- };
-
- utils.avoidDocs = () => {
- var _context$options$;
- if (ignoreReplacesDocs !== false && (utils.hasTag('ignore') || utils.classHasTag('ignore')) || overrideReplacesDocs !== false && (utils.hasTag('override') || utils.classHasTag('override')) || implementsReplacesDocs !== false && (utils.hasTag('implements') || utils.classHasTag('implements')) || augmentsExtendsReplacesDocs && (utils.hasATag(['augments', 'extends']) || utils.classHasTag('augments') || utils.classHasTag('extends'))) {
- return true;
- }
- if (_jsdocUtils.default.exemptSpeciaMethods(jsdoc, node, context,
- ruleConfig.meta.schema)) {
- return true;
- }
- const exemptedBy = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.exemptedBy) ?? ['inheritDoc', ...(mode === 'closure' ? [] : ['inheritdoc'])];
- if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
- return true;
- }
- return false;
- };
- for (const method of ['tagMightHaveNamePosition', 'tagMightHaveTypePosition']) {
-
- utils[(
- method)] = (tagName, otherModeMaps) => {
- const result = _jsdocUtils.default[(
- method)](tagName);
- if (result) {
- return true;
- }
- if (!otherModeMaps) {
- return false;
- }
- const otherResult = otherModeMaps.some(otherModeMap => {
- return _jsdocUtils.default[(
- method)](tagName, otherModeMap);
- });
- return otherResult ? {
- otherMode: true
- } : false;
- };
- }
-
- utils.tagMissingRequiredTypeOrNamepath = (tagName, otherModeMaps) => {
- const result = _jsdocUtils.default.tagMissingRequiredTypeOrNamepath(tagName);
- if (!result) {
- return false;
- }
- const otherResult = otherModeMaps.every(otherModeMap => {
- return _jsdocUtils.default.tagMissingRequiredTypeOrNamepath(tagName, otherModeMap);
- });
- return otherResult ? true : {
- otherMode: false
- };
- };
- for (const method of ['tagMustHaveNamePosition', 'tagMustHaveTypePosition']) {
-
- utils[(
- method)] = (tagName, otherModeMaps) => {
- const result = _jsdocUtils.default[(
- method)](tagName);
- if (!result) {
- return false;
- }
-
- const otherResult = otherModeMaps.every(otherModeMap => {
- return _jsdocUtils.default[(
- method)](tagName, otherModeMap);
- });
- return otherResult ? true : {
- otherMode: false
- };
- };
- }
- for (const method of ['isNamepathDefiningTag', 'isNamepathReferencingTag', 'isNamepathOrUrlReferencingTag', 'tagMightHaveNamepath']) {
-
- utils[(
- method)] = tagName => {
- return _jsdocUtils.default[(
- method)](tagName);
- };
- }
-
- utils.getTagStructureForMode = mde => {
- return _jsdocUtils.default.getTagStructureForMode(mde, settings.structuredTags);
- };
-
- utils.mayBeUndefinedTypeTag = tag => {
- return _jsdocUtils.default.mayBeUndefinedTypeTag(tag, settings.mode);
- };
-
- utils.hasValueOrExecutorHasNonEmptyResolveValue = (anyPromiseAsReturn, allBranches) => {
- return _jsdocUtils.default.hasValueOrExecutorHasNonEmptyResolveValue( node, anyPromiseAsReturn, allBranches);
- };
-
- utils.hasYieldValue = () => {
- if (['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes( node.type)) {
- return _jsdocUtils.default.hasYieldValue(
-
- node.declaration);
- }
- return _jsdocUtils.default.hasYieldValue( node);
- };
-
- utils.hasYieldReturnValue = () => {
- return _jsdocUtils.default.hasYieldValue( node, true);
- };
-
- utils.hasThrowValue = () => {
- return _jsdocUtils.default.hasThrowValue(node);
- };
-
- utils.isAsync = () => {
- return 'async' in ( node) && node.async;
- };
-
- utils.getTags = tagName => {
- return utils.filterTags(item => {
- return item.tag === tagName;
- });
- };
-
- utils.getPresentTags = tagList => {
- return utils.filterTags(tag => {
- return tagList.includes(tag.tag);
- });
- };
-
- utils.filterTags = filter => {
- return jsdoc.tags.filter(tag => {
- return filter(tag);
- });
- };
-
- utils.filterAllTags = filter => {
- const tags = _jsdocUtils.default.getAllTags(jsdoc);
- return tags.filter(tag => {
- return filter(tag);
- });
- };
-
- utils.getTagsByType = tags => {
- return _jsdocUtils.default.getTagsByType(context, mode, tags);
- };
-
- utils.hasOptionTag = tagName => {
- const {
- tags
- } = context.options[0] ?? {};
- return Boolean(tags && tags.includes(tagName));
- };
-
- utils.getClassNode = () => {
- return [...ancestors, node].reverse().find(parent => {
- return parent && ['ClassDeclaration', 'ClassExpression'].includes(parent.type);
- }) ?? null;
- };
-
- utils.getClassJsdoc = () => {
- const classNode = utils.getClassNode();
- if (!classNode) {
- return null;
- }
- const classJsdocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, classNode, {
- maxLines,
- minLines
- });
- if (classJsdocNode) {
- return (0, _jsdoccomment.parseComment)(classJsdocNode, '');
- }
- return null;
- };
-
- utils.classHasTag = tagName => {
- const classJsdoc = utils.getClassJsdoc();
- return classJsdoc !== null && _jsdocUtils.default.hasTag(classJsdoc, tagName);
- };
-
- utils.forEachPreferredTag = (tagName, arrayHandler, skipReportingBlockedTag = false) => {
- const targetTagName =
- utils.getPreferredTagName({
- skipReportingBlockedTag,
- tagName
- });
- if (!targetTagName || skipReportingBlockedTag && targetTagName && typeof targetTagName === 'object') {
- return;
- }
- const matchingJsdocTags = jsdoc.tags.filter(({
- tag
- }) => {
- return tag === targetTagName;
- });
- for (const matchingJsdocTag of matchingJsdocTags) {
- arrayHandler(
-
- matchingJsdocTag, targetTagName);
- }
- };
-
- utils.findContext = (contexts, comment) => {
- const foundContext = contexts.find(cntxt => {
- return typeof cntxt === 'string' ? _esquery.default.matches( node, _esquery.default.parse(cntxt), undefined, {
- visitorKeys: sourceCode.visitorKeys
- }) : (!cntxt.context || cntxt.context === 'any' || _esquery.default.matches( node, _esquery.default.parse(cntxt.context), undefined, {
- visitorKeys: sourceCode.visitorKeys
- })) && comment === cntxt.comment;
- });
- const contextStr = typeof foundContext === 'object' ? foundContext.context ?? 'any' : String(foundContext);
- return {
- contextStr,
- foundContext
- };
- };
- return utils;
- };
- const getSettings = context => {
- var _context$settings$jsd, _context$settings$jsd2, _context$settings$jsd3, _context$settings$jsd4, _context$settings$jsd5, _context$settings$jsd6, _context$settings$jsd7, _context$settings$jsd8, _context$settings$jsd9, _context$settings$jsd10, _context$settings$jsd11, _context$settings$jsd12, _context$settings$jsd13, _context$settings$jsd14;
-
- const settings = {
-
- ignorePrivate: Boolean((_context$settings$jsd = context.settings.jsdoc) === null || _context$settings$jsd === void 0 ? void 0 : _context$settings$jsd.ignorePrivate),
- ignoreInternal: Boolean((_context$settings$jsd2 = context.settings.jsdoc) === null || _context$settings$jsd2 === void 0 ? void 0 : _context$settings$jsd2.ignoreInternal),
- maxLines: Number(((_context$settings$jsd3 = context.settings.jsdoc) === null || _context$settings$jsd3 === void 0 ? void 0 : _context$settings$jsd3.maxLines) ?? 1),
- minLines: Number(((_context$settings$jsd4 = context.settings.jsdoc) === null || _context$settings$jsd4 === void 0 ? void 0 : _context$settings$jsd4.minLines) ?? 0),
-
- tagNamePreference: ((_context$settings$jsd5 = context.settings.jsdoc) === null || _context$settings$jsd5 === void 0 ? void 0 : _context$settings$jsd5.tagNamePreference) ?? {},
-
- preferredTypes: ((_context$settings$jsd6 = context.settings.jsdoc) === null || _context$settings$jsd6 === void 0 ? void 0 : _context$settings$jsd6.preferredTypes) ?? {},
-
- structuredTags: ((_context$settings$jsd7 = context.settings.jsdoc) === null || _context$settings$jsd7 === void 0 ? void 0 : _context$settings$jsd7.structuredTags) ?? {},
-
-
- overrideReplacesDocs: (_context$settings$jsd8 = context.settings.jsdoc) === null || _context$settings$jsd8 === void 0 ? void 0 : _context$settings$jsd8.overrideReplacesDocs,
- ignoreReplacesDocs: (_context$settings$jsd9 = context.settings.jsdoc) === null || _context$settings$jsd9 === void 0 ? void 0 : _context$settings$jsd9.ignoreReplacesDocs,
- implementsReplacesDocs: (_context$settings$jsd10 = context.settings.jsdoc) === null || _context$settings$jsd10 === void 0 ? void 0 : _context$settings$jsd10.implementsReplacesDocs,
- augmentsExtendsReplacesDocs: (_context$settings$jsd11 = context.settings.jsdoc) === null || _context$settings$jsd11 === void 0 ? void 0 : _context$settings$jsd11.augmentsExtendsReplacesDocs,
-
- exemptDestructuredRootsFromChecks: (_context$settings$jsd12 = context.settings.jsdoc) === null || _context$settings$jsd12 === void 0 ? void 0 : _context$settings$jsd12.exemptDestructuredRootsFromChecks,
-
- mode: ((_context$settings$jsd13 = context.settings.jsdoc) === null || _context$settings$jsd13 === void 0 ? void 0 : _context$settings$jsd13.mode) ?? 'typescript',
-
- contexts: (_context$settings$jsd14 = context.settings.jsdoc) === null || _context$settings$jsd14 === void 0 ? void 0 : _context$settings$jsd14.contexts
- };
-
- _jsdocUtils.default.setTagStructure(settings.mode);
- try {
- _jsdocUtils.default.overrideTagStructure(settings.structuredTags);
- } catch (error) {
- context.report({
- loc: {
- end: {
- column: 1,
- line: 1
- },
- start: {
- column: 1,
- line: 1
- }
- },
- message: error.message
- });
- return false;
- }
- return settings;
- };
- exports.getSettings = getSettings;
- const makeReport = (context, commentNode) => {
-
- const report = (message, fix = null, jsdocLoc = null, data = undefined) => {
- let loc;
- if (jsdocLoc) {
- if (!('line' in jsdocLoc)) {
- jsdocLoc.line = jsdocLoc.source[0].number;
- }
- const lineNumber = commentNode.loc.start.line + ( jsdocLoc.line);
- loc = {
- end: {
- column: 0,
- line: lineNumber
- },
- start: {
- column: 0,
- line: lineNumber
- }
- };
-
-
- if ('column' in jsdocLoc && typeof jsdocLoc.column === 'number') {
- const colNumber = commentNode.loc.start.column + jsdocLoc.column;
- loc.end.column = colNumber;
- loc.start.column = colNumber;
- }
- }
- context.report({
- data,
- fix,
- loc,
- message,
- node: commentNode
- });
- };
- return report;
- };
- const iterate = (info, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator, state, iteratingAll) => {
- const jsdocNde = jsdocNode;
- const report = makeReport(context,
- jsdocNde);
- const utils = getUtils(node, jsdoc,
- jsdocNode, settings, report, context, sourceCode, iteratingAll, ruleConfig, indent);
- if (!ruleConfig.checkInternal && settings.ignoreInternal && utils.hasTag('internal')) {
- return;
- }
- if (!ruleConfig.checkPrivate && settings.ignorePrivate && (utils.hasTag('private') || jsdoc.tags.filter(({
- tag
- }) => {
- return tag === 'access';
- }).some(({
- description
- }) => {
- return description === 'private';
- }))) {
- return;
- }
- iterator({
- context,
- globalState,
- indent,
- info,
- jsdoc,
- jsdocNode: (
-
- jsdocNde),
- node,
- report,
- settings,
- sourceCode,
- state,
- utils
- });
- };
- const getIndentAndJSDoc = function (lines, jsdocNode) {
- const sourceLine = lines[
- jsdocNode.loc.start.line - 1];
- const indnt = sourceLine.charAt(0).repeat(
- jsdocNode.loc.start.column);
- const jsdc = (0, _jsdoccomment.parseComment)(jsdocNode, '');
- return [indnt, jsdc];
- };
- const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContexts) => {
- const trackedJsdocs = new Set();
-
- let handler;
-
- let settings;
-
- const callIterator = (context, node, jsdocNodes, state, lastCall) => {
-
- const {
- sourceCode = context.getSourceCode()
- } = context;
- const {
- lines
- } = sourceCode;
- const utils = getBasicUtils(context, settings);
- for (const jsdocNode of jsdocNodes) {
- const jsdocNde = jsdocNode;
- if (!/^\/\*\*\s/u.test(sourceCode.getText(
- jsdocNde))) {
- continue;
- }
- const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
- if (additiveCommentContexts) {
- for (const [idx, {
- comment
- }] of contexts.entries()) {
- if (comment && handler(comment, jsdoc) === false) {
- continue;
- }
- iterate({
- comment,
- lastIndex: idx,
- selector: node === null || node === void 0 ? void 0 : node.type
- }, indent, jsdoc, ruleConfig, context, jsdocNode,
- node,
- settings, sourceCode, iterator, state, true);
- }
- continue;
- }
- let lastComment;
- let lastIndex;
-
- if (contexts && contexts.every(({
- comment
- }, idx) => {
- lastComment = comment;
- lastIndex = idx;
- return comment && handler(comment, jsdoc) === false;
- })) {
- continue;
- }
- iterate(lastComment ? {
- comment: lastComment,
- lastIndex,
- selector: node === null || node === void 0 ? void 0 : node.type
- } : {
- lastIndex,
- selector: node === null || node === void 0 ? void 0 : node.type
- }, indent, jsdoc, ruleConfig, context, jsdocNode, node,
- settings, sourceCode, iterator, state, true);
- }
- const settngs = settings;
- if (lastCall && ruleConfig.exit) {
- ruleConfig.exit({
- context,
- settings: settngs,
- state,
- utils
- });
- }
- };
- return {
-
- create(context) {
-
- const {
- sourceCode = context.getSourceCode()
- } = context;
- settings = getSettings(context);
- if (!settings) {
- return {};
- }
- if (contexts) {
- handler = (0, _jsdoccomment.commentHandler)(settings);
- }
- const state = {};
- return {
-
- '*:not(Program)'(node) {
- const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
- if (!ruleConfig.noTracking && trackedJsdocs.has(commentNode)) {
- return;
- }
- if (!commentNode) {
- if (ruleConfig.nonComment) {
- const ste = state;
- ruleConfig.nonComment({
- node,
- state: ste
- });
- }
- return;
- }
- trackedJsdocs.add(commentNode);
- callIterator(context, node, [(
- commentNode)], state);
- },
- 'Program:exit'() {
- const allComments = sourceCode.getAllComments();
- const untrackedJSdoc = allComments.filter(node => {
- return !trackedJsdocs.has(node);
- });
- callIterator(context, null, untrackedJSdoc,
- state, true);
- }
- };
- },
- meta: ruleConfig.meta
- };
- };
- const checkFile = (iterator, ruleConfig) => {
- return {
- create(context) {
-
- const {
- sourceCode = context.getSourceCode()
- } = context;
- const settings = getSettings(context);
- if (!settings) {
- return {};
- }
- return {
- 'Program:exit'() {
- const allComms = sourceCode.getAllComments();
- const utils = getBasicUtils(context, settings);
- iterator({
- allComments: ( allComms),
- context,
- makeReport,
- settings,
- sourceCode,
- utils
- });
- }
- };
- },
- meta: ruleConfig.meta
- };
- };
- function iterateJsdoc(iterator, ruleConfig) {
- var _ruleConfig$meta;
- const metaType = ruleConfig === null || ruleConfig === void 0 || (_ruleConfig$meta = ruleConfig.meta) === null || _ruleConfig$meta === void 0 ? void 0 : _ruleConfig$meta.type;
- if (!metaType || !['problem', 'suggestion', 'layout'].includes(metaType)) {
- throw new TypeError('Rule must include `meta.type` option (with value "problem", "suggestion", or "layout")');
- }
- if (typeof iterator !== 'function') {
- throw new TypeError('The iterator argument must be a function.');
- }
- if (ruleConfig.checkFile) {
- return checkFile( iterator, ruleConfig);
- }
- if (ruleConfig.iterateAllJsdocs) {
- return iterateAllJsdocs(iterator, ruleConfig);
- }
-
- return {
-
- create(context) {
- const settings = getSettings(context);
- if (!settings) {
- return {};
- }
-
- let contexts;
- if (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext) {
- var _context$options$2, _contexts, _contexts2;
- contexts = ruleConfig.matchContext && (_context$options$2 = context.options[0]) !== null && _context$options$2 !== void 0 && _context$options$2.match ? context.options[0].match : _jsdocUtils.default.enforcedContexts(context, ruleConfig.contextDefaults, ruleConfig.nonGlobalSettings ? {} : settings);
- if (contexts) {
- contexts = contexts.map(obj => {
- if (typeof obj === 'object' && !obj.context) {
- return {
- ...obj,
- context: 'any'
- };
- }
- return obj;
- });
- }
- const hasPlainAny = (_contexts = contexts) === null || _contexts === void 0 ? void 0 : _contexts.includes('any');
- const hasObjectAny = !hasPlainAny && ((_contexts2 = contexts) === null || _contexts2 === void 0 ? void 0 : _contexts2.find(ctxt => {
- if (typeof ctxt === 'string') {
- return false;
- }
- return (ctxt === null || ctxt === void 0 ? void 0 : ctxt.context) === 'any';
- }));
- if (hasPlainAny || hasObjectAny) {
- return iterateAllJsdocs(iterator, ruleConfig, hasObjectAny ? ( contexts) : null, ruleConfig.matchContext).create(context);
- }
- }
-
- const {
- sourceCode = context.getSourceCode()
- } = context;
- const {
- lines
- } = sourceCode;
-
- const state = {};
-
- const checkJsdoc = (info, handler, node) => {
- const jsdocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
- if (!jsdocNode) {
- return;
- }
- const [indent, jsdoc] = getIndentAndJSDoc(lines,
- jsdocNode);
- if (
-
-
-
- handler && handler(jsdoc) === false) {
- return;
- }
- iterate(info, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator,
- state);
- };
-
- let contextObject = {};
- if (contexts && (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext)) {
- contextObject = _jsdocUtils.default.getContextObject(contexts, checkJsdoc, (0, _jsdoccomment.commentHandler)(settings));
- } else {
- for (const prop of ['ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression', 'TSDeclareFunction']) {
- contextObject[prop] = checkJsdoc.bind(null, {
- selector: prop
- }, null);
- }
- }
- if (typeof ruleConfig.exit === 'function') {
- contextObject['Program:exit'] = () => {
- const ste = state;
-
-
- ruleConfig.exit({
- context,
- settings,
- state: ste
- });
- };
- }
- return contextObject;
- },
- meta: ruleConfig.meta
- };
- }
|