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

New Rule: Enforce return in getter #8449

Closed
jaredmcateer opened this issue Apr 11, 2017 · 6 comments · Fixed by #8460 or homezen/eslint-config-homezen#43
Closed

New Rule: Enforce return in getter #8449

jaredmcateer opened this issue Apr 11, 2017 · 6 comments · Fixed by #8460 or homezen/eslint-config-homezen#43
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@jaredmcateer
Copy link

Please describe what the rule should do:

Enforces that a return statement is present in property getters

What category of rule is this? (place an "X" next to just one item)

[ ] Enforces code style
[X] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

/*eslint getter-return: "error"*/

// Incorrect
class MyClass {
  get a() {
     this.retreiveVal('a');
  }
}

function MyConstructorFunction() {
  Object.defineProperty(this, 'a', {
    get: function () {
      this.retreiveVal('a');
    }
  });
}


// Correct
class MyClass {
  get a() {
     return this.retreiveVal('a');
  }
}

function MyConstructorFunction() {
  Object.defineProperty(this, 'a', {
    get: function () {
       return this.retreiveVal('a');
    }
  });
}

Why should this rule be included in ESLint (instead of a plugin)?

I cannot think of a valid use case why someone would want to define a getter that did not return a value and it can be easily overlooked when reviewing a long list of getter/setters. I think the problem is generic enough that it should be included by ESLint.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Apr 11, 2017
@platinumazure platinumazure changed the title New Rule: No return in getter New Rule: Enforce return in getter Apr 11, 2017
@platinumazure platinumazure added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Apr 11, 2017
@platinumazure
Copy link
Member

I'm 👍 to this idea. I think we should for sure do this in getter methods. I'm less sure about Object.defineProperty and friends just due to static analysis limitations, but I'm not opposed to adding it there either.

@platinumazure
Copy link
Member

@jaredmcateer Would you be interested in writing a PR if this gets accepted?

@jaredmcateer
Copy link
Author

jaredmcateer commented Apr 18, 2017 via email

@ilyavolodin
Copy link
Member

Looks like we have enough votes to accept this. Just need a champion. Anyone willing to champion this issue?

@platinumazure platinumazure self-assigned this Apr 21, 2017
@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Apr 21, 2017
@platinumazure
Copy link
Member

I'll champion.

@jaredmcateer Let us know when you get a chance to start work on this, or if your schedule fills up and it looks like you won't be able to do it. No rush, and enjoy your travels!

@aladdin-add
Copy link
Member

working on this. maybe the following weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants