Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-assign-mutated-array Allow mutation of an array after flat and flatMap #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/rules/no-assign-mutated-array.ts
Expand Up @@ -17,7 +17,8 @@ import {
import { ruleCreator } from "../utils";

const mutatorRegExp = /^(fill|reverse|sort)$/;
const creatorRegExp = /^(concat|entries|filter|keys|map|slice|splice|values)$/;
const creatorRegExp =
/^(concat|entries|filter|keys|map|slice|splice|values|flat|flatMap)$/;

const rule = ruleCreator({
defaultOptions: [],
Expand Down
18 changes: 18 additions & 0 deletions tests/rules/no-assign-mutated-array.ts
Expand Up @@ -144,6 +144,24 @@ ruleTester({ types: true }).run("no-assign-mutated-array", rule, {
);
`,
},
{
code: stripIndent`
// flat & mutated variable assignment
const a = [[0, 1], [2, 3]];
const b = a.flat().fill(0);
const c = a.flat().reverse();
const d = a.flat().sort();
`,
},
{
code: stripIndent`
// flatMap & mutated variable assignment
const a = [[0, 1], [2, 3]];
const b = a.flatMap(e => e).fill(0);
const c = a.flatMap(e => e).reverse();
const d = a.flatMap(e => e).sort();
`,
},
{
code: stripIndent`
// https://github.com/cartant/eslint-plugin-etc/issues/27
Expand Down