Skip to content

Commit c41f0b2

Browse files
committed
Sync with ember-template-lint
1 parent 86cafb1 commit c41f0b2

3 files changed

Lines changed: 44 additions & 37 deletions

File tree

docs/rules/template-sort-invocations.md

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
<!-- end auto-generated rule header -->
44

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-
95
## Why use it?
106

117
The rule helps you standardize templates:
@@ -20,31 +16,52 @@ By sorting things that are order-independent, you can more easily refactor code.
2016
>
2117
> 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.
2218
23-
## Sorting Order
19+
## Examples
2420

25-
1. Argument attributes (starting with `@`)
26-
2. Regular attributes
27-
3. `...attributes` splattributes
28-
4. Modifiers
21+
### Components
2922

30-
Within each category, attributes are sorted alphabetically.
23+
When invoking a component, list things in the following order:
3124

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+
```
3341

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+
}}
4659
```
4760

61+
### Modifiers
62+
63+
Similarly to helpers, list the named arguments in alphabetical order.
64+
4865
## Limitations
4966

5067
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`.
6481

6582
## References
6683

67-
- [Ember.js Guides - Component Syntax](https://guides.emberjs.com/release/components/component-syntax-and-arguments/)
84+
Source code and tests were copied from [`ember-codemod-sort-invocations`](https://github.com/ijlee2/ember-codemod-sort-invocations).

lib/rules/template-sort-invocations.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = {
66
docs: {
77
description: 'require sorted attributes and modifiers',
88
category: 'Best Practices',
9-
recommended: false,
109
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-sort-invocations.md',
1110
templateMode: 'both',
1211
},

tests/lib/rules/template-sort-invocations.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,7 @@ ruleTester.run('template-sort-invocations', rule, {
351351
/>
352352
</template>`,
353353
output: null,
354-
errors: [
355-
{ messageId: 'attributeOrder' },
356-
{ messageId: 'modifierOrder' },
357-
],
354+
errors: [{ messageId: 'attributeOrder' }, { messageId: 'modifierOrder' }],
358355
},
359356
{
360357
code: `<template>
@@ -376,10 +373,7 @@ ruleTester.run('template-sort-invocations', rule, {
376373
</this.MyButton>
377374
</template>`,
378375
output: null,
379-
errors: [
380-
{ messageId: 'attributeOrder' },
381-
{ messageId: 'attributeOrder' },
382-
],
376+
errors: [{ messageId: 'attributeOrder' }, { messageId: 'attributeOrder' }],
383377
},
384378
{
385379
code: `<template>
@@ -597,10 +591,7 @@ ruleTester.run('template-sort-invocations', rule, {
597591
></iframe>
598592
</template>`,
599593
output: null,
600-
errors: [
601-
{ messageId: 'attributeOrder' },
602-
{ messageId: 'splattributesOrder' },
603-
],
594+
errors: [{ messageId: 'attributeOrder' }, { messageId: 'splattributesOrder' }],
604595
},
605596
{
606597
code: `<template>

0 commit comments

Comments
 (0)