Skip to content
← Back to rules

jsdoc/no-defaults Correctness

🚧 An auto-fix is planned for this rule, but not implemented at this time.

它的作用

此规则会报告在 @param@default 的相关部分中使用了默认值。 它还可以选择性地报告方括号形式的可选参数的存在。

这为什么不好?

该规则旨在防止在这些标签上标注默认值, 因为这在 ES2015 默认参数中会显得多余。

示例

此规则的错误代码示例:

javascript
/** @param {number} [foo="7"] */
function quux(foo) {}

此规则的正确代码示例:

javascript
/** @param {number} foo */
function quux(foo) {}

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

配置

此规则接受一个包含以下属性的配置对象:

noOptionalParamNames

type: boolean

default: false

如果为 true,则报告 @param 标签中可选参数名称(方括号)的存在。

使用方法

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsdoc"],
  "rules": {
    "jsdoc/no-defaults": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsdoc"],
  rules: {
    "jsdoc/no-defaults": "error",
  },
});
bash
oxlint --deny jsdoc/no-defaults --jsdoc-plugin

版本

此规则是在 v0.3.2 中添加的。

参考资料