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.

Rule 3.6 (use property value shorthand) leads to refactoring errors

See original GitHub issue

Consider the following code…

const url = 'http://some-service.com/';
const data = { foo: 'bar' };
$.ajax({ url, data });

One day you decide that “apiUrl” is a better name so you rename the variable and end up with…

const apiUrl = 'http://some-service.com/';
const data = { foo: 'bar' };
$.ajax({ apiUrl, data });

And now you have an error. My example may seem a little contrived but it’s pretty common to have options parameters in javascript. At some point your variables names might happen to align with the option names, but it’s usually just a coincidence.

What is your opinion on this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
philippevkcommented, May 12, 2016

Anyway, it’s not a big deal as I can simply disable the rule for my project. I just wanted to let you know of the issue. Whether you support this use case is your decision!

0reactions
ljharbcommented, May 12, 2016

Personally I’d report it as a bug in the IDE’s auto-refactoring mechanism rather than disabling a useful rule 😃 but as always, you’re quite welcome to override whatever rules you wish!

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-config-walmart/styleguide.md at master - GitHub
ES6 object literal shorthand is more concise. 3.4 Use property value shorthand. eslint: object-shorthand. defined in: rules/eslint/es6.
Read more >
eslint object-shorthand error with variable passed in
This rule checks that object literal shorthand syntax is used, e.g {a, b} instead of {a: a, b: b} . The rule is...
Read more >
FAQ: Advanced Objects - Property Value Shorthand
This community-built FAQ covers the “Property Value Shorthand” exercise from the lesson “Advanced Objects”. Paths and Courses
Read more >
Real world advice for writing maintainable Go programs
3.6. Function vs methods; 3.7. Avoid named return values; 3.8. ... and s is often used as shorthand for parameters of type string...
Read more >
eser - npm
It's easier to tell which properties are using the shorthand. ... and not used anywhere in the code are most likely an error...
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