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

Always move component documentation comment to the top #137

Closed
dummdidumm opened this issue Sep 8, 2020 · 6 comments · Fixed by #140
Closed

Always move component documentation comment to the top #137

dummdidumm opened this issue Sep 8, 2020 · 6 comments · Fixed by #140
Labels
enhancement New feature or request

Comments

@dummdidumm
Copy link
Member

You can create documentation for a Svelte component like this. I think it makes sense to always have this at the top of the file.

Current result when using scripts-markup-style:

<script>
  export let name = 'world';
</script>

<!--
@component
Here's some documentation for this component.
It will show up on hover.
-->
<h1>Hello, {name}</h1>

<style>
   h1 {
     color: blue;
   }
</style>

Desired result:

<!--
@component
Here's some documentation for this component.
It will show up on hover.
-->

<script>
  export let name = 'world';
</script>

<h1>Hello, {name}</h1>

<style>
   h1 {
     color: blue;
   }
</style>

This would be a breaking change.

Thoughts?

@dummdidumm dummdidumm added the enhancement New feature or request label Sep 8, 2020
@benmccann
Copy link
Member

I think I like this change though I've never used this component documentation, so take that with a grain of salt. We should probably update the faq question you linked to if this change is made to use the same style.

@ehrencrona
Copy link
Contributor

ehrencrona commented Sep 8, 2020

I would support this, but only for comments that actually do contain @component

Other top-level comments I believe should just stay where ever the author put them (i.e. in the example above the comment would be first only if it was originally put before the <script> element). Currently, they are re-ordered if you try to add a comment on e.g. the <style> tag.

If we reorder all comments it wouldn't be possible to comment on the top-level HTML-tag, e.g.

<script>
...
</script>

<!-- the "myprop" attribute is defined in a plugin -->
<h1 data-myprop>Title</h1>

@dummdidumm
Copy link
Member Author

dummdidumm commented Sep 8, 2020

Only the @component comment would be reordered.

Your comment about "other comments are reorded" got me thinking though. Maybe we don't even need this kind of special behavior if we try to leave comments at its original place instead. Then everyone is free to place it whereever he wants (which I guess will be the top of the file most of the time).

@ehrencrona
Copy link
Contributor

@dummdidumm I agree; that would indeed seem most transparent. Also, my memory is the size of a turtle's; since #130 the comments should already stay in place; I was testing using an old version. So maybe nothing needs to be done after all?

@dummdidumm
Copy link
Member Author

Unfortunately not, only a prettier-ignore comment stays where it is, other comments are moved to the markup part.

@ehrencrona
Copy link
Contributor

Oh, right, true. We'd need to extend that to work with arbitrary comments then essentially. Looking at the code, that would also make sense code-wise. Seems like it should be a simple change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants