]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/dot-location.js
1a6ea37a733ca2117d55c7eec7ad84418359ab96
[pve-eslint.git] / eslint / tests / lib / rules / dot-location.js
1 /**
2 * @fileoverview Tests for dot-location.
3 * @author Greg Cochard
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/dot-location"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("dot-location", rule, {
22 valid: [
23 "obj.\nprop",
24 "obj. \nprop",
25 "obj.\n prop",
26 "(obj).\nprop",
27 "obj\n['prop']",
28 "obj['prop']",
29 {
30 code: "obj.\nprop",
31 options: ["object"]
32 },
33 {
34 code: "obj\n.prop",
35 options: ["property"]
36 },
37 {
38 code: "(obj)\n.prop",
39 options: ["property"]
40 },
41 {
42 code: "obj . prop",
43 options: ["object"]
44 },
45 {
46 code: "obj /* a */ . prop",
47 options: ["object"]
48 },
49 {
50 code: "obj . \nprop",
51 options: ["object"]
52 },
53 {
54 code: "obj . prop",
55 options: ["property"]
56 },
57 {
58 code: "obj . /* a */ prop",
59 options: ["property"]
60 },
61 {
62 code: "obj\n. prop",
63 options: ["property"]
64 },
65 {
66 code: "f(a\n).prop",
67 options: ["object"]
68 },
69 {
70 code: "`\n`.prop",
71 options: ["object"],
72 parserOptions: { ecmaVersion: 6 }
73 },
74 {
75 code: "obj[prop]",
76 options: ["object"]
77 },
78 {
79 code: "obj\n[prop]",
80 options: ["object"]
81 },
82 {
83 code: "obj[\nprop]",
84 options: ["object"]
85 },
86 {
87 code: "obj\n[\nprop\n]",
88 options: ["object"]
89 },
90 {
91 code: "obj[prop]",
92 options: ["property"]
93 },
94 {
95 code: "obj\n[prop]",
96 options: ["property"]
97 },
98 {
99 code: "obj[\nprop]",
100 options: ["property"]
101 },
102 {
103 code: "obj\n[\nprop\n]",
104 options: ["property"]
105 },
106
107 // https://github.com/eslint/eslint/issues/11868 (also in invalid)
108 {
109 code: "(obj).prop",
110 options: ["object"]
111 },
112 {
113 code: "(obj).\nprop",
114 options: ["object"]
115 },
116 {
117 code: "(obj\n).\nprop",
118 options: ["object"]
119 },
120 {
121 code: "(\nobj\n).\nprop",
122 options: ["object"]
123 },
124 {
125 code: "((obj\n)).\nprop",
126 options: ["object"]
127 },
128 {
129 code: "(f(a)\n).\nprop",
130 options: ["object"]
131 },
132 {
133 code: "((obj\n)\n).\nprop",
134 options: ["object"]
135 },
136 {
137 code: "(\na &&\nb()\n).toString()",
138 options: ["object"]
139 }
140 ],
141 invalid: [
142 {
143 code: "obj\n.property",
144 output: "obj.\nproperty",
145 options: ["object"],
146 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1, endLine: 2, endColumn: 2 }]
147 },
148 {
149 code: "obj.\nproperty",
150 output: "obj\n.property",
151 options: ["property"],
152 errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 4, endLine: 1, endColumn: 5 }]
153 },
154 {
155 code: "(obj).\nproperty",
156 output: "(obj)\n.property",
157 options: ["property"],
158 errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 6 }]
159 },
160 {
161 code: "5\n.toExponential()",
162 output: "5 .\ntoExponential()",
163 options: ["object"],
164 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }]
165 },
166 {
167 code: "-5\n.toExponential()",
168 output: "-5 .\ntoExponential()",
169 options: ["object"],
170 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }]
171 },
172 {
173 code: "foo /* a */ . /* b */ \n /* c */ bar",
174 output: "foo /* a */ /* b */ \n /* c */ .bar",
175 options: ["property"],
176 errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 13 }]
177 },
178 {
179 code: "foo /* a */ \n /* b */ . /* c */ bar",
180 output: "foo. /* a */ \n /* b */ /* c */ bar",
181 options: ["object"],
182 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 10 }]
183 },
184 {
185 code: "f(a\n)\n.prop",
186 output: "f(a\n).\nprop",
187 options: ["object"],
188 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
189 },
190 {
191 code: "`\n`\n.prop",
192 output: "`\n`.\nprop",
193 options: ["object"],
194 parserOptions: { ecmaVersion: 6 },
195 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
196 },
197
198 // https://github.com/eslint/eslint/issues/11868 (also in valid)
199 {
200 code: "(a\n)\n.prop",
201 output: "(a\n).\nprop",
202 options: ["object"],
203 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
204 },
205 {
206 code: "(a\n)\n.\nprop",
207 output: "(a\n).\n\nprop",
208 options: ["object"],
209 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
210 },
211 {
212 code: "(f(a)\n)\n.prop",
213 output: "(f(a)\n).\nprop",
214 options: ["object"],
215 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
216 },
217 {
218 code: "(f(a\n)\n)\n.prop",
219 output: "(f(a\n)\n).\nprop",
220 options: ["object"],
221 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 4, column: 1 }]
222 },
223 {
224 code: "((obj\n))\n.prop",
225 output: "((obj\n)).\nprop",
226 options: ["object"],
227 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
228 },
229 {
230 code: "((obj\n)\n)\n.prop",
231 output: "((obj\n)\n).\nprop",
232 options: ["object"],
233 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 4, column: 1 }]
234 },
235 {
236 code: "(a\n) /* a */ \n.prop",
237 output: "(a\n). /* a */ \nprop",
238 options: ["object"],
239 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }]
240 },
241 {
242 code: "(a\n)\n/* a */\n.prop",
243 output: "(a\n).\n/* a */\nprop",
244 options: ["object"],
245 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 4, column: 1 }]
246 },
247 {
248 code: "(a\n)\n/* a */.prop",
249 output: "(a\n).\n/* a */prop",
250 options: ["object"],
251 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 8 }]
252 },
253 {
254 code: "(5)\n.toExponential()",
255 output: "(5).\ntoExponential()",
256 options: ["object"],
257 errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }]
258 }
259 ]
260 });