Skip to content

update no-deprecated-destroyed-lifecycle rule #1501

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

Merged
merged 1 commit into from
Jun 9, 2021
Merged
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
30 changes: 8 additions & 22 deletions lib/rules/no-deprecated-destroyed-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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')
}
})
}

Expand All @@ -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')
}
})
}

Expand Down
189 changes: 45 additions & 144 deletions tests/lib/rules/no-deprecated-destroyed-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
}
</script>
`,
errors: [
{
message:
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
line: 4,
suggestions: [
{
desc: 'Instead, change to `beforeUnmount`.',
output: `
output: `
<script>
export default {
beforeUnmount () {},
destroyed () {},
unmounted () {},
}
</script>
`
}
]
`,
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: `
<script>
export default {
beforeDestroy () {},
unmounted () {},
}
</script>
`
}
]
line: 5
}
]
},
Expand All @@ -160,42 +142,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
}
</script>
`,
errors: [
{
message:
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
line: 4,
suggestions: [
{
desc: 'Instead, change to `beforeUnmount`.',
output: `
output: `
<script>
export default {
beforeUnmount:beforeDestroy,
destroyed,
unmounted:destroyed,
}
</script>
`
}
]
`,
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: `
<script>
export default {
beforeDestroy,
unmounted:destroyed,
}
</script>
`
}
]
line: 5
}
]
},
Expand All @@ -218,15 +182,7 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
}
</script>
`,
errors: [
{
message:
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
line: 12,
suggestions: [
{
desc: 'Instead, change to `beforeUnmount`.',
output: `
output: `
<script>
export default {
beforeCreate,
Expand All @@ -238,40 +194,21 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
activated,
deactivated,
beforeUnmount:beforeDestroy,
destroyed,
unmounted:destroyed,
errorCaptured,
}
</script>
`
}
]
`,
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: `
<script>
export default {
beforeCreate,
created,
beforeMount,
mounted,
beforeUpdate,
updated,
activated,
deactivated,
beforeDestroy,
unmounted:destroyed,
errorCaptured,
}
</script>
`
}
]
line: 13
}
]
},
Expand All @@ -285,42 +222,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
}
</script>
`,
errors: [
{
message:
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
line: 4,
suggestions: [
{
desc: 'Instead, change to `beforeUnmount`.',
output: `
output: `
<script>
export default {
['beforeUnmount']() {},
['destroyed']() {},
['unmounted']() {},
}
</script>
`
}
]
`,
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: `
<script>
export default {
['beforeDestroy']() {},
['unmounted']() {},
}
</script>
`
}
]
line: 5
}
]
},
Expand All @@ -334,42 +253,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
}
</script>
`,
errors: [
{
message:
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
line: 4,
suggestions: [
{
desc: 'Instead, change to `beforeUnmount`.',
output: `
output: `
<script>
export default {
[\`beforeUnmount\`]() {},
[\`destroyed\`]() {},
[\`unmounted\`]() {},
}
</script>
`
}
]
`,
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: `
<script>
export default {
[\`beforeDestroy\`]() {},
[\`unmounted\`]() {},
}
</script>
`
}
]
line: 5
}
]
}
Expand Down