🔧 This rule is automatically fixable by the --fix CLI option.
Enforces a consistent ordering of attributes in template elements. This helps improve readability and maintainability of templates.
This rule enforces a consistent order for attributes on template elements. By default, attributes are ordered by type group:
- Arguments —
@argName(Glimmer component arguments) - Attributes — standard HTML attributes like
class,id,role - Modifiers —
{{on "click" ...}},{{did-insert ...}}, etc.
Within each group, attributes are sorted alphabetically by default.
Additional groups (splattributes and comments) can be added to the ordering if needed.
Hash pairs in curly invocations (mustache/block statements) are also alphabetized when alphabetize is enabled.
Examples of incorrect code for this rule:
<template>
<MyComponent class="btn" @onClick={{this.go}} @label="hi" />
</template>In this example, class (an attribute) appears before @onClick and @label (arguments). Arguments should come first.
<template>
<MyComponent @label="hi" @action={{this.go}} />
</template>Here, @label and @action are out of alphabetical order within the arguments group.
Examples of correct code for this rule:
<template>
<MyComponent @action={{this.go}} @label="hi" class="btn" />
</template><template>
<div class="container" id="main" {{on "click" this.handleClick}}></div>
</template>| Name | Type | Default | Description |
|---|---|---|---|
order |
string[] |
["arguments", "attributes", "modifiers"] |
The order of token type groups. Valid values: "arguments", "attributes", "modifiers", "splattributes", "comments". |
alphabetize |
boolean |
true |
Whether to alphabetize attributes within each group. |
module.exports = {
rules: {
'ember/template-attribute-order': [
'error',
{
order: ['arguments', 'attributes', 'modifiers'],
alphabetize: true,
},
],
},
};