diff --git a/docs/rules/attributes-order.md b/docs/rules/attributes-order.md
index ea8c4ae9c..5737a6a84 100644
--- a/docs/rules/attributes-order.md
+++ b/docs/rules/attributes-order.md
@@ -36,6 +36,12 @@ This rule aims to enforce ordering of component attributes. The default order is
e.g. '@click="functionCall"', 'v-on="event"'
- `CONTENT`
e.g. 'v-text', 'v-html'
+
+Since 7.0.1:
+
+- `SLOT`
+ e.g. 'v-slot', 'slot' (separately from `UNIQUE`).
+ It will inherit `UNIQUE` position by default.
### the default order
diff --git a/lib/rules/attributes-order.js b/lib/rules/attributes-order.js
index 34a9d7d32..fc94c0808 100644
--- a/lib/rules/attributes-order.js
+++ b/lib/rules/attributes-order.js
@@ -19,7 +19,8 @@ const ATTRS = {
OTHER_DIRECTIVES: 'OTHER_DIRECTIVES',
OTHER_ATTR: 'OTHER_ATTR',
EVENTS: 'EVENTS',
- CONTENT: 'CONTENT'
+ CONTENT: 'CONTENT',
+ SLOT: 'SLOT'
}
/**
@@ -83,7 +84,7 @@ function getAttributeType(attribute, sourceCode) {
} else if (name === 'html' || name === 'text') {
return ATTRS.CONTENT
} else if (name === 'slot') {
- return ATTRS.UNIQUE
+ return ATTRS.SLOT
} else if (name === 'is') {
return ATTRS.DEFINITION
} else {
@@ -100,13 +101,10 @@ function getAttributeType(attribute, sourceCode) {
return ATTRS.DEFINITION
} else if (propName === 'id') {
return ATTRS.GLOBAL
- } else if (
- propName === 'ref' ||
- propName === 'key' ||
- propName === 'slot' ||
- propName === 'slot-scope'
- ) {
+ } else if (propName === 'ref' || propName === 'key') {
return ATTRS.UNIQUE
+ } else if (propName === 'slot' || propName === 'slot-scope') {
+ return ATTRS.SLOT
} else {
return ATTRS.OTHER_ATTR
}
@@ -186,6 +184,10 @@ function create(context) {
} else attributePosition[item] = i
})
+ if (!(ATTRS.SLOT in attributePosition)) {
+ attributePosition[ATTRS.SLOT] = attributePosition[ATTRS.GLOBAL]
+ }
+
/**
* @typedef {object} State
* @property {number} currentPosition
@@ -271,7 +273,7 @@ module.exports = {
items: {
type: 'string'
},
- maxItems: 10,
+ maxItems: 11,
minItems: 10
}
}
diff --git a/tests/lib/rules/attributes-order.js b/tests/lib/rules/attributes-order.js
index 87e72b56e..9347add26 100644
--- a/tests/lib/rules/attributes-order.js
+++ b/tests/lib/rules/attributes-order.js
@@ -943,6 +943,68 @@ tester.run('attributes-order', rule, {
message: 'Attribute "v-is" should go before "v-cloak".'
}
]
+ },
+
+ {
+ filename: 'test.vue',
+ options: [
+ {
+ order: [
+ 'UNIQUE',
+ 'LIST_RENDERING',
+ 'CONDITIONALS',
+ 'RENDER_MODIFIERS',
+ 'GLOBAL',
+ 'TWO_WAY_BINDING',
+ 'OTHER_DIRECTIVES',
+ 'OTHER_ATTR',
+ 'EVENTS',
+ 'CONTENT',
+ 'DEFINITION',
+ 'SLOT'
+ ]
+ }
+ ],
+ code:
+ '',
+ output:
+ '',
+ errors: [
+ {
+ message: 'Attribute "bar" should go before "v-slot".'
+ }
+ ]
+ },
+
+ {
+ filename: 'test.vue',
+ options: [
+ {
+ order: [
+ 'UNIQUE',
+ 'LIST_RENDERING',
+ 'CONDITIONALS',
+ 'RENDER_MODIFIERS',
+ 'GLOBAL',
+ 'TWO_WAY_BINDING',
+ 'OTHER_DIRECTIVES',
+ 'OTHER_ATTR',
+ 'EVENTS',
+ 'CONTENT',
+ 'DEFINITION',
+ 'SLOT'
+ ]
+ }
+ ],
+ code:
+ '',
+ output:
+ '',
+ errors: [
+ {
+ message: 'Attribute "ref" should go before "bar".'
+ }
+ ]
}
]
})