From ea6f9f01ed6b8a4f8f52d2657485880cf9a342bb Mon Sep 17 00:00:00 2001 From: Alan Wang <948467222@qq.com> Date: Wed, 9 Jun 2021 15:38:23 +0800 Subject: [PATCH] update `no-deprecated-destroyed-lifecycle` rule (#1501) --- .../no-deprecated-destroyed-lifecycle.js | 30 +-- .../no-deprecated-destroyed-lifecycle.js | 189 +++++------------- 2 files changed, 53 insertions(+), 166 deletions(-) diff --git a/lib/rules/no-deprecated-destroyed-lifecycle.js b/lib/rules/no-deprecated-destroyed-lifecycle.js index 6176daa95..9cb690cbc 100644 --- a/lib/rules/no-deprecated-destroyed-lifecycle.js +++ b/lib/rules/no-deprecated-destroyed-lifecycle.js @@ -23,15 +23,13 @@ module.exports = { categories: ['vue3-essential'], url: 'https://eslint.vuejs.org/rules/no-deprecated-destroyed-lifecycle.html' }, - fixable: null, + fixable: 'code', schema: [], messages: { deprecatedDestroyed: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', deprecatedBeforeDestroy: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - insteadUnmounted: 'Instead, change to `unmounted`.', - insteadBeforeUnmount: 'Instead, change to `beforeUnmount`.' + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.' } }, /** @param {RuleContext} context */ @@ -43,15 +41,9 @@ module.exports = { context.report({ node: destroyed.key, messageId: 'deprecatedDestroyed', - // I don't know if they have exactly the same function, so don't do autofix. - suggest: [ - { - messageId: 'insteadUnmounted', - fix(fixer) { - return fix(fixer, destroyed, 'unmounted') - } - } - ] + fix(fixer) { + return fix(fixer, destroyed, 'unmounted') + } }) } @@ -60,15 +52,9 @@ module.exports = { context.report({ node: beforeDestroy.key, messageId: 'deprecatedBeforeDestroy', - // I don't know if they have exactly the same function, so don't do autofix. - suggest: [ - { - messageId: 'insteadBeforeUnmount', - fix(fixer) { - return fix(fixer, beforeDestroy, 'beforeUnmount') - } - } - ] + fix(fixer) { + return fix(fixer, beforeDestroy, 'beforeUnmount') + } }) } diff --git a/tests/lib/rules/no-deprecated-destroyed-lifecycle.js b/tests/lib/rules/no-deprecated-destroyed-lifecycle.js index 00dda6ed8..c8c6774d6 100644 --- a/tests/lib/rules/no-deprecated-destroyed-lifecycle.js +++ b/tests/lib/rules/no-deprecated-destroyed-lifecycle.js @@ -111,42 +111,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, { } `, - errors: [ - { - message: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - line: 4, - suggestions: [ - { - desc: 'Instead, change to `beforeUnmount`.', - output: ` + output: ` - ` - } - ] + `, + errors: [ + { + message: + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', + line: 4 }, { message: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', - line: 5, - suggestions: [ - { - desc: 'Instead, change to `unmounted`.', - output: ` - - ` - } - ] + line: 5 } ] }, @@ -160,42 +142,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, { } `, - errors: [ - { - message: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - line: 4, - suggestions: [ - { - desc: 'Instead, change to `beforeUnmount`.', - output: ` + output: ` - ` - } - ] + `, + errors: [ + { + message: + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', + line: 4 }, { message: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', - line: 5, - suggestions: [ - { - desc: 'Instead, change to `unmounted`.', - output: ` - - ` - } - ] + line: 5 } ] }, @@ -218,15 +182,7 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, { } `, - errors: [ - { - message: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - line: 12, - suggestions: [ - { - desc: 'Instead, change to `beforeUnmount`.', - output: ` + output: ` - ` - } - ] + `, + errors: [ + { + message: + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', + line: 12 }, { message: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', - line: 13, - suggestions: [ - { - desc: 'Instead, change to `unmounted`.', - output: ` - - ` - } - ] + line: 13 } ] }, @@ -285,42 +222,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, { } `, - errors: [ - { - message: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - line: 4, - suggestions: [ - { - desc: 'Instead, change to `beforeUnmount`.', - output: ` + output: ` - ` - } - ] + `, + errors: [ + { + message: + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', + line: 4 }, { message: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', - line: 5, - suggestions: [ - { - desc: 'Instead, change to `unmounted`.', - output: ` - - ` - } - ] + line: 5 } ] }, @@ -334,42 +253,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, { } `, - errors: [ - { - message: - 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', - line: 4, - suggestions: [ - { - desc: 'Instead, change to `beforeUnmount`.', - output: ` + output: ` - ` - } - ] + `, + errors: [ + { + message: + 'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.', + line: 4 }, { message: 'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.', - line: 5, - suggestions: [ - { - desc: 'Instead, change to `unmounted`.', - output: ` - - ` - } - ] + line: 5 } ] }