]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/id-denylist.md
040f26e894c099f633ca57cbbd40de5fd06c3426
[pve-eslint.git] / eslint / docs / rules / id-denylist.md
1 # disallow specified identifiers (id-denylist)
2
3 > "There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
4
5 Generic names can lead to hard-to-decipher code. This rule allows you to specify a deny list of disallowed identifier names to avoid this practice.
6
7 ## Rule Details
8
9 This rule disallows specified identifiers in assignments and `function` definitions.
10
11 This rule will catch disallowed identifiers that are:
12
13 - variable declarations
14 - function declarations
15 - object properties assigned to during object creation
16
17 It will not catch disallowed identifiers that are:
18
19 - function calls (so you can still use functions you do not have control over)
20 - object properties (so you can still use objects you do not have control over)
21
22 ## Options
23
24 The rule takes one or more strings as options: the names of restricted identifiers.
25
26 For example, to restrict the use of common generic identifiers:
27
28 ```json
29 {
30 "id-denylist": ["error", "data", "err", "e", "cb", "callback"]
31 }
32 ```
33
34 Examples of **incorrect** code for this rule with sample `"data", "callback"` restricted identifiers:
35
36 ```js
37 /*eslint id-denylist: ["error", "data", "callback"] */
38
39 var data = {...};
40
41 function callback() {
42 // ...
43 }
44
45 element.callback = function() {
46 // ...
47 };
48
49 var itemSet = {
50 data: [...]
51 };
52 ```
53
54 Examples of **correct** code for this rule with sample `"data", "callback"` restricted identifiers:
55
56 ```js
57 /*eslint id-denylist: ["error", "data", "callback"] */
58
59 var encodingOptions = {...};
60
61 function processFileResult() {
62 // ...
63 }
64
65 element.successHandler = function() {
66 // ...
67 };
68
69 var itemSet = {
70 entities: [...]
71 };
72
73 callback(); // all function calls are ignored
74
75 foo.callback(); // all function calls are ignored
76
77 foo.data; // all property names that are not assignments are ignored
78 ```
79
80 ## When Not To Use It
81
82 You can turn this rule off if you do not want to restrict the use of certain identifiers.