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.

Proposing a "computed-property-as-needed" rule

See original GitHub issue

With ES6 Computed Properties, one can do the following:

let prop = 'b';
return {
  'a': 1,
  [prop]: 2,
  c: 3,
  ['d']: 4
}

Note how the brackets around the ['d'] property are superfluous. It could instead be written as 'd' or d.

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

If enabled, the following would trigger:

{
  ['x']: 1
}

Any property which does not need to be computed could trigger the rule.

Is this rule preventing an error or is it stylistic?

Stylistic

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

This rule affects basic ES6 syntax for situations where there are two equivalent ways to write the same code.

Are you willing to create the rule yourself?

I will attempt to if nobody else is interested.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, Mar 15, 2016

Or just no-useless-computed-property. That rule would be very similar to dot-notation rule.

1reaction
tlhuntercommented, Apr 22, 2016

Thanks, @BYK!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Pitch] Effectful Read-only Properties - Swift Forums
A read-only computed property is a computed property that only defines a get -ter, which can be mutating . Throughout the remainder of...
Read more >
Content of Computed property not picked up by the template ...
Now the problem is that the products property is seen as empty by the template. It's completely fine when I go to this...
Read more >
Computed Properties - Vue.js
Think of a computed property as declaratively describing how to derive a value based on other values - its only responsibility should be...
Read more >
swift language - Where to put private computed properties?
If a computed property is used to satisfy a conformance to a protocol, then I would put it in the extension that defines...
Read more >
Rule 4001. Relief from Automatic Stay; Prohibiting or ...
If the proposed credit agreement or form of order includes any of the ... (i) a grant of priority or a lien on...
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