]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/symbol-description.md
first commit
[pve-eslint.git] / eslint / docs / rules / symbol-description.md
1 # require symbol description (symbol-description)
2
3 The `Symbol` function may have an optional description:
4
5 ```js
6 var foo = Symbol("some description");
7
8 var someString = "some description";
9 var bar = Symbol(someString);
10 ```
11
12
13 Using `description` promotes easier debugging: when a symbol is logged the description is used:
14
15 ```js
16 var foo = Symbol("some description");
17
18 > console.log(foo);
19 // Symbol(some description)
20 ```
21
22 It may facilitate identifying symbols when one is observed during debugging.
23
24
25 ## Rule Details
26
27 This rules requires a description when creating symbols.
28
29
30 ## Examples
31
32 Examples of **incorrect** code for this rule:
33
34 ```js
35 /*eslint symbol-description: "error"*/
36 /*eslint-env es6*/
37
38 var foo = Symbol();
39 ```
40
41 Examples of **correct** code for this rule:
42
43 ```js
44 /*eslint symbol-description: "error"*/
45 /*eslint-env es6*/
46
47 var foo = Symbol("some description");
48
49 var someString = "some description";
50 var bar = Symbol(someString);
51 ```
52
53
54 ## When Not To Use It
55
56 This rule should not be used in ES3/5 environments.
57 In addition, this rule can be safely turned off if you don't want to enforce presence of `description` when creating Symbols.
58
59 ## Further Reading
60
61 * [Symbol Objects specification: Symbol description](https://www.ecma-international.org/ecma-262/6.0/#sec-symbol-description)