From 6e5b4ec5ea1c858688ca37a340353ee89cd51cc0 Mon Sep 17 00:00:00 2001 From: Anix Date: Fri, 3 Apr 2020 07:49:25 +0000 Subject: [PATCH] Chore: docs example for arrow function and tests (fixes #13135) --- docs/rules/no-return-assign.md | 8 ++++++++ tests/lib/rules/no-return-assign.js | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-return-assign.md b/docs/rules/no-return-assign.md index 781d5973a78..b82578d39c7 100644 --- a/docs/rules/no-return-assign.md +++ b/docs/rules/no-return-assign.md @@ -40,6 +40,10 @@ function doSomething() { function doSomething() { return foo += 2; } + +const foo = (a,b) => a = b + +const bar = (a, b, c) => (a = b, c == b) ``` Examples of **correct** code for the default `"except-parens"` option: @@ -58,6 +62,10 @@ function doSomething() { function doSomething() { return (foo = bar + 2); } + +const foo = (a, b) => (a = b) + +const bar = (a, b, c) => ((a = b), c == b) ``` ### always diff --git a/tests/lib/rules/no-return-assign.js b/tests/lib/rules/no-return-assign.js index e9d0c585edc..7233f08e317 100644 --- a/tests/lib/rules/no-return-assign.js +++ b/tests/lib/rules/no-return-assign.js @@ -52,7 +52,8 @@ ruleTester.run("no-return-assign", rule, { { code: "() => (result = a * b)", options: ["except-parens"] - } + }, + "const foo = (a,b,c) => ((a = b), c)" ], invalid: [ { @@ -79,7 +80,12 @@ ruleTester.run("no-return-assign", rule, { }, { code: "() => result = a * b", - errors: [{ messageId: "arrowAssignment", type: "ArrowFunctionExpression" }] + errors: [ + { + messageId: "arrowAssignment", + type: "ArrowFunctionExpression" + } + ] }, { code: "function x() { return result = a * b; };", @@ -95,6 +101,10 @@ ruleTester.run("no-return-assign", rule, { code: "function x() { return result || (result = a * b); };", options: ["always"], errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] + }, + { + code: '"const foo = (a,b,c) => (a = b, c)"', + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] } ] });