]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/rules/no-with.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / rules / no-with.md
CommitLineData
8f9d1d4d
DC
1---
2title: no-with
8f9d1d4d
DC
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
eb39fafa
DC
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
8f9d1d4d
DC
20::: incorrect
21
eb39fafa
DC
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
8f9d1d4d
DC
30:::
31
eb39fafa
DC
32Examples of **correct** code for this rule:
33
8f9d1d4d
DC
34::: correct
35
eb39fafa
DC
36```js
37/*eslint no-with: "error"*/
38/*eslint-env es6*/
39
40const r = ({x, y}) => Math.sqrt(x * x + y * y);
41```
42
8f9d1d4d
DC
43:::
44
eb39fafa
DC
45## When Not To Use It
46
47If you intentionally use `with` statements then you can disable this rule.