Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(define-macros-order): add defineExposeLast option #2349

Merged

Conversation

waynzh
Copy link
Contributor

@waynzh waynzh commented Dec 10, 2023

will close #2235

I'll be thankful for any suggestions on these TODOs.

  • open to suggestions for a better option name…
  • should we include defineExpose within the order schema? There is a potential conflict in the options, like:
    { order: ['defineExpose', 'defineProps'], defineExposeLast: true }.
  • any other test cases should we add to verify the fixer?
  • update the docs.

@waynzh waynzh marked this pull request as draft December 10, 2023 13:11
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks really good to me! 🙂

I couldn't come up with a better option name. I shortly thought about extending it to an array (something like orderLast), but I'm not sure if that's worth the effort or if defineExpose is the only macro for which it makes sense to put it at the end.

tests/lib/rules/define-macros-order.js Outdated Show resolved Hide resolved
@waynzh
Copy link
Contributor Author

waynzh commented Dec 21, 2023

I shortly thought about extending it to an array (something like orderLast)

Introducing a new orderLast array property or placing defineExpose into the order schema might potentially lead to configuration conflicts, like { order: ['defineExpose', 'defineProps'], anotherPropertyMarksExposeLast }. I was at a loss as to how to deal with these conflicts, so I chose to add a new boolean property specifically for the 'defineExpose' macro.

if defineExpose is the only macro for which it makes sense to put it at the end

In my personal practice, yes.
If it makes sense, I'll go ahead and update the test case and docs ASAP🤖

@FloEdelmann
Copy link
Member

FloEdelmann commented Dec 21, 2023

Introducing a new orderLast array property […] might potentially lead to configuration conflicts

If we'd introduce that orderLast option, we should validate the options so that a property can only be specified in either order or orderLast, so that wouldn't be a problem.

But if defineExpose is the only macro for which it makes sense to put it at the end anyway, I think defineExposeLast is fine.

@waynzh
Copy link
Contributor Author

waynzh commented Dec 21, 2023

Putting defineExpose or other macros at the front can be understood as it aids in better understanding the current component. But if it's mandatory to place it at the end, it feels like only defineExpose is reasonable.

we should validate the options

Just curious, are there similar references that need to be restricted in the options? I'm not sure whether to enforce this in the JSON schema or to trigger an error in the code logic.🤔

@FloEdelmann
Copy link
Member

are there similar references that need to be restricted in the options?

It's not possible in JSON schema. And it looks like we don't already do the same in another rule. But we could either throw an error, or just ignore values in orderLast that are already part of order.

@waynzh waynzh marked this pull request as ready for review December 21, 2023 15:19
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 🙂

loc: node.loc,
messageId: 'defineExposeNotTheLast',
fix(fixer) {
return moveNodeToLast(fixer, node, lastNode)
Copy link
Member

@ota-meshi ota-meshi Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that probably shouldn't support auto-fix. It may break user's code.

<script setup>
let a = 1
defineExpose({a})
a = 2
</script>

What do you think about supporting suggestions instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response. It seems reasonable to me not to support auto-fix, thanks for pointing out!
I'll add to suggestion and refine the test cases.

@waynzh waynzh force-pushed the feature/define-macros-order-add-option branch from 5fc8bed to 3c704bb Compare January 7, 2024 16:15
@waynzh waynzh requested a review from ota-meshi January 7, 2024 16:31
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi ota-meshi merged commit e2f8b70 into vuejs:master Jan 8, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force defineExpose at the end of <script>
3 participants