eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Add `prefer-object-define-properties` rule
Added prefer-object-define-properties
rule, resolves #1729
Might need more test cases and better description And unsure if fixer can be improved (formatting the output etc)
~Should I check if they are in the same scope?~ Updated
I tried to update the snapshot but it doesn't seems to work
Should I check if they are in the same scope?
Shouldn't they next to each other?
Should I check if they are in the same scope?
Shouldn't they next to each other?
Oh right. How should I check this? Just the ranges? Or if there is something in between them? (although I don't know if that's hard)
This is how I did in other rule https://github.com/sindresorhus/eslint-plugin-unicorn/blob/a7f600796d53d67553959d6d1aa8b0993abd2633/rules/no-array-push-push.js#L22
Putting this on draft for now
@Slowlife01
I made some changes. I hope it's easier to understand the code.
Mainly changes:
- Instead of grouping calls. It only checks two sibling calls.
- Relax the node type check, not only Identifier/Literal for property
- Fix the fix logic for some untested node types. (eg, use
...descriptors
)
This not done yet.
- Need more test for the stricter
isObjectDefinePropertyOrObjectDefineProperties
- The "secondCallExpression" removal is not correct, it's tricky for ASI problem.
Maybe other isssues, I'll review again later.
I won't be able to finish this now