]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-with.md
f72fbdb56f1c901d0b33cf05024d2bf606ee884a
[pve-eslint.git] / eslint / docs / src / rules / no-with.md
1 ---
2 title: no-with
3 layout: doc
4 rule_type: suggestion
5 further_reading:
6 - https://web.archive.org/web/20200717110117/https://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
7 ---
8
9
10
11 The `with` statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to.
12
13 ## Rule Details
14
15 This rule disallows `with` statements.
16
17 If ESLint parses code in strict mode, the parser (instead of this rule) reports the error.
18
19 Examples of **incorrect** code for this rule:
20
21 ::: incorrect
22
23 ```js
24 /*eslint no-with: "error"*/
25
26 with (point) {
27 r = Math.sqrt(x * x + y * y); // is r a member of point?
28 }
29 ```
30
31 :::
32
33 Examples of **correct** code for this rule:
34
35 ::: correct
36
37 ```js
38 /*eslint no-with: "error"*/
39 /*eslint-env es6*/
40
41 const r = ({x, y}) => Math.sqrt(x * x + y * y);
42 ```
43
44 :::
45
46 ## When Not To Use It
47
48 If you intentionally use `with` statements then you can disable this rule.