src/content/docs/linter/rules/use-flat-map.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/useFlatMap`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/prefer-array-flat-map`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat-map.md) - Same as [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/#map_flatten){
"linter": {
"rules": {
"complexity": {
"useFlatMap": "error"
}
}
}
}
Promotes the use of .flatMap() when map().flat() are used together.
const array = ["split", "the text", "into words"];
array.map(sentence => sentence.split(' ')).flat();
const array = ["split", "the text", "into words"];
array.map(sentence => sentence.split(' ')).flat(1);
const array = ["split", "the text", "into words"];
array.map(sentence => sentence.split(' ')).flat(2);