]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-with.md
979c58b0ae91e5bd1255ba35eacc98cdac1e317d
[pve-eslint.git] / eslint / docs / rules / no-with.md
1 # disallow `with` statements (no-with)
2
3 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.
4
5 ## Rule Details
6
7 This rule disallows `with` statements.
8
9 If ESLint parses code in strict mode, the parser (instead of this rule) reports the error.
10
11 Examples of **incorrect** code for this rule:
12
13 ```js
14 /*eslint no-with: "error"*/
15
16 with (point) {
17 r = Math.sqrt(x * x + y * y); // is r a member of point?
18 }
19 ```
20
21 Examples of **correct** code for this rule:
22
23 ```js
24 /*eslint no-with: "error"*/
25 /*eslint-env es6*/
26
27 const r = ({x, y}) => Math.sqrt(x * x + y * y);
28 ```
29
30 ## When Not To Use It
31
32 If you intentionally use `with` statements then you can disable this rule.
33
34 ## Further Reading
35
36 * [with Statement Considered Harmful](https://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/)