diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js index ef33f095bb..dffa9ca708 100644 --- a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js +++ b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/checkTagNames.js @@ -9,18 +9,24 @@ var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // https://babeljs.io/docs/en/babel-plugin-transform-react-jsx/ const jsxTagNames = new Set(['jsx', 'jsxFrag', 'jsxImportSource', 'jsxRuntime']); +const typedTagsAlwaysUnnecessary = new Set(['augments', 'callback', 'class', 'enum', 'implements', 'private', 'property', 'protected', 'public', 'readonly', 'this', 'type', 'typedef']); +const typedTagsNeedingName = new Set(['template']); +const typedTagsUnnecessaryOutsideDeclare = new Set(['abstract', 'access', 'class', 'constant', 'constructs', 'default', 'enum', 'export', 'exports', 'function', 'global', 'inherits', 'instance', 'interface', 'member', 'memberof', 'memberOf', 'method', 'mixes', 'mixin', 'module', 'name', 'namespace', 'override', 'property', 'requires', 'static', 'this']); var _default = (0, _iterateJsdoc.default)(({ sourceCode, jsdoc, report, utils, context, + node, settings, jsdocNode }) => { const { definedTags = [], - jsxTags + enableFixer = true, + jsxTags, + typed } = context.options[0] || {}; let definedPreferredTags = []; const { @@ -46,12 +52,69 @@ var _default = (0, _iterateJsdoc.default)(({ return preferredType; }); } - for (const jsdocTag of jsdoc.tags) { + const isInAmbientContext = subNode => { + return subNode.type === 'Program' ? context.getFilename().endsWith('.d.ts') : Boolean(subNode.declare) || isInAmbientContext(subNode.parent); + }; + const tagIsRedundantWhenTyped = jsdocTag => { + var _node$parent; + if (!typedTagsUnnecessaryOutsideDeclare.has(jsdocTag.tag)) { + return false; + } + if (jsdocTag.tag === 'default') { + return false; + } + if (context.getFilename().endsWith('.d.ts') && ['Program', null, undefined].includes(node === null || node === void 0 ? void 0 : (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type)) { + return false; + } + if (isInAmbientContext(node)) { + return false; + } + return true; + }; + const reportWithTagRemovalFixer = (message, jsdocTag, tagIndex, additionalTagChanges) => { + utils.reportJSDoc(message, jsdocTag, enableFixer ? () => { + if (jsdocTag.description.trim()) { + utils.changeTag(jsdocTag, { + postType: '', + type: '', + ...additionalTagChanges + }); + } else { + utils.removeTag(tagIndex, { + removeEmptyBlock: true + }); + } + } : null, true); + }; + const checkTagForTypedValidity = (jsdocTag, tagIndex) => { + if (typedTagsAlwaysUnnecessary.has(jsdocTag.tag)) { + reportWithTagRemovalFixer(`'@${jsdocTag.tag}' is redundant when using a type system.`, jsdocTag, tagIndex, { + postTag: '', + tag: '' + }); + return true; + } + if (tagIsRedundantWhenTyped(jsdocTag)) { + reportWithTagRemovalFixer(`'@${jsdocTag.tag}' is redundant outside of ambient (\`declare\`/\`.d.ts\`) contexts when using a type system.`, jsdocTag, tagIndex); + return true; + } + if (typedTagsNeedingName.has(jsdocTag.tag) && !jsdocTag.name) { + reportWithTagRemovalFixer(`'@${jsdocTag.tag}' without a name is redundant when using a type system.`, jsdocTag, tagIndex); + return true; + } + return false; + }; + for (let tagIndex = 0; tagIndex < jsdoc.tags.length; tagIndex += 1) { + const jsdocTag = jsdoc.tags[tagIndex]; const tagName = jsdocTag.tag; if (jsxTags && jsxTagNames.has(tagName)) { continue; } - if (utils.isValidTag(tagName, [...definedTags, ...definedPreferredTags, ...definedNonPreferredTags, ...definedStructuredTags])) { + if (typed && checkTagForTypedValidity(jsdocTag, tagIndex)) { + continue; + } + const validTags = [...definedTags, ...definedPreferredTags, ...definedNonPreferredTags, ...definedStructuredTags, ...(typed ? typedTagsNeedingName : [])]; + if (utils.isValidTag(tagName, validTags)) { let preferredTagName = utils.getPreferredTagName({ allowObjectReturn: true, defaultMessage: `Blacklisted tag found (\`@${tagName}\`)`, @@ -97,8 +160,14 @@ var _default = (0, _iterateJsdoc.default)(({ }, type: 'array' }, + enableFixer: { + type: 'boolean' + }, jsxTags: { type: 'boolean' + }, + typed: { + type: 'boolean' } }, type: 'object' |