Skip to content

Add 'OTHER_DIRECTIVE' category to attributes-order #518

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/rules/attributes-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ex: 'v-once', 'v-pre'
ex: 'id'
- UNIQUE
ex: 'ref', 'key', 'slot'
- OTHER_DIRECTIVE
ex: 'v-focus', 'v-autosize'
- BINDING
ex: 'v-model', 'v-bind', ':property="foo"'
- OTHER_ATTR
Expand Down Expand Up @@ -87,7 +89,7 @@ Specify custom order of attribute groups
:+1: Examples of **correct** code with custom order`:

```html
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'DEFINITION'] }] -->
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'DEFINITION', 'OTHER_DIRECTIVE'] }] -->
<div
propOne="prop"
propTwo="prop"
Expand All @@ -96,7 +98,7 @@ Specify custom order of attribute groups
```

```html
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'DEFINITION', 'OTHER_ATTR', 'EVENTS', 'CONTENT'] }] -->
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'DEFINITION', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'OTHER_DIRECTIVE'] }] -->
<div
ref="header"
is="header"
Expand All @@ -108,7 +110,7 @@ Specify custom order of attribute groups
:-1: Examples of **incorrect** code with custom order`:

```html
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'DEFINITION', 'OTHER_ATTR', 'EVENTS', 'CONTENT'] }] -->
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'DEFINITION', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'OTHER_DIRECTIVE'] }] -->
<div
ref="header"
propOne="prop"
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/attributes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function getAttributeType (name, isDirective) {
return 'EVENTS'
} else if (name === 'html' || name === 'text') {
return 'CONTENT'
} else {
return 'OTHER_DIRECTIVE'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment this category is not defined, so custom directives are always required to go first.

}
} else {
if (name === 'is') {
Expand All @@ -43,7 +45,7 @@ function getPosition (attribute, attributeOrder) {

function create (context) {
const sourceCode = context.getSourceCode()
let attributeOrder = ['DEFINITION', 'LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'OTHER_ATTR', 'EVENTS', 'CONTENT']
let attributeOrder = ['DEFINITION', 'LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'OTHER_DIRECTIVE', 'BINDING', 'OTHER_ATTR', 'EVENTS', 'CONTENT']
if (context.options[0] && context.options[0].order) {
attributeOrder = context.options[0].order
}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/attributes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ tester.run('attributes-order', rule, {
'RENDER_MODIFIERS',
'GLOBAL',
'UNIQUE',
'OTHER_DIRECTIVE',
'BINDING',
'OTHER_ATTR',
'EVENTS',
Expand All @@ -202,6 +203,7 @@ tester.run('attributes-order', rule, {
'RENDER_MODIFIERS',
'GLOBAL',
'UNIQUE',
'OTHER_DIRECTIVE',
'BINDING',
'DEFINITION',
'OTHER_ATTR',
Expand Down Expand Up @@ -236,6 +238,7 @@ tester.run('attributes-order', rule, {
'DEFINITION',
'EVENTS',
'UNIQUE',
'OTHER_DIRECTIVE',
'BINDING',
'CONTENT',
'GLOBAL',
Expand Down Expand Up @@ -343,6 +346,7 @@ tester.run('attributes-order', rule, {
'RENDER_MODIFIERS',
'GLOBAL',
'UNIQUE',
'OTHER_DIRECTIVE',
'BINDING',
'DEFINITION',
'OTHER_ATTR',
Expand Down Expand Up @@ -459,6 +463,7 @@ tester.run('attributes-order', rule, {
'EVENTS',
'BINDING',
'UNIQUE',
'OTHER_DIRECTIVE',
'DEFINITION',
'CONDITIONALS',
'LIST_RENDERING',
Expand Down