]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-whitespace-before-property.md
bump version to 8.41.0-3
[pve-eslint.git] / eslint / docs / src / rules / no-whitespace-before-property.md
1 ---
2 title: no-whitespace-before-property
3 rule_type: layout
4 ---
5
6
7
8 JavaScript allows whitespace between objects and their properties. However, inconsistent spacing can make code harder to read and can lead to errors.
9
10 ```js
11 foo. bar .baz . quz
12 ```
13
14 ## Rule Details
15
16 This rule disallows whitespace around the dot or before the opening bracket before properties of objects if they are on the same line. This rule allows whitespace when the object and property are on separate lines, as it is common to add newlines to longer chains of properties:
17
18 ```js
19 foo
20 .bar()
21 .baz()
22 .qux()
23 ```
24
25 Examples of **incorrect** code for this rule:
26
27 ::: incorrect
28
29 ```js
30 /*eslint no-whitespace-before-property: "error"*/
31
32 foo [bar]
33
34 foo. bar
35
36 foo .bar
37
38 foo. bar. baz
39
40 foo. bar()
41 .baz()
42
43 foo
44 .bar(). baz()
45 ```
46
47 :::
48
49 Examples of **correct** code for this rule:
50
51 ::: correct
52
53 ```js
54 /*eslint no-whitespace-before-property: "error"*/
55
56 foo.bar
57
58 foo[bar]
59
60 foo[ bar ]
61
62 foo.bar.baz
63
64 foo
65 .bar().baz()
66
67 foo
68 .bar()
69 .baz()
70
71 foo.
72 bar().
73 baz()
74 ```
75
76 :::
77
78 ## When Not To Use It
79
80 Turn this rule off if you do not care about allowing whitespace around the dot or before the opening bracket before properties of objects if they are on the same line.