TristonJ / eslint-plugin-prefer-arrow

ESLint plugin to prefer arrow functions
MIT License
55 stars 10 forks source link

Detect getters and setters #13

Closed fabiospampinato closed 5 years ago

fabiospampinato commented 5 years ago

This rule is telling me I have to write my getters as arrow functions, which is impossible.

TristonJ commented 5 years ago

Hi, would you mind posting an example code snippet? These are the existing tests for getters/setters that are passing: const foo = { get bar() { return "test"; } } const foo = { set bar(xyz) {} } class foo { get bar() { return "test"; } } class foo { set bar(xyz) { } }

fabiospampinato commented 5 years ago

@TristonJ You're right it is actually detecting some getters/setters, but not this one:

  Object.defineProperty ( window, 'foo', {
    get () {
      return 123;
    }
  });
TristonJ commented 5 years ago

Thank you for the additional details @fabiospampinato. It looks to me like it is correctly reporting an error in that specific case. In your snippet, we are actually defining a property called get on an object that is passed into Object.defineProperty. You can re-write that snippet of code as:

Object.defineProperty ( window, 'foo', {
    get: () => 123
});

which is entirely valid syntax.

fabiospampinato commented 5 years ago

Oh you're right! 🤦‍♂ Thanks!