RightCapitalHQ / frontend-style-guide

RightCapital's frontend style guide.
MIT License
7 stars 0 forks source link

Add a rule to prevent simultaneously calling lodash `mapKeys()` and `mapValues()` #183

Open frantic1048 opened 2 months ago

frantic1048 commented 2 months ago

Example:

import { chain, mapKeys, mapValues } from 'lodash';

chain(input).mapKeys(...).mapValues(...).value();

mapValues(mapKeys(input, ...), ...);

The usage is not intuitive, and it is preferable to use Object.fromEntries() in this scenario. The similar case is .keyBy(...).mapValues(...)


const input = [
  { k: 'key1', v: 'value1' },
  { k: 'key2', v: 'value2' },
];

// this `mapKeys().mapValues()` call
chain(input).mapKeys('k').mapValues('v').value();

// equals
Object.fromEntries(input.map((item) => [item.k, item.v]));

// equals
{
  key1: 'value1',
  key2: 'value2',
}