symbol-description

需要符号说明

Symbol 函数可能有一个可选的描述:

¥The Symbol function may have an optional description:

const foo = Symbol("some description");

const someString = "some description";
const bar = Symbol(someString);

使用 description 可以促进更轻松的调试:当记录一个符号时,使用描述:

¥Using description promotes easier debugging: when a symbol is logged the description is used:

const foo = Symbol("some description");

> console.log(foo);
// Symbol(some description)

当在调试期间观察到符号时,它可能有助于识别符号。

¥It may facilitate identifying symbols when one is observed during debugging.

规则详情

¥Rule Details

此规则在创建符号时需要描述。

¥This rules requires a description when creating symbols.

示例

¥Examples

此规则的错误代码示例:

¥Examples of incorrect code for this rule:

在线运行
/*eslint symbol-description: "error"*/

const foo = Symbol();

此规则的正确代码示例:

¥Examples of correct code for this rule:

在线运行
/*eslint symbol-description: "error"*/

const foo = Symbol("some description");

const someString = "some description";
const bar = Symbol(someString);

何时不使用

¥When Not To Use It

此规则不应在 ES3/5 环境中使用。此外,如果你不想在创建符号时强制存在 description,则可以安全地关闭此规则。

¥This rule should not be used in ES3/5 environments. In addition, this rule can be safely turned off if you don’t want to enforce presence of description when creating Symbols.

版本

此规则是在 ESLint v3.4.0 中引入。

进阶读物

资源