Javascript - 哪个 eslint jsdoc 规则/设置强制 @private、@public 或 @protected

发布于 2025-01-13 12:24:50 字数 461 浏览 2 评论 0原文

是否有任何 eslint jsdoc 规则/设置来强制 @private@public@protected?使用模块 eslint-plugin-jsdoc 没有强制的规则/设置它。

以下示例应引发 eslint jsdoc 错误:

/**
 * @param {string} foo
 */
function quux (foo) {

}

不应接受此 jsDoc,因为 @private@public@protected 不可用。

也许你可以帮助我。 谢谢。

Is there any eslint jsdoc rule/setting to force either @private, @public or @protected? With the module eslint-plugin-jsdoc there is no rule/setting to force it.

Following example should throw a eslint jsdoc error:

/**
 * @param {string} foo
 */
function quux (foo) {

}

This jsDoc should not accepted because @private, @public or @protected are not available.

Maybe you can help me.
Thanks.

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

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

发布评论

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

评论(1

我最亲爱的 2025-01-20 12:24:50

您可以使用 jsdoc/no-restricted-syntax 规则,禁止没有这些访问修饰符的块。

将其添加到您的 eslint 配置文件中:

rules: {
  'jsdoc/no-restricted-syntax': ['error', {
    contexts: [
      {
        comment: 'JsdocBlock:not(JsdocBlock:has(JsdocTag[tag=/private|protected|public/]))',
        context: 'any',
        message: 'Access modifier tags must be present',
      },
    ]
  }
}

You can use the jsdoc/no-restricted-syntax rule, disallowing blocks which don't have those access modifiers.

Add this to your eslint config file:

rules: {
  'jsdoc/no-restricted-syntax': ['error', {
    contexts: [
      {
        comment: 'JsdocBlock:not(JsdocBlock:has(JsdocTag[tag=/private|protected|public/]))',
        context: 'any',
        message: 'Access modifier tags must be present',
      },
    ]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文