Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/rules/no-assign-mutated-array.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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