question-mark
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.

New rule proposal: compact-accessor

See original GitHub issue

Please describe what the rule should do:

If an accessor property has both getter and setter functions, this rule requires their definitions to be one after another in object literals/class definitions.

Optionally, the rule can require their order (get before set, or set before get).

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

[X] Enforces code style (layout)

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

/* eslint compact-accessor:error*/
var foo = {
    get a(){},
    bar: 5,
    set a(val){}
};

var foo = {
    get a(){},
    ...bar,
    set a(val){}
}

class foo {
    get a(){}
    bar(){}
    set a(val){}
}
/* eslint compact-accessor:["error", "getBeforeSet"]*/
var foo = {
    set a(val){},
    get a(){}
}

class foo {
    set a(val){}
    get a(){}
}

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

While it is allowed, I don’t think there is a real use case for non-consecutive definitions of accessor functions for the same property, and it should be a best practice to avoid this feature. Also, the additional option can enforce a consistent style (e.g., get before set).

I’m not sure about the rule’s name, there could be a better word than compact for this.

Notes:

  • The rule does not enforce the existence of the pair for a getter/setter (that’s accessor-pairs).
  • The rule does not require grouping of all accessor properties at the same place, it works with each individually.
  • If a property has a duplicate getter or setter, such property will be ignored by this rule and caught by other rules (no-dupe-keys and no-dupe-class-members)

Problem: This rule is overlapping with sort-keys. But, one might want to enforce this without sorting. Also, sort-keys doesn’t work with classes and doesn’t enforce get/set order.

Are you willing to submit a pull request to implement this rule?

Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Sep 25, 2019

grouped-accessor-pairs?

1reaction
mdjermanoviccommented, Sep 25, 2019

I’ll work on this over the weekend, should be ready for review soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments Due: March 31, 2023,...
Read more >
Enhanced Disclosures by Certain Investment Advisers and ...
Proposed rule. SUMMARY: The Securities and Exchange Commission (“Commission”) is proposing to amend rules and forms under both the Investment ...
Read more >
Proposed Rules - GovInfo
The proposed rule would rescind certain regulatory changes made effective on November. 16, 2020 and implements new statutory.
Read more >
SEC Proposes Amendments to the Shareholder Proposal Rules
The SEC proposed modifying certain bases for excluding shareholder proposals from company proxy statements. If adopted, these amendments are ...
Read more >
SEC Proposes Revisions to Shareholder Proposal Rules
The Securities and Exchange Commission (SEC) last month proposed revisions to Rule 14a-8 under the Securities Exchange Act of 1934, ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found