Skip to content

Commit f12f142

Browse files
Merge pull request #2461 from NullVoxPopuli/nvp/template-lint-extract-rule-template-attribute-indentation
Extract rule: template-attribute-indentation
2 parents c20baf3 + 0bf977c commit f12f142

4 files changed

Lines changed: 1679 additions & 11 deletions

File tree

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,18 @@ rules in templates can be disabled with eslint directives with mustache or html
383383

384384
### Stylistic Issues
385385

386-
| Name                          | Description | 💼 | 🔧 | 💡 |
387-
| :--------------------------------------------------------------------------- | :--------------------------------------------------------------------- | :- | :- | :- |
388-
| [order-in-components](docs/rules/order-in-components.md) | enforce proper order of properties in components | | 🔧 | |
389-
| [order-in-controllers](docs/rules/order-in-controllers.md) | enforce proper order of properties in controllers | | 🔧 | |
390-
| [order-in-models](docs/rules/order-in-models.md) | enforce proper order of properties in models | | 🔧 | |
391-
| [order-in-routes](docs/rules/order-in-routes.md) | enforce proper order of properties in routes | | 🔧 | |
392-
| [template-attribute-order](docs/rules/template-attribute-order.md) | enforce consistent ordering of attributes in template elements | | | |
393-
| [template-block-indentation](docs/rules/template-block-indentation.md) | enforce consistent indentation for block statements and their children | | | |
394-
| [template-eol-last](docs/rules/template-eol-last.md) | require or disallow newline at the end of template files | | 🔧 | |
395-
| [template-linebreak-style](docs/rules/template-linebreak-style.md) | enforce consistent linebreaks in templates | | 🔧 | |
396-
| [template-no-only-default-slot](docs/rules/template-no-only-default-slot.md) | disallow using only the default slot | | 🔧 | |
386+
| Name                           | Description | 💼 | 🔧 | 💡 |
387+
| :----------------------------------------------------------------------------- | :----------------------------------------------------------------------------- | :- | :- | :- |
388+
| [order-in-components](docs/rules/order-in-components.md) | enforce proper order of properties in components | | 🔧 | |
389+
| [order-in-controllers](docs/rules/order-in-controllers.md) | enforce proper order of properties in controllers | | 🔧 | |
390+
| [order-in-models](docs/rules/order-in-models.md) | enforce proper order of properties in models | | 🔧 | |
391+
| [order-in-routes](docs/rules/order-in-routes.md) | enforce proper order of properties in routes | | 🔧 | |
392+
| [template-attribute-indentation](docs/rules/template-attribute-indentation.md) | enforce proper indentation of attributes and arguments in multi-line templates | | | |
393+
| [template-attribute-order](docs/rules/template-attribute-order.md) | enforce consistent ordering of attributes in template elements | | | |
394+
| [template-block-indentation](docs/rules/template-block-indentation.md) | enforce consistent indentation for block statements and their children | | | |
395+
| [template-eol-last](docs/rules/template-eol-last.md) | require or disallow newline at the end of template files | | 🔧 | |
396+
| [template-linebreak-style](docs/rules/template-linebreak-style.md) | enforce consistent linebreaks in templates | | 🔧 | |
397+
| [template-no-only-default-slot](docs/rules/template-no-only-default-slot.md) | disallow using only the default slot | | 🔧 | |
397398

398399
### Testing
399400

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# ember/template-attribute-indentation
2+
3+
<!-- end auto-generated rule header -->
4+
5+
Migrated from [ember-template-lint/attribute-indentation](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/attribute-indentation.md).
6+
7+
## Rule Details
8+
9+
This rule requires the positional params, attributes, and block params of helpers/components to be indented by moving them to multiple lines when the open invocation has more than 80 characters (configurable).
10+
11+
## Configuration
12+
13+
<!-- begin auto-generated rule options list -->
14+
15+
| Name | Type | Choices |
16+
| :------------------------ | :------ | :--------------------------- |
17+
| `as-indentation` | | `attribute`, `closing-brace` |
18+
| `element-open-end` | | `new-line`, `last-attribute` |
19+
| `indentation` | Integer | |
20+
| `mustache-open-end` | | `new-line`, `last-attribute` |
21+
| `open-invocation-max-len` | Integer | |
22+
| `process-elements` | Boolean | |
23+
24+
<!-- end auto-generated rule options list -->
25+
26+
## Examples
27+
28+
Examples of **incorrect** code for this rule:
29+
30+
Non-block form (> 80 characters):
31+
32+
```hbs
33+
{{employee-details firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl}}
34+
```
35+
36+
Block form (> 80 characters):
37+
38+
```hbs
39+
{{#employee-details
40+
firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl
41+
as |employee|
42+
}}
43+
{{employee.fullName}}
44+
{{/employee-details}}
45+
```
46+
47+
HTML element (> 80 characters):
48+
49+
```hbs
50+
<input disabled id='firstName' value={{firstName}} class='input-field first-name' type='text' />
51+
```
52+
53+
Examples of **correct** code for this rule:
54+
55+
Non-block form (attributes on separate lines):
56+
57+
```hbs
58+
{{employee-details firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl}}
59+
```
60+
61+
Block form (attributes on separate lines):
62+
63+
```hbs
64+
{{#employee-details
65+
firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl
66+
as |employee|
67+
}}
68+
{{employee.fullName}}
69+
{{/employee-details}}
70+
```
71+
72+
HTML element (attributes on separate lines):
73+
74+
```hbs
75+
<input disabled id='firstName' value={{firstName}} class='input-field first-name' type='text' />
76+
```
77+
78+
Short invocations (< 80 characters) are allowed on a single line:
79+
80+
```hbs
81+
{{employee-details firstName=firstName lastName=lastName}}
82+
```
83+
84+
## Options
85+
86+
- `open-invocation-max-len` (integer, default `80`): Maximum length of the opening invocation before attributes must be on separate lines.
87+
- `indentation` (integer, default `2`): Number of spaces for attribute indentation.
88+
- `process-elements` (boolean, default `true`): Also validate indentation of HTML/SVG element attributes.
89+
- `element-open-end` (`"new-line"` | `"last-attribute"`, default `"new-line"`): Position of the closing `>` bracket.
90+
- `mustache-open-end` (`"new-line"` | `"last-attribute"`, default `"new-line"`): Position of the closing `}}` braces.
91+
- `as-indentation` (`"attribute"` | `"closing-brace"`, default `"closing-brace"`): Position of `as |param|` block params relative to attributes or closing brace.

0 commit comments

Comments
 (0)