eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Add `prefer-object-define-properties` rule

Open Slowlife01 opened this issue 2 years ago • 7 comments

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)

Slowlife01 avatar Jun 19 '22 07:06 Slowlife01

~Should I check if they are in the same scope?~ Updated

Slowlife01 avatar Jun 20 '22 02:06 Slowlife01

I tried to update the snapshot but it doesn't seems to work

Slowlife01 avatar Jun 20 '22 12:06 Slowlife01

Should I check if they are in the same scope?

Shouldn't they next to each other?

fisker avatar Jun 21 '22 21:06 fisker

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)

Slowlife01 avatar Jun 21 '22 23:06 Slowlife01

This is how I did in other rule https://github.com/sindresorhus/eslint-plugin-unicorn/blob/a7f600796d53d67553959d6d1aa8b0993abd2633/rules/no-array-push-push.js#L22

fisker avatar Jun 27 '22 07:06 fisker

Putting this on draft for now

Slowlife01 avatar Jun 29 '22 07:06 Slowlife01

@Slowlife01

I made some changes. I hope it's easier to understand the code.

Mainly changes:

  1. Instead of grouping calls. It only checks two sibling calls.
  2. Relax the node type check, not only Identifier/Literal for property
  3. Fix the fix logic for some untested node types. (eg, use ...descriptors)

This not done yet.

  1. Need more test for the stricter isObjectDefinePropertyOrObjectDefineProperties
  2. The "secondCallExpression" removal is not correct, it's tricky for ASI problem.

Maybe other isssues, I'll review again later.

fisker avatar Sep 17 '22 05:09 fisker

I won't be able to finish this now

Slowlife01 avatar Oct 11 '22 06:10 Slowlife01