]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/dot-location.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / dot-location.md
1 ---
2 title: dot-location
3 layout: doc
4 rule_type: layout
5 related_rules:
6 - newline-after-var
7 - dot-notation
8 ---
9
10
11
12 JavaScript allows you to place newlines before or after a dot in a member expression.
13
14 Consistency in placing a newline before or after the dot can greatly increase readability.
15
16 ```js
17 var a = universe.
18 galaxy;
19
20 var b = universe
21 .galaxy;
22 ```
23
24 ## Rule Details
25
26 This rule aims to enforce newline consistency in member expressions. This rule prevents the use of mixed newlines around the dot in a member expression.
27
28 ## Options
29
30 The rule takes one option, a string:
31
32 * If it is `"object"` (default), the dot in a member expression should be on the same line as the object portion.
33 * If it is `"property"`, the dot in a member expression should be on the same line as the property portion.
34
35 ### object
36
37 The default `"object"` option requires the dot to be on the same line as the object.
38
39 Examples of **incorrect** code for the default `"object"` option:
40
41 ::: incorrect
42
43 ```js
44 /*eslint dot-location: ["error", "object"]*/
45
46 var foo = object
47 .property;
48 ```
49
50 :::
51
52 Examples of **correct** code for the default `"object"` option:
53
54 ::: correct
55
56 ```js
57 /*eslint dot-location: ["error", "object"]*/
58
59 var foo = object.
60 property;
61
62 var bar = (
63 object
64 ).
65 property;
66
67 var baz = object.property;
68 ```
69
70 :::
71
72 ### property
73
74 The `"property"` option requires the dot to be on the same line as the property.
75
76 Examples of **incorrect** code for the `"property"` option:
77
78 ::: incorrect
79
80 ```js
81 /*eslint dot-location: ["error", "property"]*/
82
83 var foo = object.
84 property;
85 ```
86
87 :::
88
89 Examples of **correct** code for the `"property"` option:
90
91 ::: correct
92
93 ```js
94 /*eslint dot-location: ["error", "property"]*/
95
96 var foo = object
97 .property;
98 var bar = object.property;
99 ```
100
101 :::
102
103 ## When Not To Use It
104
105 You can turn this rule off if you are not concerned with the consistency of newlines before or after dots in member expressions.