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