rrd108 / vue-mess-detector

A static code analysis tool for detecting code smells and best practice violations in Vue.js and Nuxt.js projects
MIT License
188 stars 6 forks source link

add rule (vue-reccomended): Single-file component top-level element order #41

Closed rrd108 closed 2 months ago

rrd108 commented 3 months ago

https://vuejs.org/style-guide/rules-recommended.html#single-file-component-top-level-element-order

David-Pena commented 2 months ago

Would we assume the correct order for this is:

<script setup></script>
<template></template>
<style></style>

Or how could we approach this rule?

rrd108 commented 2 months ago

Yes, choose the opiniated order above.

David-Pena commented 2 months ago

Hi @rrd108 I have a question, which interface / type should I use to handle all blocks? script, template and style?

image

I'm trying the SFCBlock type but I'm not sure here what to send as first parameter here: image

Because the checkRules function receives SFCDescriptor image

I think because of not using the correct struct, I'm having issues trying to test the rule with a project I have (the tests pass but with my own components doesnt report the rule)

rrd108 commented 2 months ago

In rulesCheck.ts we execute all the checks. There you can see we use script, template, styles of SFCDescriptor, or the SFCDescriptor itself, according the need.

As here we want to check the order of the blocks, I guess source of SFCDescriptor is the one to use here.

Will it work for this?

David-Pena commented 2 months ago

Will it work for this?

That was it! thanks image

PR created 🚀 #78