eslint-plugin-jsdoc
Version:
JSDoc linting rules for ESLint.
1 lines • 5.22 kB
Source Map (JSON)
{"version":3,"file":"noTypes.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/noTypes.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * @param {import('comment-parser').Line} line\n */\nconst removeType = ({\n tokens,\n}) => {\n tokens.postTag = '';\n tokens.type = '';\n};\n\nexport default iterateJsdoc(({\n node,\n utils,\n}) => {\n if (!utils.isIteratingFunctionOrVariable() && !utils.isVirtualFunction()) {\n return;\n }\n\n const tags = utils.getPresentTags([\n 'param', 'arg', 'argument', 'returns', 'return',\n ]);\n\n for (const tag of tags) {\n if (tag.type) {\n utils.reportJSDoc(`Types are not permitted on @${tag.tag}.`, tag, () => {\n for (const source of tag.source) {\n removeType(source);\n }\n });\n }\n }\n\n if (node?.type === 'ClassDeclaration') {\n const propertyTags = utils.getPresentTags([\n 'prop', 'property',\n ]);\n for (const tag of propertyTags) {\n if (tag.type) {\n utils.reportJSDoc(`Types are not permitted on @${tag.tag} in the supplied context.`, tag, () => {\n for (const source of tag.source) {\n removeType(source);\n }\n });\n }\n }\n }\n}, {\n contextDefaults: [\n 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression', 'TSDeclareFunction',\n // Add this to above defaults\n 'TSMethodSignature', 'ClassDeclaration',\n ],\n meta: {\n docs: {\n description: 'This rule reports types being used on `@param` or `@returns` (redundant with TypeScript).',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-types.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n contexts: {\n description: `Set this to an array of strings representing the AST context (or an object with\noptional \\`context\\` and \\`comment\\` properties) where you wish the rule to be applied.\n\n\\`context\\` defaults to \\`any\\` and \\`comment\\` defaults to no specific comment context.\n\nOverrides the default contexts (\\`ArrowFunctionExpression\\`, \\`FunctionDeclaration\\`,\n\\`FunctionExpression\\`, \\`TSDeclareFunction\\`, \\`TSMethodSignature\\`,\n\\`ClassDeclaration\\`). Set to \\`\"any\"\\` if you want\nthe rule to apply to any JSDoc block throughout your files (as is necessary\nfor finding function blocks not attached to a function declaration or\nexpression, i.e., \\`@callback\\` or \\`@function\\` (or its aliases \\`@func\\` or\n\\`@method\\`) (including those associated with an \\`@interface\\`).\n\nSee the [\"AST and Selectors\"](../advanced.md#ast-and-selectors)\nsection of our Advanced docs for more on the expected format.`,\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA8C;AAE9C;AACA;AACA;AACA,MAAM,UAAU,GAAG,CAAC;EAClB;AACF,CAAC,KAAK;EACJ,MAAM,CAAC,OAAO,GAAG,EAAE;EACnB,MAAM,CAAC,IAAI,GAAG,EAAE;AAClB,CAAC;AAAC,iCAEa,IAAAA,qBAAY,EAAC,CAAC;EAC3B,IAAI;EACJ;AACF,CAAC,KAAK;EACJ,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,EAAE;IACxE;EACF;EAEA,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,CAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAChD,CAAC;EAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;IACtB,IAAI,GAAG,CAAC,IAAI,EAAE;MACZ,KAAK,CAAC,WAAW,CAAC,+BAA+B,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM;QACtE,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE;UAC/B,UAAU,CAAC,MAAM,CAAC;QACpB;MACF,CAAC,CAAC;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