diff --git a/lib/rules/order-in-components.js b/lib/rules/order-in-components.js
index d26fa7d10..acd002f3e 100644
--- a/lib/rules/order-in-components.js
+++ b/lib/rules/order-in-components.js
@@ -8,25 +8,54 @@ const utils = require('../utils')
const traverseNodes = require('vue-eslint-parser').AST.traverseNodes
const defaultOrder = [
+ // Side Effects (triggers effects outside the component)
'el',
+
+ // Global Awareness (requires knowledge beyond the component)
'name',
'parent',
+
+ // Component Type (changes the type of the component)
'functional',
+
+ // Template Modifiers (changes the way templates are compiled)
['delimiters', 'comments'],
+
+ // Template Dependencies (assets used in the template)
['components', 'directives', 'filters'],
+
+ // Composition (merges properties into the options)
'extends',
'mixins',
+ ['provide', 'inject'], // for Vue.js 2.2.0+
+
+ // Interface (the interface to the component)
'inheritAttrs',
'model',
['props', 'propsData'],
- 'fetch',
- 'asyncData',
+ 'emits', // for Vue.js 3.x
+
+ // Note:
+ // The `setup` option is included in the "Composition" category,
+ // but the behavior of the `setup` option requires the definition of "Interface",
+ // so we prefer to put the `setup` option after the "Interface".
+ 'setup', // for Vue 3.x
+
+ // Local State (local reactive properties)
+ 'fetch', // for Nuxt
+ 'asyncData', // for Nuxt
'data',
'computed',
+
+ // Events (callbacks triggered by reactive events)
'watch',
'LIFECYCLE_HOOKS',
+
+ // Non-Reactive Properties (instance properties independent of the reactivity system)
'methods',
- 'head',
+
+ // Rendering (the declarative description of the component output)
+ 'head', // for Nuxt
['template', 'render'],
'renderError'
]
@@ -41,8 +70,13 @@ const groups = {
'updated',
'activated',
'deactivated',
+ 'beforeUnmount', // for Vue.js 3.x
+ 'unmounted', // for Vue.js 3.x
'beforeDestroy',
- 'destroyed'
+ 'destroyed',
+ 'renderTracked', // for Vue.js 3.x
+ 'renderTriggered', // for Vue.js 3.x
+ 'errorCaptured' // for Vue.js 2.5.0+
]
}
diff --git a/lib/rules/require-explicit-emits.js b/lib/rules/require-explicit-emits.js
index 13219f71e..034921622 100644
--- a/lib/rules/require-explicit-emits.js
+++ b/lib/rules/require-explicit-emits.js
@@ -24,8 +24,6 @@ const utils = require('../utils')
// ------------------------------------------------------------------------------
const FIX_EMITS_AFTER_OPTIONS = [
- 'props',
- 'propsData',
'setup',
'data',
'computed',
@@ -44,8 +42,13 @@ const FIX_EMITS_AFTER_OPTIONS = [
'updated',
'activated',
'deactivated',
+ 'beforeUnmount',
+ 'unmounted',
'beforeDestroy',
- 'destroyed'
+ 'destroyed',
+ 'renderTracked',
+ 'renderTriggered',
+ 'errorCaptured'
]
/**
diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js
index f94b4ec67..055ecd984 100644
--- a/tests/lib/rules/order-in-components.js
+++ b/tests/lib/rules/order-in-components.js
@@ -35,6 +35,49 @@ ruleTester.run('order-in-components', rule, {
`,
parserOptions
},
+ {
+ filename: 'example.vue',
+ code: `
+ export default {
+ el,
+ name,
+ parent,
+ functional,
+ delimiters, comments,
+ components, directives, filters,
+ extends: MyComp,
+ mixins,
+ provide, inject,
+ inheritAttrs,
+ model,
+ props, propsData,
+ emits,
+ setup,
+ data,
+ computed,
+ watch,
+ beforeCreate,
+ created,
+ beforeMount,
+ mounted,
+ beforeUpdate,
+ updated,
+ activated,
+ deactivated,
+ beforeUnmount,
+ unmounted,
+ beforeDestroy,
+ destroyed,
+ renderTracked,
+ renderTriggered,
+ errorCaptured,
+ methods,
+ template, render,
+ renderError,
+ };
+ `,
+ parserOptions
+ },
{
filename: 'test.vue',
code: `
diff --git a/tests/lib/rules/require-explicit-emits.js b/tests/lib/rules/require-explicit-emits.js
index 1db1edb2b..cef95dd75 100644
--- a/tests/lib/rules/require-explicit-emits.js
+++ b/tests/lib/rules/require-explicit-emits.js
@@ -1282,8 +1282,62 @@ emits: {'foo': null}
+ `
+ },
+ {
+ desc:
+ 'Add the `emits` option with object syntax and define "foo" event.',
+ output: `
+
+
+
+
+ `
+ }
+ ]
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+
+ `,
+ errors: [
+ {
+ message:
+ 'The "foo" event has been triggered but not declared on `emits` option.',
+ suggestions: [
+ {
+ desc:
+ 'Add the `emits` option with array syntax and define "foo" event.',
+ output: `
+
+
+
+
`
@@ -1299,7 +1353,7 @@ emits: ['foo'],
export default {
name: '',
emits: {'foo': null},
- props: {}
+ watch: {}
}
`