如何配置 eslint-plugin-jsdoc 以禁止 '*'和“任何”同时使用最少的规则集?

发布于 2025-01-14 03:25:37 字数 950 浏览 4 评论 0原文

我正在尝试设置 preferredTypes 以防止 *any 作为参数/属性类型。我不想使用大部分推荐规则,因为它标记了太多问题。我正在尝试让我的团队轻松使用此 lint 规则集,并逐步修复问题并稍后切换规则。

我认为防止 @param {*} 很容易完成 根据文档

settings.jsdoc.preferredTypes 用于指示首选或禁止类型的选项映射(如果此处指示默认类型,则这些类型将优先于检查类型的默认建议)。

所以我的 .eslintrc.js 设置对象看起来像:

...
settings: {
  ...
  jsdoc: { preferredTypes: { '*': false } }
}

我有规则 'jsdoc/valid-types'、'jsdoc/no-undefined-types' 和 'jsdoc/check-tag-names '(选择作为标记更大错误的平衡,但现在不是太多)。

但我在 @param {*} 上没有看到任何错误报告。

是否可以在不添加额外的 jsdoc lint 规则的情况下完成此操作,或者如果确实需要它们,我可以将其自定义为仅命中 {*}{any} 吗?

I'm trying to set preferredTypes to prevent * or any as param/property types. I don't want to use most of the recommended rules as it flags up too many issues. I'm trying to ease my team onto using this lint rule set, and gradually fix issues and switch rules on later.

I thought preventing @param {*} would be easily done as per the docs:

settings.jsdoc.preferredTypes An option map to indicate preferred or forbidden types (if default types are indicated here, these will have precedence over the default recommendations for check-types).

So my .eslintrc.js settings object looks like:

...
settings: {
  ...
  jsdoc: { preferredTypes: { '*': false } }
}

And I have the rules 'jsdoc/valid-types', 'jsdoc/no-undefined-types', and 'jsdoc/check-tag-names' (picked as a balance of flagging bigger errors but not too many right now).

But I'm not seeing any reporting of errors on @param {*}.

Can this be done without adding extra jsdoc lint rules, or if it does need them can I customise it to it only hits {*} or {any}?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2025-01-21 03:25:37

至少您需要 jsdoc/check-types

此规则在 check-types 的文档中引用,并且此规则是必需的,即使它在 check-types 的文档中没有明确说明代码>首选类型。

这是隐藏在 check-types 示例:

/**
 * @param {*} baz
 */
function qux(baz) {
}
// Settings: {"jsdoc":{"preferredTypes":{"*":false,"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "baz" type "*".

如果没有 check-types,首选类型设置不会执行任何操作,如果您考虑一下,这是有道理的。

At minimum you need jsdoc/check-types

This rule is referenced in the documentation for check-types and this rule is required, even though it's not explicit under the documentation for preferredTypes.

Here is the excerpt burried part way down the check-types examples:

/**
 * @param {*} baz
 */
function qux(baz) {
}
// Settings: {"jsdoc":{"preferredTypes":{"*":false,"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "baz" type "*".

Without check-types the preferred types setting does nothing, which, if you think about it makes sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文