eslint-plugin-jsdoc 39.3.3 → 39.3.6
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 +16 -2
- package/dist/iterateJsdoc.js +1 -1
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/jsdocUtils.js +13 -357
- 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/CONTRIBUTING.md +0 -100
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
|
};
|
|
@@ -365,7 +373,7 @@ const getPreferredTagName = (context, mode, name, tagPreference = {}) => {
|
|
|
365
373
|
return [key.replace(/^tag /u, ''), value];
|
|
366
374
|
}));
|
|
367
375
|
|
|
368
|
-
if (name
|
|
376
|
+
if (Object.prototype.hasOwnProperty.call(tagPreferenceFixed, name)) {
|
|
369
377
|
return tagPreferenceFixed[name];
|
|
370
378
|
}
|
|
371
379
|
|
|
@@ -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
|
|
|
@@ -1281,7 +937,7 @@ const parseClosureTemplateTag = tag => {
|
|
|
1281
937
|
|
|
1282
938
|
const enforcedContexts = (context, defaultContexts) => {
|
|
1283
939
|
const {
|
|
1284
|
-
contexts = defaultContexts === true ? ['ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'] : defaultContexts
|
|
940
|
+
contexts = defaultContexts === true ? ['ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression', 'TSDeclareFunction'] : defaultContexts
|
|
1285
941
|
} = context.options[0] || {};
|
|
1286
942
|
return contexts;
|
|
1287
943
|
};
|
|
@@ -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,
|