Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Differentiate between named functions and getter/setter functions.

See original GitHub issue

This is not a new rule, but an extension of the core space-before-function-paren rule. I am filing this as part of my research efforts to answer a stackoverflow question I made today.

When does this rule warn? Please describe and show example code:

This rule adds a third parameter to space-before-function-paren to allow for custom spacing for getter/setter functions.

"space-before-function-paren": [2, {
    "anonymous": "always",
    "named": "always",
    "getterSetter": "never"

This allows for code like this to stop throwing errors when using "always" for "named" functions.

var myObject = {
    get myProperty() { return 'foo'; }

This aligns getter definitions with what mdn recommends in their example.

Is this rule preventing an error or is it stylistic?


Why is this rule a candidate for inclusion instead of creating a custom rule?

This rule seeks to extend an existing ruleset. It makes sense to include it as an option in an already well-known ruleset, instead of isolating it in its own rule.

Are you willing to create the rule yourself?

If you’re ok with me altering a core rule. I see that get and set are already tracked under parent.kind when evaluating named functions explicitly. This means that the interpretation of how getter and setters are defined will need to be decoupled from named functions. If I’m able to make a clean break at the definition of what a named function is, it should be as simple as wrapping an if statement around that area of the code.

If I’m unable to make a breaking change that way, I may still be able to support some kind of a legacy definition of named functions as including getters/setters, and then over-ride that definition to include a finer grained definition if and only if they include the third option explicitly. However, just writing all that out made me cringe. I imagine it would look and feel much worse when implemented. Exposing variable definitions of core concepts of the ESLint parser sounds like a terrible precedent to set.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

kaicataldocommented, Aug 25, 2016

Closing this because we haven’t made any progress in months. Thanks for contributing!

nzakascommented, Mar 9, 2016

If this is separating out accessors from named functions, it’s a breaking change, so we need to be very certain that this is what we want.

Also, if we do want this, should we also have an option for concise methods?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between getter/setter methods and ...
The method that is used to set/modify the value of a private instance variable of a class is known as a setter method...
Read more >
What is the difference between using a getter method ... - Quora
A get method is used to make data available as a property on an object even though it is processed by a function....
Read more >
How getter and setter are different from normal functions?
Getters and setters are simply an object oriented convention. A lot of frameworks will look for methods called "getX()" and "setX(type)".
Read more >
Why use Getters and Setters functions | Zell Liew
When you use Getter and Setters, it becomes easier to see whether that line of code is GETTING a value, CHANGING a value,...
Read more >
Getter and Setter in Java - GeeksforGeeks
Getter and Setter are methods used to protect your data and make your code more secure. Getter returns the value (accessors), it returns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found