Skip to content

Commit

Permalink
Chore: docs example for arrow function and tests (fixes eslint#13135)
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Apr 3, 2020
1 parent 17e2fe4 commit 6e5b4ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/rules/no-return-assign.md
Expand Up @@ -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:
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions tests/lib/rules/no-return-assign.js
Expand Up @@ -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: [
{
Expand All @@ -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; };",
Expand All @@ -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" }]
}
]
});

0 comments on commit 6e5b4ec

Please sign in to comment.