Skip to content

rule: vue/sort-keys-fix, the same as vue/sort-keys but with autofix #1517

@hugoattal

Description

@hugoattal

Please describe what the rule should do:
This should do the exact same thing as vue/sort-keys, but also autofix it (with --fix flag).

I think it should still be a different rule because this kind of fix is unsafe, meaning it can break/change the behavior of the code.
Here's an example:

const music = {
    title: "Africa",
    author: "Toto"
}
console.log(Object.values(music)[0]); // "Africa"

After fix:

const music = {
    author: "Toto",
    title: "Africa"
}
console.log(Object.values(music)[0]); // "Toto"

Still, this kind of breaking should never happen with clean code. And fixing the sort-keys manually is really tedious... That's why I suggest to add a new rule with an autofix like this one: https://github.com/leo-buneev/eslint-plugin-sort-keys-fix.

What category should the rule belong to?

  • Enforces code style (layout)
  • Warns about a potential error (problem)
  • Suggests an alternate way of doing something (suggestion)
  • Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

Example 1:

// BAD
<script lang="ts">
export default defineComponent({
    components: { B, A }
});
</script>
// GOOD
<script lang="ts">
export default defineComponent({
    components: { A, B }
});
</script>

Example 2:

// BAD
<script lang="ts">
export default defineComponent({
    methods: {
        B(){
            // ...
        },
        A(){
            // ...
        }
    }
});
</script>
// GOOD
<script lang="ts">
export default defineComponent({
    methods: {
        A(){
            // ...
        },
        B(){
            // ...
        }
    }
});
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions