]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/id-denylist.md
import 8.3.0 source
[pve-eslint.git] / eslint / docs / rules / id-denylist.md
CommitLineData
6f036462
TL
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
5Generic 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
9This rule disallows specified identifiers in assignments and `function` definitions.
10
11This rule will catch disallowed identifiers that are:
12
13- variable declarations
14- function declarations
15- object properties assigned to during object creation
609c276f
TL
16- class fields
17- class methods
6f036462
TL
18
19It will not catch disallowed identifiers that are:
20
21- function calls (so you can still use functions you do not have control over)
22- object properties (so you can still use objects you do not have control over)
23
24## Options
25
26The rule takes one or more strings as options: the names of restricted identifiers.
27
28For example, to restrict the use of common generic identifiers:
29
30```json
31{
32 "id-denylist": ["error", "data", "err", "e", "cb", "callback"]
33}
34```
35
36Examples of **incorrect** code for this rule with sample `"data", "callback"` restricted identifiers:
37
38```js
39/*eslint id-denylist: ["error", "data", "callback"] */
40
41var data = {...};
42
43function callback() {
44 // ...
45}
46
47element.callback = function() {
48 // ...
49};
50
51var itemSet = {
52 data: [...]
53};
609c276f
TL
54
55class Foo {
56 data = [];
57}
58
59class Foo {
60 #data = [];
61}
62
63class Foo {
64 callback( {);
65}
66
67class Foo {
68 #callback( {);
69}
6f036462
TL
70```
71
72Examples of **correct** code for this rule with sample `"data", "callback"` restricted identifiers:
73
74```js
75/*eslint id-denylist: ["error", "data", "callback"] */
76
77var encodingOptions = {...};
78
79function processFileResult() {
80 // ...
81}
82
83element.successHandler = function() {
84 // ...
85};
86
87var itemSet = {
88 entities: [...]
89};
90
91callback(); // all function calls are ignored
92
93foo.callback(); // all function calls are ignored
94
95foo.data; // all property names that are not assignments are ignored
609c276f
TL
96
97class Foo {
98 items = [];
99}
100
101class Foo {
102 #items = [];
103}
104
105class Foo {
106 method( {);
107}
108
109class Foo {
110 #method( {);
111}
6f036462
TL
112```
113
114## When Not To Use It
115
116You can turn this rule off if you do not want to restrict the use of certain identifiers.