:satellite: Today I Found

eslint-plugin-functional, an ESLint plugin to promote functional programming

programming ESLint eslint JavaScript javascript TypeScript typescript functional

eslint-plugin-functional is an ESLint plugin to disable mutation and promote functional programming in JavaScript.

This can be very useful in projects using React, Redux or similar libraries, which require or at least recommend using immutable data.

Enforcing immutability

For example, the immutable-data rule forbids you to mutate objects and arrays:

const obj = { foo: 'bar' };
// Modifying an existing object/array is not allowed!
obj.bar = 'baz';

Forcing you to create a new derived object:

const obj = { foo: 'bar' };
const obj2 = { ...obj, bar: 'baz' };

Preferring read-only types

If you’re using TypeScript, you can use the prefer-readonly-type rule to enforce declaring interface/type properties as read-only. The following would be invalid with this rule:

interface Point {
  x: number;
  y: number;

While this would be valid:

interface Point {
  readonly x: number;
  readonly y: number;