You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/template-sort-invocations.md
+41-24Lines changed: 41 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,6 @@
2
2
3
3
<!-- end auto-generated rule header -->
4
4
5
-
Require sorted attributes and modifiers.
6
-
7
-
Component attributes and modifiers should be sorted in a consistent order for better readability and maintainability.
8
-
9
5
## Why use it?
10
6
11
7
The rule helps you standardize templates:
@@ -20,31 +16,52 @@ By sorting things that are order-independent, you can more easily refactor code.
20
16
>
21
17
> The `--fix` option for this rule doesn't preserve formatting. You can use `prettier`, [`prettier-plugin-ember-hbs-tag`](https://github.com/ijlee2/prettier-plugin-ember-hbs-tag), and [`prettier-plugin-ember-template-tag`](https://github.com/ember-tooling/prettier-plugin-ember-template-tag) to format templates in `*.hbs`, `hbs` tags, and `<template>` tags, respectively.
22
18
23
-
## Sorting Order
19
+
## Examples
24
20
25
-
1. Argument attributes (starting with `@`)
26
-
2. Regular attributes
27
-
3.`...attributes` splattributes
28
-
4. Modifiers
21
+
### Components
29
22
30
-
Within each category, attributes are sorted alphabetically.
23
+
When invoking a component, list things in the following order:
31
24
32
-
## Examples
25
+
1. Arguments
26
+
2. Attributes
27
+
3. Modifiers
28
+
4. Splattributes
29
+
30
+
The order clearly shows how the component is customized more and more. Things are alphabetized within each group.
31
+
32
+
```hbs
33
+
<Ui::Button
34
+
@label='Submit form'
35
+
@type='submit'
36
+
data-test-button
37
+
{{on 'click' this.doSomething}}
38
+
...attributes
39
+
/>
40
+
```
33
41
34
-
This rule **allows** the following:
35
-
36
-
```gjs
37
-
<template>
38
-
<Button
39
-
@isDisabled={{true}}
40
-
@label='Submit'
41
-
class='button'
42
-
{{on 'click' @onClick}}
43
-
...attributes
44
-
/>
45
-
</template>
42
+
> [!NOTE]
43
+
>
44
+
> In rare cases, the order of [`...attributes`](https://guides.emberjs.com/release/components/component-arguments-and-html-attributes/#toc_html-attributes) can matter. Similarly, the order can matter when an [ARIA attribute has multiple values](https://github.com/ijlee2/ember-container-query/issues/38#issuecomment-647017665).
45
+
>
46
+
> Disable the rule per instance in either case.
47
+
48
+
### Helpers
49
+
50
+
When invoking a helper, list the named arguments in alphabetical order.
51
+
52
+
```hbs
53
+
{{t
54
+
'my-component.description'
55
+
installedOn=this.installationDate
56
+
packageName='ember-source'
57
+
packageVersion='6.0.0'
58
+
}}
46
59
```
47
60
61
+
### Modifiers
62
+
63
+
Similarly to helpers, list the named arguments in alphabetical order.
64
+
48
65
## Limitations
49
66
50
67
It's intended that there are no options for sorting. Alphabetical sort is the simplest for everyone to understand and to apply across different projects. It's also the easiest to maintain.
@@ -64,4 +81,4 @@ To better meet your needs, consider creating a plugin for `ember-template-lint`.
0 commit comments