X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=eslint%2Ftests%2Flib%2Frules%2Ffunc-call-spacing.js;h=3520882b019659a5da2b034ddfe7a067881f3000;hb=6f036462704d9ce418f40ac7bd6ee34d916fa3b5;hp=f0199fd0a4e019a39a5319589f9fdfd63648c199;hpb=a4a2572412fc0fce7ee3862a533144d797a86f44;p=pve-eslint.git diff --git a/eslint/tests/lib/rules/func-call-spacing.js b/eslint/tests/lib/rules/func-call-spacing.js index f0199fd..3520882 100644 --- a/eslint/tests/lib/rules/func-call-spacing.js +++ b/eslint/tests/lib/rules/func-call-spacing.js @@ -218,6 +218,28 @@ ruleTester.run("func-call-spacing", rule, { code: "import\n(source)", options: ["always", { allowNewlines: true }], parserOptions: { ecmaVersion: 2020 } + }, + + // Optional chaining + { + code: "func?.()", + options: ["never"], + parserOptions: { ecmaVersion: 2020 } + }, + { + code: "func ?.()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 } + }, + { + code: "func?. ()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 } + }, + { + code: "func ?. ()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 } } ], invalid: [ @@ -560,7 +582,7 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f\n();", - output: "f ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, @@ -572,7 +594,7 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f\n(a, b);", - output: "f (a, b);", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, @@ -593,7 +615,7 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f.b\n();", - output: "f.b ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [ { @@ -614,7 +636,7 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f.b\n().c ();", - output: "f.b ().c ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [ { @@ -635,13 +657,13 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f\n() ()", - output: "f () ()", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, { code: "f\n()()", - output: "f () ()", + output: "f\n() ()", // Don't fix the first error to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [ { messageId: "unexpectedNewline", type: "CallExpression" }, @@ -696,25 +718,25 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "f\r();", - output: "f ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, { code: "f\u2028();", - output: "f ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, { code: "f\u2029();", - output: "f ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, { code: "f\r\n();", - output: "f ();", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }] }, @@ -841,7 +863,7 @@ ruleTester.run("func-call-spacing", rule, { }, { code: "fnn\n (a, b);", - output: "fnn (a, b);", + output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787) options: ["always"], errors: [ { @@ -853,6 +875,96 @@ ruleTester.run("func-call-spacing", rule, { endColumn: 2 } ] + }, + { + code: "f /*comment*/ ()", + output: null, // Don't remove comments + options: ["never"], + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "f /*\n*/ ()", + output: null, // Don't remove comments + options: ["never"], + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "f/*comment*/()", + output: "f/*comment*/ ()", + options: ["always"], + errors: [{ messageId: "missing" }] + }, + + // Optional chaining + { + code: "func ?.()", + output: "func?.()", + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "func?. ()", + output: "func?.()", + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "func ?. ()", + output: "func?.()", + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "func\n?.()", + output: "func?.()", + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "func\n//comment\n?.()", + output: null, // Don't remove comments + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] + }, + { + code: "func?.()", + output: null, // Not sure inserting a space into either before/after `?.`. + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "missing" }] + }, + { + code: "func\n ?.()", + output: "func ?.()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] + }, + { + code: "func?.\n ()", + output: "func?. ()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] + }, + { + code: "func ?.\n ()", + output: "func ?. ()", + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] + }, + { + code: "func\n /*comment*/ ?.()", + output: null, // Don't remove comments + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] } ] });