You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rules/no-restricted-properties.md
+43-1Lines changed: 43 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,21 @@ If you want to restrict a property globally but allow specific objects to use it
85
85
}
86
86
```
87
87
88
-
Note that the `allowObjects` option cannot be used together with the `object` option since they are mutually exclusive.
88
+
If you want to restrict all properties on an object except for specific ones, you can use the `allowProperties` option:
89
+
90
+
```json
91
+
{
92
+
"rules": {
93
+
"no-restricted-properties": [2, {
94
+
"object": "config",
95
+
"allowProperties": ["settings", "version"],
96
+
"message": "Accessing other properties is restricted."
97
+
}]
98
+
}
99
+
}
100
+
```
101
+
102
+
Note that the `allowObjects` option cannot be used together with the `object` option since they are mutually exclusive. Similarly, the `allowProperties` option cannot be used together with the `property` option since they are also mutually exclusive.
89
103
90
104
Examples of **incorrect** code for this rule:
91
105
@@ -145,6 +159,20 @@ myArray.push(5);
145
159
146
160
:::
147
161
162
+
::: incorrect
163
+
164
+
```js
165
+
/* eslint no-restricted-properties: [2, {
166
+
"object": "config",
167
+
"allowProperties": ["settings", "version"]
168
+
}] */
169
+
170
+
config.apiKey="12345";
171
+
config.timeout=5000;
172
+
```
173
+
174
+
:::
175
+
148
176
Examples of **correct** code for this rule:
149
177
150
178
::: correct
@@ -188,6 +216,20 @@ history.push('/about');
188
216
189
217
:::
190
218
219
+
::: correct
220
+
221
+
```js
222
+
/* eslint no-restricted-properties: [2, {
223
+
"object": "config",
224
+
"allowProperties": ["settings", "version"]
225
+
}] */
226
+
227
+
config.settings= { theme:"dark" };
228
+
config.version="1.0.0";
229
+
```
230
+
231
+
:::
232
+
191
233
## When Not To Use It
192
234
193
235
If you don't have any object/property combinations to restrict, you should not use this rule.
0 commit comments