]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-whitespace-before-property.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-whitespace-before-property.md
1 ---
2 title: no-whitespace-before-property
3 layout: doc
4 rule_type: layout
5 ---
6
7
8
9 JavaScript allows whitespace between objects and their properties. However, inconsistent spacing can make code harder to read and can lead to errors.
10
11 ```js
12 foo. bar .baz . quz
13 ```
14
15 ## Rule Details
16
17 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:
18
19 ```js
20 foo
21 .bar()
22 .baz()
23 .qux()
24 ```
25
26 Examples of **incorrect** code for this rule:
27
28 ::: incorrect
29
30 ```js
31 /*eslint no-whitespace-before-property: "error"*/
32
33 foo [bar]
34
35 foo. bar
36
37 foo .bar
38
39 foo. bar. baz
40
41 foo. bar()
42 .baz()
43
44 foo
45 .bar(). baz()
46 ```
47
48 :::
49
50 Examples of **correct** code for this rule:
51
52 ::: correct
53
54 ```js
55 /*eslint no-whitespace-before-property: "error"*/
56
57 foo.bar
58
59 foo[bar]
60
61 foo[ bar ]
62
63 foo.bar.baz
64
65 foo
66 .bar().baz()
67
68 foo
69 .bar()
70 .baz()
71
72 foo.
73 bar().
74 baz()
75 ```
76
77 :::
78
79 ## When Not To Use It
80
81 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.