Skip to content

attributes-order

Reports an attribute that is out of the recommended order: is, v-for, conditions (v-if, v-else-if, v-else, v-show), v-pre and v-once, id, ref, key and slots, v-model, other directives, plain and bound attributes, events, and v-html and v-text last. A bare v-bind="object" takes the place of the attribute it precedes. The order is not alphabetical. Only in .vue files.

A fixed order puts the directives that decide whether and how often an element exists first, so a reader sees at once what the element is before they read how it looks.

To fix, move the attribute to its place in the order.

Reported
...
<div>text</div>
...
<a @click="go" :href="u" v-if="ok">x</a>
<a v-if="ok" :href="u" @click="go">x</a>
<input v-bind="props" :id="i" v-model="m">
...
angular:
lint:
rules:
attributes-order: warn # off (default), warn, error
html:
lint:
rules:
attributes-order: warn # off (default), warn, error
svelte:
lint:
rules:
attributes-order: warn # off (default), warn, error
vue:
lint:
rules:
attributes-order: warn # off (default), warn, error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line attributes-order in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint-plugin-vue attributes-order partial the default order, no alphabetical, order or sortLineLength option, no fix