aliyome / eslint-force-equals-method

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-force-equals-method

This ESLint plugin is created for learning purposes. It prohibits the use of ==, !=, === and !== operator in the comparison of immutable value objects and enforces the use of the equals method.

class ValueObject {
  constructor(private readonly value: string) {}
  equals(other: ValueObject) {
    return this.value === other.value;
  }
}

const vo1 = new ValueObject('foo');
const vo2 = new ValueObject('foo');

// OK
vo1.equals(vo2);

// NG
vo1 === vo2;
vo1 !== vo2;
vo1 == vo2;
vo1 != vo2;

image

About


Languages

Language:TypeScript 58.0%Language:JavaScript 42.0%