eslint-plugin-jsdoc 39.3.1 → 39.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/dist/alignTransform.js +14 -4
- package/dist/alignTransform.js.map +1 -1
- package/dist/jsdocUtils.js +12 -356
- package/dist/jsdocUtils.js.map +1 -1
- package/dist/utils/hasReturnValue.js +364 -0
- package/dist/utils/hasReturnValue.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2682,6 +2682,22 @@ const fn = ({ids}) => {}
|
|
|
2682
2682
|
*/
|
|
2683
2683
|
const fn = ( lorem, sit ) => {}
|
|
2684
2684
|
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Function description.
|
|
2688
|
+
*
|
|
2689
|
+
* @param lorem Description.
|
|
2690
|
+
* @param sit Description multi words.
|
|
2691
|
+
*/
|
|
2692
|
+
const fn = ( lorem, sit ) => {};
|
|
2693
|
+
|
|
2694
|
+
/**
|
|
2695
|
+
* Function description.
|
|
2696
|
+
*
|
|
2697
|
+
* @return Return description.
|
|
2698
|
+
*/
|
|
2699
|
+
const fn2 = () => {}
|
|
2700
|
+
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
|
|
2685
2701
|
````
|
|
2686
2702
|
|
|
2687
2703
|
|
|
@@ -6743,7 +6759,7 @@ You may provide a custom default message by using the following format:
|
|
|
6743
6759
|
```js
|
|
6744
6760
|
{
|
|
6745
6761
|
'jsdoc/match-description': ['error', {
|
|
6746
|
-
message: 'The default
|
|
6762
|
+
message: 'The default description should begin with a capital letter.'
|
|
6747
6763
|
}]
|
|
6748
6764
|
}
|
|
6749
6765
|
```
|
|
@@ -10367,6 +10383,19 @@ const a = 'string';
|
|
|
10367
10383
|
*/
|
|
10368
10384
|
const a = new Todo();
|
|
10369
10385
|
// Settings: {"jsdoc":{"mode":"typescript"}}
|
|
10386
|
+
|
|
10387
|
+
/**
|
|
10388
|
+
* @template A, [B=SomeDefault]
|
|
10389
|
+
*/
|
|
10390
|
+
class Foo {
|
|
10391
|
+
/**
|
|
10392
|
+
* @param {A} baz
|
|
10393
|
+
* @return {B}
|
|
10394
|
+
*/
|
|
10395
|
+
bar (baz) {
|
|
10396
|
+
}
|
|
10397
|
+
}
|
|
10398
|
+
// Settings: {"jsdoc":{"mode":"typescript"}}
|
|
10370
10399
|
````
|
|
10371
10400
|
|
|
10372
10401
|
|
package/dist/alignTransform.js
CHANGED
|
@@ -79,7 +79,7 @@ const alignTransform = ({
|
|
|
79
79
|
let intoTags = false;
|
|
80
80
|
let width;
|
|
81
81
|
|
|
82
|
-
const alignTokens = tokens => {
|
|
82
|
+
const alignTokens = (tokens, hasNoTypes) => {
|
|
83
83
|
const nothingAfter = {
|
|
84
84
|
delim: false,
|
|
85
85
|
name: false,
|
|
@@ -105,6 +105,11 @@ const alignTransform = ({
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (hasNoTypes) {
|
|
111
|
+
nothingAfter.tag = true;
|
|
112
|
+
tokens.postTag = '';
|
|
108
113
|
} // Todo: Avoid fixing alignment of blocks with multiline wrapping of type
|
|
109
114
|
|
|
110
115
|
|
|
@@ -136,7 +141,7 @@ const alignTransform = ({
|
|
|
136
141
|
return tokens;
|
|
137
142
|
};
|
|
138
143
|
|
|
139
|
-
const update = (line, index, source) => {
|
|
144
|
+
const update = (line, index, source, hasNoTypes) => {
|
|
140
145
|
const tokens = { ...line.tokens
|
|
141
146
|
};
|
|
142
147
|
|
|
@@ -192,7 +197,7 @@ const alignTransform = ({
|
|
|
192
197
|
}
|
|
193
198
|
|
|
194
199
|
return { ...line,
|
|
195
|
-
tokens: alignTokens(tokens)
|
|
200
|
+
tokens: alignTokens(tokens, hasNoTypes)
|
|
196
201
|
};
|
|
197
202
|
};
|
|
198
203
|
|
|
@@ -202,9 +207,14 @@ const alignTransform = ({
|
|
|
202
207
|
}) => {
|
|
203
208
|
width = source.reduce(getWidth(tags), { ...zeroWidth
|
|
204
209
|
});
|
|
210
|
+
const hasNoTypes = fields.tags.every(({
|
|
211
|
+
type
|
|
212
|
+
}) => {
|
|
213
|
+
return !type;
|
|
214
|
+
});
|
|
205
215
|
return rewireSource({ ...fields,
|
|
206
216
|
source: source.map((line, index) => {
|
|
207
|
-
return update(line, index, source);
|
|
217
|
+
return update(line, index, source, hasNoTypes);
|
|
208
218
|
})
|
|
209
219
|
});
|
|
210
220
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alignTransform.js","names":["rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","Markers","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","intoTags","alignTokens","nothingAfter","delim","description","postName","postType","postTag","spacings","postDelimiter","update","line","isEmpty","end","fields","reduce","map"],"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\n // `comment-parser/primitives` export\n Markers,\n util,\n} from 'comment-parser';\n\nconst {\n rewireSource,\n} = util;\n\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\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\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 === Markers.start ? 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\nconst space = (len) => {\n return ''.padStart(len, ' ');\n};\n\nconst alignTransform = ({\n customSpacings,\n tags,\n indent,\n preserveMainDescriptionPostDelimiter,\n}) => {\n let intoTags = false;\n let width;\n\n const alignTokens = (tokens) => {\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 /* istanbul 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 // 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);\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);\n }\n\n return tokens;\n };\n\n const update = (line, index, source) => {\n const tokens = {\n ...line.tokens,\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 === Markers.end && isEmpty) {\n tokens.start = indent + ' ';\n\n return {\n ...line,\n tokens,\n };\n }\n\n /* eslint-disable indent */\n switch (tokens.delimiter) {\n case Markers.start:\n tokens.start = indent;\n break;\n case Markers.delim:\n tokens.start = indent + ' ';\n break;\n default:\n tokens.delimiter = '';\n\n // compensate delimiter\n tokens.start = indent + ' ';\n }\n /* eslint-enable */\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 // Not align.\n if (!shouldAlign(tags, index, source)) {\n return {\n ...line,\n tokens,\n };\n }\n\n return {\n ...line,\n tokens: alignTokens(tokens),\n };\n };\n\n return ({\n source,\n ...fields\n }) => {\n width = source.reduce(getWidth(tags), {\n ...zeroWidth,\n });\n\n return rewireSource({\n ...fields,\n source: source.map((line, index) => {\n return update(line, index, source);\n }),\n });\n };\n};\n\nexport default alignTransform;\n"],"mappings":";;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AASA,MAAM;EACJA;AADI,IAEFC,mBAFJ;AAIA,MAAMC,SAAS,GAAG;EAChBC,IAAI,EAAE,CADU;EAEhBC,KAAK,EAAE,CAFS;EAGhBC,GAAG,EAAE,CAHW;EAIhBC,IAAI,EAAE;AAJU,CAAlB;;AAOA,MAAMC,WAAW,GAAG,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAd,KAAyB;EAC3C,MAAML,GAAG,GAAGK,MAAM,CAACD,KAAD,CAAN,CAAcE,MAAd,CAAqBN,GAArB,CAAyBO,OAAzB,CAAiC,GAAjC,EAAsC,EAAtC,CAAZ;EACA,MAAMC,WAAW,GAAGL,IAAI,CAACM,QAAL,CAAcT,GAAd,CAApB;;EAEA,IAAIQ,WAAJ,EAAiB;IACf,OAAO,IAAP;EACD;;EAED,IAAIR,GAAG,KAAK,EAAZ,EAAgB;IACd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B,MAAD;IAFd,CAAP;EAID,CAjED;;EAmEA,OAAO,CAAC;IACND,MADM;IAEN,GAAGmC;EAFG,CAAD,KAGD;IACJ3B,KAAK,GAAGR,MAAM,CAACoC,MAAP,CAAc7B,QAAQ,CAACT,IAAD,CAAtB,EAA8B,EACpC,GAAGN;IADiC,CAA9B,CAAR;IAIA,OAAOF,YAAY,CAAC,EAClB,GAAG6C,MADe;MAElBnC,MAAM,EAAEA,MAAM,CAACqC,GAAP,CAAW,CAACL,IAAD,EAAOjC,KAAP,KAAiB;QAClC,OAAOgC,MAAM,CAACC,IAAD,EAAOjC,KAAP,EAAcC,MAAd,CAAb;MACD,CAFO;IAFU,CAAD,CAAnB;EAMD,CAdD;AAeD,CArJD;;eAuJeiB,c"}
|
|
1
|
+
{"version":3,"file":"alignTransform.js","names":["rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","Markers","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","intoTags","alignTokens","hasNoTypes","nothingAfter","delim","description","postName","postType","postTag","spacings","postDelimiter","update","line","isEmpty","end","fields","reduce","every","map"],"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\n // `comment-parser/primitives` export\n Markers,\n util,\n} from 'comment-parser';\n\nconst {\n rewireSource,\n} = util;\n\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\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\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 === Markers.start ? 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\nconst space = (len) => {\n return ''.padStart(len, ' ');\n};\n\nconst alignTransform = ({\n customSpacings,\n tags,\n indent,\n preserveMainDescriptionPostDelimiter,\n}) => {\n let intoTags = false;\n let width;\n\n const alignTokens = (tokens, hasNoTypes) => {\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 /* istanbul 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 if (hasNoTypes) {\n nothingAfter.tag = true;\n tokens.postTag = '';\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);\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);\n }\n\n return tokens;\n };\n\n const update = (line, index, source, hasNoTypes) => {\n const tokens = {\n ...line.tokens,\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 === Markers.end && isEmpty) {\n tokens.start = indent + ' ';\n\n return {\n ...line,\n tokens,\n };\n }\n\n /* eslint-disable indent */\n switch (tokens.delimiter) {\n case Markers.start:\n tokens.start = indent;\n break;\n case Markers.delim:\n tokens.start = indent + ' ';\n break;\n default:\n tokens.delimiter = '';\n\n // compensate delimiter\n tokens.start = indent + ' ';\n }\n /* eslint-enable */\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 // Not align.\n if (!shouldAlign(tags, index, source)) {\n return {\n ...line,\n tokens,\n };\n }\n\n return {\n ...line,\n tokens: alignTokens(tokens, hasNoTypes),\n };\n };\n\n return ({\n source,\n ...fields\n }) => {\n width = source.reduce(getWidth(tags), {\n ...zeroWidth,\n });\n const hasNoTypes = fields.tags.every(({\n type,\n }) => {\n return !type;\n });\n\n return rewireSource({\n ...fields,\n source: source.map((line, index) => {\n return update(line, index, source, hasNoTypes);\n }),\n });\n };\n};\n\nexport default alignTransform;\n"],"mappings":";;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AASA,MAAM;EACJA;AADI,IAEFC,mBAFJ;AAIA,MAAMC,SAAS,GAAG;EAChBC,IAAI,EAAE,CADU;EAEhBC,KAAK,EAAE,CAFS;EAGhBC,GAAG,EAAE,CAHW;EAIhBC,IAAI,EAAE;AAJU,CAAlB;;AAOA,MAAMC,WAAW,GAAG,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAd,KAAyB;EAC3C,MAAML,GAAG,GAAGK,MAAM,CAACD,KAAD,C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M,CAAC8B,aAAP,GAAuB,EAAvB;MACD,CAFD,MAEO,IAAI,CAACX,oCAAL,EAA2C;QAChDnB,MAAM,CAAC8B,aAAP,GAAuB,GAAvB;MACD;;MAED,OAAO,EACL,GAAGE,IADE;QAELhC;MAFK,CAAP;IAID,CAnDiD,CAqDlD;;;IACA,IAAI,CAACJ,WAAW,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAd,CAAhB,EAAuC;MACrC,OAAO,EACL,GAAGiC,IADE;QAELhC;MAFK,CAAP;IAID;;IAED,OAAO,EACL,GAAGgC,IADE;MAELhC,MAAM,EAAEqB,WAAW,CAACrB,MAAD,EAASsB,UAAT;IAFd,CAAP;EAID,CAjED;;EAmEA,OAAO,CAAC;IACNvB,MADM;IAEN,GAAGoC;EAFG,CAAD,KAGD;IACJ5B,KAAK,GAAGR,MAAM,CAACqC,MAAP,CAAc9B,QAAQ,CAACT,IAAD,CAAtB,EAA8B,EACpC,GAAGN;IADiC,CAA9B,CAAR;IAGA,MAAM+B,UAAU,GAAGa,MAAM,CAACtC,IAAP,CAAYwC,KAAZ,CAAkB,CAAC;MACpC1C;IADoC,CAAD,KAE/B;MACJ,OAAO,CAACA,IAAR;IACD,CAJkB,CAAnB;IAMA,OAAON,YAAY,CAAC,EAClB,GAAG8C,MADe;MAElBpC,MAAM,EAAEA,MAAM,CAACuC,GAAP,CAAW,CAACN,IAAD,EAAOlC,KAAP,KAAiB;QAClC,OAAOiC,MAAM,CAACC,IAAD,EAAOlC,KAAP,EAAcC,MAAd,EAAsBuB,UAAtB,CAAb;MACD,CAFO;IAFU,CAAD,CAAnB;EAMD,CAnBD;AAoBD,CA/JD;;eAiKeN,c"}
|
package/dist/jsdocUtils.js
CHANGED
|
@@ -11,6 +11,8 @@ var _getDefaultTagStructureForMode = _interopRequireDefault(require("./getDefaul
|
|
|
11
11
|
|
|
12
12
|
var _tagNames = require("./tagNames");
|
|
13
13
|
|
|
14
|
+
var _hasReturnValue = require("./utils/hasReturnValue");
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
@@ -117,6 +119,8 @@ const getPropertiesFromPropertySignature = propSignature => {
|
|
|
117
119
|
|
|
118
120
|
|
|
119
121
|
const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
122
|
+
var _functionNode$value;
|
|
123
|
+
|
|
120
124
|
// eslint-disable-next-line complexity
|
|
121
125
|
const getParamName = (param, isProperty) => {
|
|
122
126
|
var _param$left, _param$left3;
|
|
@@ -254,7 +258,11 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
254
258
|
throw new Error(`Unsupported function signature format: \`${param.type}\`.`);
|
|
255
259
|
};
|
|
256
260
|
|
|
257
|
-
|
|
261
|
+
if (!functionNode) {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (functionNode.params || ((_functionNode$value = functionNode.value) === null || _functionNode$value === void 0 ? void 0 : _functionNode$value.params) || []).map(param => {
|
|
258
266
|
return getParamName(param);
|
|
259
267
|
});
|
|
260
268
|
};
|
|
@@ -629,358 +637,6 @@ const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
|
|
|
629
637
|
const mustHaveEither = tagMustHaveEitherTypeOrNamePosition(tag.tag, tagMap);
|
|
630
638
|
const hasEither = tagMightHaveEitherTypeOrNamePosition(tag.tag, tagMap) && (hasTypePosition || hasNameOrNamepathPosition);
|
|
631
639
|
return mustHaveEither && !hasEither && !mustHaveTypePosition;
|
|
632
|
-
};
|
|
633
|
-
/**
|
|
634
|
-
* Checks if a node is a promise but has no resolve value or an empty value.
|
|
635
|
-
* An `undefined` resolve does not count.
|
|
636
|
-
*
|
|
637
|
-
* @param {object} node
|
|
638
|
-
* @returns {boolean}
|
|
639
|
-
*/
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const isNewPromiseExpression = node => {
|
|
643
|
-
return node && node.type === 'NewExpression' && node.callee.type === 'Identifier' && node.callee.name === 'Promise';
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
const isVoidPromise = node => {
|
|
647
|
-
var _node$typeParameters, _node$typeParameters$, _node$typeParameters$2;
|
|
648
|
-
|
|
649
|
-
return (node === null || node === void 0 ? void 0 : (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : (_node$typeParameters$ = _node$typeParameters.params) === null || _node$typeParameters$ === void 0 ? void 0 : (_node$typeParameters$2 = _node$typeParameters$[0]) === null || _node$typeParameters$2 === void 0 ? void 0 : _node$typeParameters$2.type) === 'TSVoidKeyword';
|
|
650
|
-
};
|
|
651
|
-
/**
|
|
652
|
-
* @callback PromiseFilter
|
|
653
|
-
* @param {object} node
|
|
654
|
-
* @returns {boolean}
|
|
655
|
-
*/
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Checks if a node has a return statement. Void return does not count.
|
|
659
|
-
*
|
|
660
|
-
* @param {object} node
|
|
661
|
-
* @param {PromiseFilter} promFilter
|
|
662
|
-
* @returns {boolean|Node}
|
|
663
|
-
*/
|
|
664
|
-
// eslint-disable-next-line complexity
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const hasReturnValue = (node, promFilter) => {
|
|
668
|
-
var _node$returnType, _node$returnType$type;
|
|
669
|
-
|
|
670
|
-
if (!node) {
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
switch (node.type) {
|
|
675
|
-
case 'TSFunctionType':
|
|
676
|
-
case 'TSMethodSignature':
|
|
677
|
-
return !['TSVoidKeyword', 'TSUndefinedKeyword'].includes(node === null || node === void 0 ? void 0 : (_node$returnType = node.returnType) === null || _node$returnType === void 0 ? void 0 : (_node$returnType$type = _node$returnType.typeAnnotation) === null || _node$returnType$type === void 0 ? void 0 : _node$returnType$type.type);
|
|
678
|
-
|
|
679
|
-
case 'MethodDefinition':
|
|
680
|
-
return hasReturnValue(node.value, promFilter);
|
|
681
|
-
|
|
682
|
-
case 'FunctionExpression':
|
|
683
|
-
case 'FunctionDeclaration':
|
|
684
|
-
case 'ArrowFunctionExpression':
|
|
685
|
-
{
|
|
686
|
-
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node.body)) || hasReturnValue(node.body, promFilter);
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
case 'BlockStatement':
|
|
690
|
-
{
|
|
691
|
-
return node.body.some(bodyNode => {
|
|
692
|
-
return bodyNode.type !== 'FunctionDeclaration' && hasReturnValue(bodyNode, promFilter);
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
case 'LabeledStatement':
|
|
697
|
-
case 'WhileStatement':
|
|
698
|
-
case 'DoWhileStatement':
|
|
699
|
-
case 'ForStatement':
|
|
700
|
-
case 'ForInStatement':
|
|
701
|
-
case 'ForOfStatement':
|
|
702
|
-
case 'WithStatement':
|
|
703
|
-
{
|
|
704
|
-
return hasReturnValue(node.body, promFilter);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
case 'IfStatement':
|
|
708
|
-
{
|
|
709
|
-
return hasReturnValue(node.consequent, promFilter) || hasReturnValue(node.alternate, promFilter);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
case 'TryStatement':
|
|
713
|
-
{
|
|
714
|
-
return hasReturnValue(node.block, promFilter) || hasReturnValue(node.handler && node.handler.body, promFilter) || hasReturnValue(node.finalizer, promFilter);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
case 'SwitchStatement':
|
|
718
|
-
{
|
|
719
|
-
return node.cases.some(someCase => {
|
|
720
|
-
return someCase.consequent.some(nde => {
|
|
721
|
-
return hasReturnValue(nde, promFilter);
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
case 'ReturnStatement':
|
|
727
|
-
{
|
|
728
|
-
// void return does not count.
|
|
729
|
-
if (node.argument === null) {
|
|
730
|
-
return false;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
if (promFilter && isNewPromiseExpression(node.argument)) {
|
|
734
|
-
// Let caller decide how to filter, but this is, at the least,
|
|
735
|
-
// a return of sorts and truthy
|
|
736
|
-
return promFilter(node.argument);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
return true;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
default:
|
|
743
|
-
{
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
/**
|
|
749
|
-
* Avoids further checking child nodes if a nested function shadows the
|
|
750
|
-
* resolver, but otherwise, if name is used (by call or passed in as an
|
|
751
|
-
* argument to another function), will be considered as non-empty.
|
|
752
|
-
*
|
|
753
|
-
* This could check for redeclaration of the resolver, but as such is
|
|
754
|
-
* unlikely, we avoid the performance cost of checking everywhere for
|
|
755
|
-
* (re)declarations or assignments.
|
|
756
|
-
*
|
|
757
|
-
* @param {AST} node
|
|
758
|
-
* @param {string} resolverName
|
|
759
|
-
* @returns {boolean}
|
|
760
|
-
*/
|
|
761
|
-
// eslint-disable-next-line complexity
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
const hasNonEmptyResolverCall = (node, resolverName) => {
|
|
765
|
-
if (!node) {
|
|
766
|
-
return false;
|
|
767
|
-
} // Arrow function without block
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
switch (node.type) {
|
|
771
|
-
// istanbul ignore next -- In Babel?
|
|
772
|
-
case 'OptionalCallExpression':
|
|
773
|
-
case 'CallExpression':
|
|
774
|
-
return node.callee.name === resolverName && ( // Implicit or explicit undefined
|
|
775
|
-
node.arguments.length > 1 || node.arguments[0] !== undefined) || node.arguments.some(nde => {
|
|
776
|
-
// Being passed in to another function (which might invoke it)
|
|
777
|
-
return nde.type === 'Identifier' && nde.name === resolverName || // Handle nested items
|
|
778
|
-
hasNonEmptyResolverCall(nde, resolverName);
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
case 'ChainExpression':
|
|
782
|
-
case 'Decorator':
|
|
783
|
-
case 'ExpressionStatement':
|
|
784
|
-
return hasNonEmptyResolverCall(node.expression, resolverName);
|
|
785
|
-
|
|
786
|
-
case 'ClassBody':
|
|
787
|
-
case 'BlockStatement':
|
|
788
|
-
return node.body.some(bodyNode => {
|
|
789
|
-
return hasNonEmptyResolverCall(bodyNode, resolverName);
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
case 'FunctionExpression':
|
|
793
|
-
case 'FunctionDeclaration':
|
|
794
|
-
case 'ArrowFunctionExpression':
|
|
795
|
-
{
|
|
796
|
-
var _node$params$;
|
|
797
|
-
|
|
798
|
-
// Shadowing
|
|
799
|
-
if (((_node$params$ = node.params[0]) === null || _node$params$ === void 0 ? void 0 : _node$params$.name) === resolverName) {
|
|
800
|
-
return false;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
return hasNonEmptyResolverCall(node.body, resolverName);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
case 'LabeledStatement':
|
|
807
|
-
case 'WhileStatement':
|
|
808
|
-
case 'DoWhileStatement':
|
|
809
|
-
case 'ForStatement':
|
|
810
|
-
case 'ForInStatement':
|
|
811
|
-
case 'ForOfStatement':
|
|
812
|
-
case 'WithStatement':
|
|
813
|
-
{
|
|
814
|
-
return hasNonEmptyResolverCall(node.body, resolverName);
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
case 'ConditionalExpression':
|
|
818
|
-
case 'IfStatement':
|
|
819
|
-
{
|
|
820
|
-
return hasNonEmptyResolverCall(node.test, resolverName) || hasNonEmptyResolverCall(node.consequent, resolverName) || hasNonEmptyResolverCall(node.alternate, resolverName);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
case 'TryStatement':
|
|
824
|
-
{
|
|
825
|
-
return hasNonEmptyResolverCall(node.block, resolverName) || hasNonEmptyResolverCall(node.handler && node.handler.body, resolverName) || hasNonEmptyResolverCall(node.finalizer, resolverName);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
case 'SwitchStatement':
|
|
829
|
-
{
|
|
830
|
-
return node.cases.some(someCase => {
|
|
831
|
-
return someCase.consequent.some(nde => {
|
|
832
|
-
return hasNonEmptyResolverCall(nde, resolverName);
|
|
833
|
-
});
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
case 'ArrayPattern':
|
|
838
|
-
case 'ArrayExpression':
|
|
839
|
-
return node.elements.some(element => {
|
|
840
|
-
return hasNonEmptyResolverCall(element, resolverName);
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
case 'AssignmentPattern':
|
|
844
|
-
return hasNonEmptyResolverCall(node.right, resolverName);
|
|
845
|
-
|
|
846
|
-
case 'AssignmentExpression':
|
|
847
|
-
case 'BinaryExpression':
|
|
848
|
-
case 'LogicalExpression':
|
|
849
|
-
{
|
|
850
|
-
return hasNonEmptyResolverCall(node.left, resolverName) || hasNonEmptyResolverCall(node.right, resolverName);
|
|
851
|
-
}
|
|
852
|
-
// Comma
|
|
853
|
-
|
|
854
|
-
case 'SequenceExpression':
|
|
855
|
-
case 'TemplateLiteral':
|
|
856
|
-
return node.expressions.some(subExpression => {
|
|
857
|
-
return hasNonEmptyResolverCall(subExpression, resolverName);
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
case 'ObjectPattern':
|
|
861
|
-
case 'ObjectExpression':
|
|
862
|
-
return node.properties.some(property => {
|
|
863
|
-
return hasNonEmptyResolverCall(property, resolverName);
|
|
864
|
-
});
|
|
865
|
-
// istanbul ignore next -- In Babel?
|
|
866
|
-
|
|
867
|
-
case 'ClassMethod':
|
|
868
|
-
case 'MethodDefinition':
|
|
869
|
-
return node.decorators && node.decorators.some(decorator => {
|
|
870
|
-
return hasNonEmptyResolverCall(decorator, resolverName);
|
|
871
|
-
}) || node.computed && hasNonEmptyResolverCall(node.key, resolverName) || hasNonEmptyResolverCall(node.value, resolverName);
|
|
872
|
-
// istanbul ignore next -- In Babel?
|
|
873
|
-
|
|
874
|
-
case 'ObjectProperty':
|
|
875
|
-
/* eslint-disable no-fallthrough */
|
|
876
|
-
// istanbul ignore next -- In Babel?
|
|
877
|
-
|
|
878
|
-
case 'PropertyDefinition': // istanbul ignore next -- In Babel?
|
|
879
|
-
|
|
880
|
-
case 'ClassProperty':
|
|
881
|
-
/* eslint-enable no-fallthrough */
|
|
882
|
-
|
|
883
|
-
case 'Property':
|
|
884
|
-
return node.computed && hasNonEmptyResolverCall(node.key, resolverName) || hasNonEmptyResolverCall(node.value, resolverName);
|
|
885
|
-
// istanbul ignore next -- In Babel?
|
|
886
|
-
|
|
887
|
-
case 'ObjectMethod':
|
|
888
|
-
// istanbul ignore next -- In Babel?
|
|
889
|
-
return node.computed && hasNonEmptyResolverCall(node.key, resolverName) || node.arguments.some(nde => {
|
|
890
|
-
return hasNonEmptyResolverCall(nde, resolverName);
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
case 'ClassExpression':
|
|
894
|
-
case 'ClassDeclaration':
|
|
895
|
-
return hasNonEmptyResolverCall(node.body, resolverName);
|
|
896
|
-
|
|
897
|
-
case 'AwaitExpression':
|
|
898
|
-
case 'SpreadElement':
|
|
899
|
-
case 'UnaryExpression':
|
|
900
|
-
case 'YieldExpression':
|
|
901
|
-
return hasNonEmptyResolverCall(node.argument, resolverName);
|
|
902
|
-
|
|
903
|
-
case 'VariableDeclaration':
|
|
904
|
-
{
|
|
905
|
-
return node.declarations.some(nde => {
|
|
906
|
-
return hasNonEmptyResolverCall(nde, resolverName);
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
case 'VariableDeclarator':
|
|
911
|
-
{
|
|
912
|
-
return hasNonEmptyResolverCall(node.id, resolverName) || hasNonEmptyResolverCall(node.init, resolverName);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
case 'TaggedTemplateExpression':
|
|
916
|
-
return hasNonEmptyResolverCall(node.quasi, resolverName);
|
|
917
|
-
// ?.
|
|
918
|
-
// istanbul ignore next -- In Babel?
|
|
919
|
-
|
|
920
|
-
case 'OptionalMemberExpression':
|
|
921
|
-
case 'MemberExpression':
|
|
922
|
-
return hasNonEmptyResolverCall(node.object, resolverName) || hasNonEmptyResolverCall(node.property, resolverName);
|
|
923
|
-
// istanbul ignore next -- In Babel?
|
|
924
|
-
|
|
925
|
-
case 'Import':
|
|
926
|
-
case 'ImportExpression':
|
|
927
|
-
return hasNonEmptyResolverCall(node.source, resolverName);
|
|
928
|
-
|
|
929
|
-
case 'ReturnStatement':
|
|
930
|
-
{
|
|
931
|
-
if (node.argument === null) {
|
|
932
|
-
return false;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
return hasNonEmptyResolverCall(node.argument, resolverName);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
/*
|
|
939
|
-
// Shouldn't need to parse literals/literal components, etc.
|
|
940
|
-
case 'Identifier':
|
|
941
|
-
case 'TemplateElement':
|
|
942
|
-
case 'Super':
|
|
943
|
-
// Exports not relevant in this context
|
|
944
|
-
*/
|
|
945
|
-
|
|
946
|
-
default:
|
|
947
|
-
return false;
|
|
948
|
-
}
|
|
949
|
-
};
|
|
950
|
-
/**
|
|
951
|
-
* Checks if a Promise executor has no resolve value or an empty value.
|
|
952
|
-
* An `undefined` resolve does not count.
|
|
953
|
-
*
|
|
954
|
-
* @param {object} node
|
|
955
|
-
* @param {boolean} anyPromiseAsReturn
|
|
956
|
-
* @returns {boolean}
|
|
957
|
-
*/
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const hasValueOrExecutorHasNonEmptyResolveValue = (node, anyPromiseAsReturn) => {
|
|
961
|
-
return hasReturnValue(node, prom => {
|
|
962
|
-
if (anyPromiseAsReturn) {
|
|
963
|
-
return true;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
if (isVoidPromise(prom)) {
|
|
967
|
-
return false;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
const [{
|
|
971
|
-
params,
|
|
972
|
-
body
|
|
973
|
-
} = {}] = prom.arguments;
|
|
974
|
-
|
|
975
|
-
if (!(params !== null && params !== void 0 && params.length)) {
|
|
976
|
-
return false;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
const [{
|
|
980
|
-
name: resolverName
|
|
981
|
-
}] = params;
|
|
982
|
-
return hasNonEmptyResolverCall(body, resolverName);
|
|
983
|
-
});
|
|
984
640
|
}; // eslint-disable-next-line complexity
|
|
985
641
|
|
|
986
642
|
|
|
@@ -1261,7 +917,7 @@ const isInlineTag = (tag) => {
|
|
|
1261
917
|
|
|
1262
918
|
const parseClosureTemplateTag = tag => {
|
|
1263
919
|
return tag.name.split(',').map(type => {
|
|
1264
|
-
return type.trim();
|
|
920
|
+
return type.trim().replace(/^\[(?<name>.*?)=.*\]$/u, '$<name>');
|
|
1265
921
|
});
|
|
1266
922
|
};
|
|
1267
923
|
/**
|
|
@@ -1497,10 +1153,10 @@ var _default = {
|
|
|
1497
1153
|
hasATag,
|
|
1498
1154
|
hasDefinedTypeTag,
|
|
1499
1155
|
hasParams,
|
|
1500
|
-
hasReturnValue,
|
|
1156
|
+
hasReturnValue: _hasReturnValue.hasReturnValue,
|
|
1501
1157
|
hasTag,
|
|
1502
1158
|
hasThrowValue,
|
|
1503
|
-
hasValueOrExecutorHasNonEmptyResolveValue,
|
|
1159
|
+
hasValueOrExecutorHasNonEmptyResolveValue: _hasReturnValue.hasValueOrExecutorHasNonEmptyResolveValue,
|
|
1504
1160
|
hasYieldValue,
|
|
1505
1161
|
isConstructor,
|
|
1506
1162
|
isGetter,
|