Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-accessor-recursion - improve detection #119

Open
forivall opened this issue May 29, 2019 · 1 comment
Open

no-accessor-recursion - improve detection #119

forivall opened this issue May 29, 2019 · 1 comment

Comments

@forivall
Copy link

forivall commented May 29, 2019

In my code, i sometimes use the pattern

class CustomError extends Error {
  constructor(someBigObject: any) {
    super()
    this.object = someBigObject
  }
  get message(): string {
    const value = `Failed ${util.inspect(this.object)}`
    this.message = value
    return value
  }
  set message(value: string) {
    Object.defineProperty(this, 'message', {value, configurable: true, enumerable: true, writable: true})
  }
}

Ideally, this should pass, and only fail if there's a get/access in the set and a set/assignment in the get (or a get/access in the get or a set/assignment in the set, obviously)

@ajafff
Copy link
Owner

ajafff commented Jun 2, 2019

That seems reasonable to me.
I'm definitely onboard with the change to only show an error if the get accessor contains a read or the set accessor contains a write access of the property.

Though I'm not sure about displaying an error if the get accessor invokes the set accessor which in turn invokes the get accessor. Then we would probably also need to detect the get accessor invoking a method which invokes the get accessor (with an arbitrary amount of nesting). And then I probably need to solve the halting problem 😆


Implementation status: I already added the necessary code to distinguish read and write access to tsutils. Once I update that library I can also improve the detection of accessors with computed names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants