]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/semi-spacing.js
2 * @fileoverview Tests for semi-spacing.
3 * @author Mathias Schreck
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/semi-spacing"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("semi-spacing", rule
, {
25 "var a = 'b',\nc = 'd';",
26 "var a = function() {};",
28 "var a = 'b'\n;(function(){}())",
29 "debugger\n;(function(){}())",
30 "while (true) { break; }",
31 "while (true) { continue; }",
33 "function foo() { return; }",
34 "throw new Error('foo');",
35 "for (var i = 0; i < 10; i++) {}",
38 code
: "var a = 'b' ;",
39 options
: [{ before
: true, after
: true }]
42 code
: "var a = 'b';c = 'd';",
43 options
: [{ before
: false, after
: false }]
46 code
: "for (var i = 0 ;i < 10 ;i++) {}",
47 options
: [{ before
: true, after
: false }]
50 code
: "for (var i = 0 ; i < 10 ; i++) {}",
51 options
: [{ before
: true, after
: true }]
54 // https://github.com/eslint/eslint/issues/3721
55 "function foo(){return 2;}",
56 "for(var i = 0; i < results.length;) {}",
57 { code
: "function foo() { return 2; }", options
: [{ after
: false }] },
58 { code
: "for ( var i = 0;i < results.length; ) {}", options
: [{ after
: false }] },
60 "do {} while (true); foo"
64 code
: "var a = 'b' ;",
65 output
: "var a = 'b';",
68 messageId
: "unexpectedWhitespaceBefore",
69 type
: "VariableDeclaration",
78 code
: "var a = 'b' ;",
79 output
: "var a = 'b';",
82 messageId
: "unexpectedWhitespaceBefore",
83 type
: "VariableDeclaration",
92 code
: "var a = 'b',\nc = 'd' ;",
93 output
: "var a = 'b',\nc = 'd';",
94 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "VariableDeclaration", line
: 2, column
: 8 }]
97 code
: "var a = function() {} ;",
98 output
: "var a = function() {};",
99 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "VariableDeclaration", line
: 1, column
: 22 }]
102 code
: "var a = function() {\n} ;",
103 output
: "var a = function() {\n};",
104 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "VariableDeclaration", line
: 2, column
: 2 }]
107 code
: "/^a$/.test('b') ;",
108 output
: "/^a$/.test('b');",
109 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "ExpressionStatement", line
: 1, column
: 16 }]
112 code
: ";(function(){}()) ;",
113 output
: ";(function(){}());",
114 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "ExpressionStatement", line
: 1, column
: 18 }]
117 code
: "while (true) { break ; }",
118 output
: "while (true) { break; }",
119 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "BreakStatement", line
: 1, column
: 21 }]
122 code
: "while (true) { continue ; }",
123 output
: "while (true) { continue; }",
124 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "ContinueStatement", line
: 1, column
: 24 }]
129 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "DebuggerStatement", line
: 1, column
: 9 }]
132 code
: "function foo() { return ; }",
133 output
: "function foo() { return; }",
134 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "ReturnStatement", line
: 1, column
: 24 }]
137 code
: "throw new Error('foo') ;",
138 output
: "throw new Error('foo');",
139 errors
: [{ messageId
: "unexpectedWhitespaceBefore", type
: "ThrowStatement", line
: 1, column
: 23 }]
142 code
: "for (var i = 0 ; i < 10 ; i++) {}",
143 output
: "for (var i = 0; i < 10; i++) {}",
145 { messageId
: "unexpectedWhitespaceBefore", type
: "ForStatement", line
: 1, column
: 15 },
146 { messageId
: "unexpectedWhitespaceBefore", type
: "ForStatement", line
: 1, column
: 24 }
150 code
: "var a = 'b';c = 'd';",
151 output
: "var a = 'b'; c = 'd';",
154 messageId
: "missingWhitespaceAfter",
155 type
: "VariableDeclaration",
164 code
: "var a = 'b';",
165 output
: "var a = 'b' ;",
166 options
: [{ before
: true, after
: true }],
169 messageId
: "missingWhitespaceBefore",
170 type
: "VariableDeclaration",
179 code
: "var a = 'b'; c = 'd';",
180 output
: "var a = 'b';c = 'd';",
181 options
: [{ before
: false, after
: false }],
184 messageId
: "unexpectedWhitespaceAfter",
185 type
: "VariableDeclaration",
194 code
: "var a = 'b'; c = 'd';",
195 output
: "var a = 'b';c = 'd';",
196 options
: [{ before
: false, after
: false }],
199 messageId
: "unexpectedWhitespaceAfter",
200 type
: "VariableDeclaration",
209 code
: "for (var i = 0;i < 10;i++) {}",
210 output
: "for (var i = 0; i < 10; i++) {}",
213 messageId
: "missingWhitespaceAfter",
214 type
: "ForStatement",
221 messageId
: "missingWhitespaceAfter",
222 type
: "ForStatement",
231 code
: "for (var i = 0; i < 10; i++) {}",
232 output
: "for (var i = 0 ; i < 10 ; i++) {}",
233 options
: [{ before
: true, after
: true }],
236 messageId
: "missingWhitespaceBefore",
237 type
: "ForStatement",
244 messageId
: "missingWhitespaceBefore",
245 type
: "ForStatement",
254 code
: "for (var i = 0; i < 10; i++) {}",
255 output
: "for (var i = 0;i < 10;i++) {}",
256 options
: [{ before
: false, after
: false }],
258 { messageId
: "unexpectedWhitespaceAfter", type
: "ForStatement", line
: 1, column
: 16 },
259 { messageId
: "unexpectedWhitespaceAfter", type
: "ForStatement", line
: 1, column
: 24 }
263 code
: "import Foo from 'bar' ;",
264 output
: "import Foo from 'bar';",
265 options
: [{ before
: false, after
: true }],
266 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
268 { messageId
: "unexpectedWhitespaceBefore", type
: "ImportDeclaration", line
: 1, column
: 22 }
272 code
: "import * as foo from 'bar' ;",
273 output
: "import * as foo from 'bar';",
274 options
: [{ before
: false, after
: true }],
275 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
277 { messageId
: "unexpectedWhitespaceBefore", type
: "ImportDeclaration", line
: 1, column
: 27 }
281 code
: "var foo = 0; export {foo} ;",
282 output
: "var foo = 0; export {foo};",
283 options
: [{ before
: false, after
: true }],
284 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
286 { messageId
: "unexpectedWhitespaceBefore", type
: "ExportNamedDeclaration", line
: 1, column
: 26 }
290 code
: "export * from 'foo' ;",
291 output
: "export * from 'foo';",
292 options
: [{ before
: false, after
: true }],
293 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
295 { messageId
: "unexpectedWhitespaceBefore", type
: "ExportAllDeclaration", line
: 1, column
: 20 }
299 code
: "export default foo ;",
300 output
: "export default foo;",
301 options
: [{ before
: false, after
: true }],
302 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
304 { messageId
: "unexpectedWhitespaceBefore", type
: "ExportDefaultDeclaration", line
: 1, column
: 19 }
308 code
: "while(foo) {continue ;}",
309 output
: "while(foo) {continue;}",
310 options
: [{ before
: false, after
: true }],
311 parserOptions
: { ecmaVersion
: 6 },
314 messageId
: "unexpectedWhitespaceBefore",
315 type
: "ContinueStatement",
324 code
: "if(foo) {throw new Error() ; }",
325 output
: "if(foo) {throw new Error(); }",
326 options
: [{ before
: false, after
: false }],
327 parserOptions
: { ecmaVersion
: 6 },
330 messageId
: "unexpectedWhitespaceBefore",
331 type
: "ThrowStatement",
340 code
: "for(a ; ; );",
341 output
: "for(a;; );",
342 options
: [{ before
: false, after
: false }],
343 parserOptions
: { ecmaVersion
: 6 },
345 type
: "ForStatement",
346 messageId
: "unexpectedWhitespaceBefore",
353 type
: "ForStatement",
354 messageId
: "unexpectedWhitespaceAfter",
362 code
: "for(a ; \n ; );",
363 output
: "for(a; \n ; );",
364 options
: [{ before
: false, after
: false }],
365 parserOptions
: { ecmaVersion
: 6 },
367 type
: "ForStatement",
368 messageId
: "unexpectedWhitespaceBefore",
377 code
: "do {} while (true) ;",
378 output
: "do {} while (true);",
380 messageId
: "unexpectedWhitespaceBefore",
381 type
: "DoWhileStatement",
389 code
: "do {} while (true);foo",
390 output
: "do {} while (true); foo",
392 messageId
: "missingWhitespaceAfter",
393 type
: "DoWhileStatement",
401 code
: "do {} while (true); foo",
402 output
: "do {} while (true) ;foo",
403 options
: [{ before
: true, after
: false }],
405 messageId
: "missingWhitespaceBefore",
406 type
: "DoWhileStatement",
413 messageId
: "unexpectedWhitespaceAfter",
414 type
: "DoWhileStatement",