Rule 3.6 (use property value shorthand) leads to refactoring errors
See original GitHub issueConsider 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:
- Created 7 years ago
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
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!