-
-
Notifications
You must be signed in to change notification settings - Fork 211
Extract rule: template-attribute-indentation #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # ember/template-attribute-indentation | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| Migrated from [ember-template-lint/attribute-indentation](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/attribute-indentation.md). | ||
|
|
||
| ## Rule Details | ||
|
|
||
| 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). | ||
|
|
||
| ## Configuration | ||
|
|
||
| <!-- begin auto-generated rule options list --> | ||
|
|
||
| | Name | Type | Choices | | ||
| | :------------------------ | :------ | :--------------------------- | | ||
| | `as-indentation` | | `attribute`, `closing-brace` | | ||
| | `element-open-end` | | `new-line`, `last-attribute` | | ||
| | `indentation` | Integer | | | ||
| | `mustache-open-end` | | `new-line`, `last-attribute` | | ||
| | `open-invocation-max-len` | Integer | | | ||
| | `process-elements` | Boolean | | | ||
|
|
||
| <!-- end auto-generated rule options list --> | ||
|
|
||
| ## Examples | ||
|
|
||
| Examples of **incorrect** code for this rule: | ||
|
|
||
| Non-block form (> 80 characters): | ||
|
|
||
| ```hbs | ||
| {{employee-details firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl}} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be updated to angle bracket invocation?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a different PR perhaps -- these are copying from ember-template-lint. I'd rather get everything ported over from #2371, and then do full modernization passes, rather than doing the same small loop on repeat |
||
| ``` | ||
|
|
||
| Block form (> 80 characters): | ||
|
|
||
| ```hbs | ||
| {{#employee-details | ||
| firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl | ||
| as |employee| | ||
| }} | ||
| {{employee.fullName}} | ||
| {{/employee-details}} | ||
| ``` | ||
|
|
||
| HTML element (> 80 characters): | ||
|
|
||
| ```hbs | ||
| <input disabled id='firstName' value={{firstName}} class='input-field first-name' type='text' /> | ||
| ``` | ||
|
|
||
| Examples of **correct** code for this rule: | ||
|
|
||
| Non-block form (attributes on separate lines): | ||
|
|
||
| ```hbs | ||
| {{employee-details firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl}} | ||
| ``` | ||
|
|
||
| Block form (attributes on separate lines): | ||
|
|
||
| ```hbs | ||
| {{#employee-details | ||
| firstName=firstName lastName=lastName age=age avatarUrl=avatarUrl | ||
| as |employee| | ||
| }} | ||
| {{employee.fullName}} | ||
| {{/employee-details}} | ||
| ``` | ||
|
|
||
| HTML element (attributes on separate lines): | ||
|
|
||
| ```hbs | ||
| <input disabled id='firstName' value={{firstName}} class='input-field first-name' type='text' /> | ||
| ``` | ||
|
|
||
| Short invocations (< 80 characters) are allowed on a single line: | ||
|
|
||
| ```hbs | ||
| {{employee-details firstName=firstName lastName=lastName}} | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| - `open-invocation-max-len` (integer, default `80`): Maximum length of the opening invocation before attributes must be on separate lines. | ||
| - `indentation` (integer, default `2`): Number of spaces for attribute indentation. | ||
| - `process-elements` (boolean, default `true`): Also validate indentation of HTML/SVG element attributes. | ||
| - `element-open-end` (`"new-line"` | `"last-attribute"`, default `"new-line"`): Position of the closing `>` bracket. | ||
| - `mustache-open-end` (`"new-line"` | `"last-attribute"`, default `"new-line"`): Position of the closing `}}` braces. | ||
| - `as-indentation` (`"attribute"` | `"closing-brace"`, default `"closing-brace"`): Position of `as |param|` block params relative to attributes or closing brace. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be hbs only since this is the kind of stylistic thing that should be prettier for template tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be a stylisstic rule, yes (never in the recommended config), but not everyone uses prettier, so I imagine once all of #2371 is merged, we make sure this rule works with gjs