]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/space-infix-ops.js
2 * @fileoverview Require spaces around infix operators
3 * @author Michael Ficarra
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/space-infix-ops"),
13 { RuleTester
} = require("../../../lib/rule-tester"),
14 parser
= require("../../fixtures/fixture-parser");
16 const ruleTester
= new RuleTester();
18 ruleTester
.run("space-infix-ops", rule
, {
36 { code
: "const my_object = {key: 'value'};", parserOptions
: { ecmaVersion
: 6 } },
37 { code
: "var {a = 0} = bar;", parserOptions
: { ecmaVersion
: 6 } },
38 { code
: "function foo(a = 0) { }", parserOptions
: { ecmaVersion
: 6 } },
39 { code
: "a ** b", parserOptions
: { ecmaVersion
: 7 } },
40 { code
: "a|0", options
: [{ int32Hint
: true }] },
41 { code
: "a |0", options
: [{ int32Hint
: true }] },
44 { code
: "function foo(a: number = 0) { }", parser
: parser("type-annotations/function-parameter-type-annotation"), parserOptions
: { ecmaVersion
: 6 } },
45 { code
: "function foo(): Bar { }", parser
: parser("type-annotations/function-return-type-annotation"), parserOptions
: { ecmaVersion
: 6 } },
46 { code
: "var foo: Bar = '';", parser
: parser("type-annotations/variable-declaration-init-type-annotation"), parserOptions
: { ecmaVersion
: 6 } },
47 { code
: "const foo = function(a: number = 0): Bar { };", parser
: parser("type-annotations/function-expression-type-annotation"), parserOptions
: { ecmaVersion
: 6 } },
49 // TypeScript Type Aliases
50 { code
: "type Foo<T> = T;", parser
: parser("typescript-parsers/type-alias"), parserOptions
: { ecmaVersion
: 6 } },
52 { code
: "a &&= b", parserOptions
: { ecmaVersion
: 2021 } },
53 { code
: "a ||= b", parserOptions
: { ecmaVersion
: 2021 } },
54 { code
: "a ??= b", parserOptions
: { ecmaVersion
: 2021 } }
61 messageId
: "missingSpace",
62 data
: { operator
: "+" },
63 type
: "BinaryExpression",
73 messageId
: "missingSpace",
74 data
: { operator
: "+" },
75 type
: "BinaryExpression",
85 messageId
: "missingSpace",
86 data
: { operator
: "+" },
87 type
: "BinaryExpression",
97 messageId
: "missingSpace",
98 data
: { operator
: "||" },
99 type
: "LogicalExpression",
109 messageId
: "missingSpace",
110 data
: { operator
: "||" },
111 type
: "LogicalExpression",
121 messageId
: "missingSpace",
122 data
: { operator
: "||" },
123 type
: "LogicalExpression",
133 messageId
: "missingSpace",
134 data
: { operator
: "=" },
135 type
: "AssignmentExpression",
144 messageId
: "missingSpace",
145 data
: { operator
: "=" },
146 type
: "AssignmentExpression",
155 messageId
: "missingSpace",
156 data
: { operator
: "=" },
157 type
: "AssignmentExpression",
166 messageId
: "missingSpace",
167 data
: { operator
: "?" },
168 type
: "ConditionalExpression",
178 messageId
: "missingSpace",
179 data
: { operator
: "?" },
180 type
: "ConditionalExpression",
190 messageId
: "missingSpace",
191 data
: { operator
: ":" },
192 type
: "ConditionalExpression",
202 messageId
: "missingSpace",
203 data
: { operator
: "?" },
204 type
: "ConditionalExpression",
214 messageId
: "missingSpace",
215 data
: { operator
: "?" },
216 type
: "ConditionalExpression",
226 messageId
: "missingSpace",
227 data
: { operator
: ":" },
228 type
: "ConditionalExpression",
238 messageId
: "missingSpace",
239 data
: { operator
: ":" },
240 type
: "ConditionalExpression",
248 output
: "var a = b;",
250 messageId
: "missingSpace",
251 data
: { operator
: "=" },
252 type
: "VariableDeclarator",
259 output
: "var a = b;",
261 messageId
: "missingSpace",
262 data
: { operator
: "=" },
263 type
: "VariableDeclarator",
270 output
: "var a = b;",
272 messageId
: "missingSpace",
273 data
: { operator
: "=" },
274 type
: "VariableDeclarator",
280 code
: "var a = b, c=d;",
281 output
: "var a = b, c = d;",
283 messageId
: "missingSpace",
284 data
: { operator
: "=" },
285 type
: "VariableDeclarator",
297 messageId
: "missingSpace",
298 data
: { operator
: "|" },
299 type
: "BinaryExpression",
305 code
: "var output = test || (test && test.value) ||(test2 && test2.value);",
306 output
: "var output = test || (test && test.value) || (test2 && test2.value);",
308 messageId
: "missingSpace",
309 data
: { operator
: "||" },
310 type
: "LogicalExpression",
316 code
: "var output = a ||(b && c.value) || (d && e.value);",
317 output
: "var output = a || (b && c.value) || (d && e.value);",
319 messageId
: "missingSpace",
320 data
: { operator
: "||" },
321 type
: "LogicalExpression",
327 code
: "var output = a|| (b && c.value) || (d && e.value);",
328 output
: "var output = a || (b && c.value) || (d && e.value);",
330 messageId
: "missingSpace",
331 data
: { operator
: "||" },
332 type
: "LogicalExpression",
338 code
: "const my_object={key: 'value'}",
339 output
: "const my_object = {key: 'value'}",
340 parserOptions
: { ecmaVersion
: 6 },
342 messageId
: "missingSpace",
343 data
: { operator
: "=" },
344 type
: "VariableDeclarator",
350 code
: "var {a=0}=bar;",
351 output
: "var {a = 0} = bar;",
352 parserOptions
: { ecmaVersion
: 6 },
354 messageId
: "missingSpace",
355 data
: { operator
: "=" },
358 type
: "AssignmentPattern"
360 messageId
: "missingSpace",
361 data
: { operator
: "=" },
364 type
: "VariableDeclarator"
368 code
: "function foo(a=0) { }",
369 output
: "function foo(a = 0) { }",
370 parserOptions
: { ecmaVersion
: 6 },
372 messageId
: "missingSpace",
373 data
: { operator
: "=" },
376 type
: "AssignmentPattern"
382 parserOptions
: { ecmaVersion
: 7 },
384 messageId
: "missingSpace",
385 data
: { operator
: "**" },
388 type
: "BinaryExpression"
393 output
: "'foo' in {}",
395 messageId
: "missingSpace",
396 data
: { operator
: "in" },
399 type
: "BinaryExpression"
403 code
: "'foo'instanceof{}",
404 output
: "'foo' instanceof {}",
406 messageId
: "missingSpace",
407 data
: { operator
: "instanceof" },
410 type
: "BinaryExpression"
416 code
: "var a: Foo= b;",
417 output
: "var a: Foo = b;",
418 parser
: parser("type-annotations/variable-declaration-init-type-annotation-no-space"),
420 messageId
: "missingSpace",
421 data
: { operator
: "=" },
422 type
: "VariableDeclarator",
428 code
: "function foo(a: number=0): Foo { }",
429 output
: "function foo(a: number = 0): Foo { }",
430 parser
: parser("type-annotations/function-declaration-type-annotation-no-space"),
431 parserOptions
: { ecmaVersion
: 6 },
433 messageId
: "missingSpace",
434 data
: { operator
: "=" },
437 type
: "AssignmentPattern"
444 parserOptions
: { ecmaVersion
: 2021 },
446 messageId
: "missingSpace",
447 data
: { operator
: "&&=" },
452 type
: "AssignmentExpression"
458 parserOptions
: { ecmaVersion
: 2021 },
460 messageId
: "missingSpace",
461 data
: { operator
: "||=" },
466 type
: "AssignmentExpression"
472 parserOptions
: { ecmaVersion
: 2021 },
474 messageId
: "missingSpace",
475 data
: { operator
: "??=" },
480 type
: "AssignmentExpression"