1.1.4 • Published 2 years ago

eslint-plugin-tidesquare v1.1.4

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

eslint-plugin-tidesquare

Rules

1. no-direct-class-method-passing

This rule is to prevent losing this context while passing class method directly into functions parameter like below.

class Clock {
  constructor() {
    this.currentTime = '12:00 PM'
  }

  showTime() {
    console.log(this.currentTime)
  }
}

class Timer {
  constructor() {}

  afterDelay(callback, duration) {
    setTimeout(callback, duration)
  }
}

const myClock = new Clock()
const myTimer = new Timer()

// Passing the showTime method directly as a callback.
myTimer.afterDelay(myClock.showTime, 1000) // After 1 second, this logs: `undefined`.

2. no-direct-class-method-referencing

This rule is to prevent losing this context while referencing class method directly like below.

class CoffeeMachine {
  makeEspresso() {
    console.log('Making Espresso in:', 2 - this.discountTime, 'minutes.')
  }

  makeLatte() {
    console.log('Making Latte in:', 5 - this.discountTime, 'minutes.')
  }
}

class Barista {
  discountTime = 1 // Let's say the barista has a trick to make coffee 1 minute faster

  constructor(private readonly machine: CoffeeMachine) {}
  private readonly coffeeMakingTimeMap = {
    Espresso: this.machine.makeEspresso,
    Latte: this.machine.makeLatte,
  }
  orderCoffee(type: string) {
    this.coffeeMakingTimeMap[type]()
  }
}

const machine = new CoffeeMachine()
const john = new Barista(machine)
john.orderCoffee('Espresso') // Logs: "Making Espresso in: NaN minutes."
1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.17

2 years ago

1.0.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.1.4

2 years ago

1.0.5

2 years ago

1.1.3

2 years ago

1.0.4

2 years ago

1.1.2

2 years ago

1.0.3

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago