eslint-plugin-jsdoc 24.0.5 → 24.0.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
CHANGED
|
@@ -9872,6 +9872,15 @@ class foo extends base {
|
|
|
9872
9872
|
}
|
|
9873
9873
|
}
|
|
9874
9874
|
// Settings: {"jsdoc":{"mode":"closure"}}
|
|
9875
|
+
|
|
9876
|
+
/**
|
|
9877
|
+
* @param {string} cb
|
|
9878
|
+
*/
|
|
9879
|
+
function createGetter (cb) {
|
|
9880
|
+
return function (...args) {
|
|
9881
|
+
cb();
|
|
9882
|
+
};
|
|
9883
|
+
}
|
|
9875
9884
|
````
|
|
9876
9885
|
|
|
9877
9886
|
|
|
@@ -158,7 +158,7 @@ const getReducedASTNode = function getReducedASTNode(node, sourceCode) {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
if (parent) {
|
|
161
|
+
if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {
|
|
162
162
|
if (parent.parent && parent.parent.type === 'ExportNamedDeclaration') {
|
|
163
163
|
return parent.parent;
|
|
164
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/eslint/getJSDocComment.js"],"names":["isCommentToken","token","type","getDecorator","sourceCode","tokenBefore","getTokenBefore","includeComments","value","looksLikeExport","astNode","getTSFunctionComment","parent","grandparent","greatGrandparent","greatGreatGrandparent","getReducedASTNode","node","includes","getCommentsBefore","length","test","getJSDocComment","settings","findJSDocComment","minLines","maxLines","currentNode","decorator","charAt","loc","start","line","end","reducedNode"],"mappings":";;;;;;;AAAA;;;;;;AAMA;;;;;;AAMA,MAAMA,cAAc,GAAIC,KAAD,IAAW;AAChC,SAAOA,KAAK,CAACC,IAAN,KAAe,MAAf,IAAyBD,KAAK,CAACC,IAAN,KAAe,OAAxC,IAAmDD,KAAK,CAACC,IAAN,KAAe,SAAzE;AACD,CAFD;;AAI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C,CAAd;AACA,YAAMqB,SAAS,GAAGzB,YAAY,CAACE,WAAD,EAAcD,UAAd,CAA9B;;AACA,UAAIwB,SAAJ,EAAe;AACbD,QAAAA,WAAW,GAAGC,SAAd;AACA;AACD;;AACD,UAAI,CAACvB,WAAD,IAAgB,CAACL,cAAc,CAACK,WAAD,CAAnC,EAAkD;AAChD,eAAO,IAAP;AACD;;AACD,UAAIA,WAAW,CAACH,IAAZ,KAAqB,MAAzB,EAAiC;AAC/ByB,QAAAA,WAAW,GAAGtB,WAAd;AACA;AACD;;AACD;AACD;;AAED,QACEA,WAAW,CAACH,IAAZ,KAAqB,OAArB,IACAG,WAAW,CAACG,KAAZ,CAAkBqB,MAAlB,CAAyB,CAAzB,MAAgC,GADhC,IAEAF,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6B3B,WAAW,CAACyB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDP,QAFzD,IAGAE,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6B3B,WAAW,CAACyB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDN,QAJ3D,EAKE;AACA,aAAOrB,WAAP;AACD;;AAED,WAAO,IAAP;AACD,GAhCD;;AAkCA,QAAM6B,WAAW,GAAGlB,iBAAiB,CAACC,IAAD,EAAOb,UAAP,CAArC;AAEA,SAAOoB,gBAAgB,CAACU,WAAD,CAAvB;AACD,CA9CD;;;eAiDeZ,e","sourcesContent":["/**\n * Obtained originally from {@link https://github.com/eslint/eslint/blob/master/lib/util/source-code.js#L313}\n *\n * @license MIT\n */\n\n/**\n * Checks if the given token is a comment token or not.\n *\n * @param {Token} token - The token to check.\n * @returns {boolean} `true` if the token is a comment token.\n */\nconst isCommentToken = (token) => {\n return token.type === 'Line' || token.type === 'Block' || token.type === 'Shebang';\n};\n\nconst getDecorator = (token, sourceCode) => {\n if (token && token.type === 'Identifier') {\n const tokenBefore = sourceCode.getTokenBefore(token, {includeComments: true});\n if (tokenBefore && tokenBefore.type === 'Punctuator' && tokenBefore.value === '@') {\n return tokenBefore;\n }\n }\n\n return false;\n};\n\n/**\n * Check to see if its a ES6 export declaration.\n *\n * @param {ASTNode} astNode An AST node.\n * @returns {boolean} whether the given node represents an export declaration.\n * @private\n */\nconst looksLikeExport = function (astNode) {\n return astNode.type === 'ExportDefaultDeclaration' || astNode.type === 'ExportNamedDeclaration' ||\n astNode.type === 'ExportAllDeclaration' || astNode.type === 'ExportSpecifier';\n};\n\nconst getTSFunctionComment = function (astNode) {\n const {parent} = astNode;\n const grandparent = parent.parent;\n const greatGrandparent = grandparent.parent;\n const greatGreatGrandparent = greatGrandparent && greatGrandparent.parent;\n\n // istanbul ignore if\n if (parent.type !== 'TSTypeAnnotation') {\n return astNode;\n }\n\n switch (grandparent.type) {\n case 'ClassProperty':\n case 'TSDeclareFunction':\n case 'TSMethodSignature':\n case 'TSPropertySignature':\n return grandparent;\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGrandparent.type === 'VariableDeclarator'\n\n // && greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionExpression':\n // istanbul ignore else\n if (greatGrandparent.type === 'MethodDefinition') {\n return greatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore if\n if (grandparent.type !== 'Identifier') {\n // istanbul ignore next\n return astNode;\n }\n }\n\n // istanbul ignore next\n switch (greatGrandparent.type) {\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGreatGrandparent.type === 'VariableDeclarator' &&\n greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionDeclaration':\n return greatGrandparent;\n case 'VariableDeclarator':\n // istanbul ignore else\n if (greatGreatGrandparent.type === 'VariableDeclaration') {\n return greatGreatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore next\n return astNode;\n }\n};\n\n/* eslint-disable complexity */\n/**\n * Reduces the provided node to the appropriate node for evaluating JSDoc comment status.\n *\n * @param {ASTNode} node An AST node.\n * @param {SourceCode} sourceCode The ESLint SourceCode.\n * @returns {ASTNode} The AST node that can be evaluated for appropriate JSDoc comments.\n * @private\n */\nconst getReducedASTNode = function (node, sourceCode) {\n let {parent} = node;\n\n switch (node.type) {\n case 'TSFunctionType':\n return getTSFunctionComment(node);\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSEnumDeclaration':\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n return looksLikeExport(parent) ? parent : node;\n\n case 'ClassExpression':\n case 'ObjectExpression':\n case 'ArrowFunctionExpression':\n case 'TSEmptyBodyFunctionExpression':\n case 'FunctionExpression':\n if (\n !['CallExpression', 'OptionalCallExpression', 'NewExpression'].includes(parent.type)\n ) {\n while (\n !sourceCode.getCommentsBefore(parent).length &&\n !/Function/u.test(parent.type) &&\n parent.type !== 'VariableDeclaration' &&\n parent.type !== 'ExpressionStatement' &&\n parent.type !== 'MethodDefinition' &&\n parent.type !== 'Property'\n ) {\n parent = parent.parent;\n\n if (!parent) {\n break;\n }\n }\n if (parent) {\n if (parent.parent && parent.parent.type === 'ExportNamedDeclaration') {\n return parent.parent;\n }\n\n return parent;\n }\n }\n\n return node;\n\n default:\n return node;\n }\n};\n\n/**\n * Retrieves the JSDoc comment for a given node.\n *\n * @param {SourceCode} sourceCode The ESLint SourceCode\n * @param {ASTNode} node The AST node to get the comment for.\n * @param {object} settings The settings in context\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @public\n * @deprecated\n */\nconst getJSDocComment = function (sourceCode, node, settings) {\n /**\n * Checks for the presence of a JSDoc comment for the given node and returns it.\n *\n * @param {ASTNode} astNode The AST node to get the comment for.\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @private\n */\n const findJSDocComment = (astNode) => {\n const {minLines, maxLines} = settings;\n let currentNode = astNode;\n let tokenBefore = null;\n\n while (currentNode) {\n tokenBefore = sourceCode.getTokenBefore(currentNode, {includeComments: true});\n const decorator = getDecorator(tokenBefore, sourceCode);\n if (decorator) {\n currentNode = decorator;\n continue;\n }\n if (!tokenBefore || !isCommentToken(tokenBefore)) {\n return null;\n }\n if (tokenBefore.type === 'Line') {\n currentNode = tokenBefore;\n continue;\n }\n break;\n }\n\n if (\n tokenBefore.type === 'Block' &&\n tokenBefore.value.charAt(0) === '*' &&\n currentNode.loc.start.line - tokenBefore.loc.end.line >= minLines &&\n currentNode.loc.start.line - tokenBefore.loc.end.line <= maxLines\n ) {\n return tokenBefore;\n }\n\n return null;\n };\n\n const reducedNode = getReducedASTNode(node, sourceCode);\n\n return findJSDocComment(reducedNode);\n};\n\nexport {getReducedASTNode, getJSDocComment};\nexport default getJSDocComment;\n"],"file":"getJSDocComment.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/eslint/getJSDocComment.js"],"names":["isCommentToken","token","type","getDecorator","sourceCode","tokenBefore","getTokenBefore","includeComments","value","looksLikeExport","astNode","getTSFunctionComment","parent","grandparent","greatGrandparent","greatGreatGrandparent","getReducedASTNode","node","includes","getCommentsBefore","length","test","getJSDocComment","settings","findJSDocComment","minLines","maxLines","currentNode","decorator","charAt","loc","start","line","end","reducedNode"],"mappings":";;;;;;;AAAA;;;;;;AAMA;;;;;;AAMA,MAAMA,cAAc,GAAIC,KAAD,IAAW;AAChC,SAAOA,KAAK,CAACC,IAAN,KAAe,MAAf,IAAyBD,KAAK,CAACC,IAAN,KAAe,OAAxC,IAAmDD,KAAK,CAACC,IAAN,KAAe,SAAzE;AACD,CAFD;;AAIA,MAAMC,YAAY,GAAG,CAACF,KAAD,EAAQG,UAAR,KAAuB;AAC1C,MAAIH,KAAK,IAAIA,KAAK,CAACC,IAAN,KAAe,YAA5B,EAA0C;AACxC,UAAMG,WAAW,GAAGD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AAd,CAA9B;;AACA,UAAIwB,SAAJ,EAAe;AACbD,QAAAA,WAAW,GAAGC,SAAd;AACA;AACD;;AACD,UAAI,CAACvB,WAAD,IAAgB,CAACL,cAAc,CAACK,WAAD,CAAnC,EAAkD;AAChD,eAAO,IAAP;AACD;;AACD,UAAIA,WAAW,CAACH,IAAZ,KAAqB,MAAzB,EAAiC;AAC/ByB,QAAAA,WAAW,GAAGtB,WAAd;AACA;AACD;;AACD;AACD;;AAED,QACEA,WAAW,CAACH,IAAZ,KAAqB,OAArB,IACAG,WAAW,CAACG,KAAZ,CAAkBqB,MAAlB,CAAyB,CAAzB,MAAgC,GADhC,IAEAF,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6B3B,WAAW,CAACyB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDP,QAFzD,IAGAE,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6B3B,WAAW,CAACyB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDN,QAJ3D,EAKE;AACA,aAAOrB,WAAP;AACD;;AAED,WAAO,IAAP;AACD,GAhCD;;AAkCA,QAAM6B,WAAW,GAAGlB,iBAAiB,CAACC,IAAD,EAAOb,UAAP,CAArC;AAEA,SAAOoB,gBAAgB,CAACU,WAAD,CAAvB;AACD,CA9CD;;;eAiDeZ,e","sourcesContent":["/**\n * Obtained originally from {@link https://github.com/eslint/eslint/blob/master/lib/util/source-code.js#L313}\n *\n * @license MIT\n */\n\n/**\n * Checks if the given token is a comment token or not.\n *\n * @param {Token} token - The token to check.\n * @returns {boolean} `true` if the token is a comment token.\n */\nconst isCommentToken = (token) => {\n return token.type === 'Line' || token.type === 'Block' || token.type === 'Shebang';\n};\n\nconst getDecorator = (token, sourceCode) => {\n if (token && token.type === 'Identifier') {\n const tokenBefore = sourceCode.getTokenBefore(token, {includeComments: true});\n if (tokenBefore && tokenBefore.type === 'Punctuator' && tokenBefore.value === '@') {\n return tokenBefore;\n }\n }\n\n return false;\n};\n\n/**\n * Check to see if its a ES6 export declaration.\n *\n * @param {ASTNode} astNode An AST node.\n * @returns {boolean} whether the given node represents an export declaration.\n * @private\n */\nconst looksLikeExport = function (astNode) {\n return astNode.type === 'ExportDefaultDeclaration' || astNode.type === 'ExportNamedDeclaration' ||\n astNode.type === 'ExportAllDeclaration' || astNode.type === 'ExportSpecifier';\n};\n\nconst getTSFunctionComment = function (astNode) {\n const {parent} = astNode;\n const grandparent = parent.parent;\n const greatGrandparent = grandparent.parent;\n const greatGreatGrandparent = greatGrandparent && greatGrandparent.parent;\n\n // istanbul ignore if\n if (parent.type !== 'TSTypeAnnotation') {\n return astNode;\n }\n\n switch (grandparent.type) {\n case 'ClassProperty':\n case 'TSDeclareFunction':\n case 'TSMethodSignature':\n case 'TSPropertySignature':\n return grandparent;\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGrandparent.type === 'VariableDeclarator'\n\n // && greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionExpression':\n // istanbul ignore else\n if (greatGrandparent.type === 'MethodDefinition') {\n return greatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore if\n if (grandparent.type !== 'Identifier') {\n // istanbul ignore next\n return astNode;\n }\n }\n\n // istanbul ignore next\n switch (greatGrandparent.type) {\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGreatGrandparent.type === 'VariableDeclarator' &&\n greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionDeclaration':\n return greatGrandparent;\n case 'VariableDeclarator':\n // istanbul ignore else\n if (greatGreatGrandparent.type === 'VariableDeclaration') {\n return greatGreatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore next\n return astNode;\n }\n};\n\n/* eslint-disable complexity */\n/**\n * Reduces the provided node to the appropriate node for evaluating JSDoc comment status.\n *\n * @param {ASTNode} node An AST node.\n * @param {SourceCode} sourceCode The ESLint SourceCode.\n * @returns {ASTNode} The AST node that can be evaluated for appropriate JSDoc comments.\n * @private\n */\nconst getReducedASTNode = function (node, sourceCode) {\n let {parent} = node;\n\n switch (node.type) {\n case 'TSFunctionType':\n return getTSFunctionComment(node);\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSEnumDeclaration':\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n return looksLikeExport(parent) ? parent : node;\n\n case 'ClassExpression':\n case 'ObjectExpression':\n case 'ArrowFunctionExpression':\n case 'TSEmptyBodyFunctionExpression':\n case 'FunctionExpression':\n if (\n !['CallExpression', 'OptionalCallExpression', 'NewExpression'].includes(parent.type)\n ) {\n while (\n !sourceCode.getCommentsBefore(parent).length &&\n !/Function/u.test(parent.type) &&\n parent.type !== 'VariableDeclaration' &&\n parent.type !== 'ExpressionStatement' &&\n parent.type !== 'MethodDefinition' &&\n parent.type !== 'Property'\n ) {\n parent = parent.parent;\n\n if (!parent) {\n break;\n }\n }\n if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {\n if (parent.parent && parent.parent.type === 'ExportNamedDeclaration') {\n return parent.parent;\n }\n\n return parent;\n }\n }\n\n return node;\n\n default:\n return node;\n }\n};\n\n/**\n * Retrieves the JSDoc comment for a given node.\n *\n * @param {SourceCode} sourceCode The ESLint SourceCode\n * @param {ASTNode} node The AST node to get the comment for.\n * @param {object} settings The settings in context\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @public\n * @deprecated\n */\nconst getJSDocComment = function (sourceCode, node, settings) {\n /**\n * Checks for the presence of a JSDoc comment for the given node and returns it.\n *\n * @param {ASTNode} astNode The AST node to get the comment for.\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @private\n */\n const findJSDocComment = (astNode) => {\n const {minLines, maxLines} = settings;\n let currentNode = astNode;\n let tokenBefore = null;\n\n while (currentNode) {\n tokenBefore = sourceCode.getTokenBefore(currentNode, {includeComments: true});\n const decorator = getDecorator(tokenBefore, sourceCode);\n if (decorator) {\n currentNode = decorator;\n continue;\n }\n if (!tokenBefore || !isCommentToken(tokenBefore)) {\n return null;\n }\n if (tokenBefore.type === 'Line') {\n currentNode = tokenBefore;\n continue;\n }\n break;\n }\n\n if (\n tokenBefore.type === 'Block' &&\n tokenBefore.value.charAt(0) === '*' &&\n currentNode.loc.start.line - tokenBefore.loc.end.line >= minLines &&\n currentNode.loc.start.line - tokenBefore.loc.end.line <= maxLines\n ) {\n return tokenBefore;\n }\n\n return null;\n };\n\n const reducedNode = getReducedASTNode(node, sourceCode);\n\n return findJSDocComment(reducedNode);\n};\n\nexport {getReducedASTNode, getJSDocComment};\nexport default getJSDocComment;\n"],"file":"getJSDocComment.js"}
|
package/package.json
CHANGED