Skip to content

Commit

Permalink
update no-deprecated-destroyed-lifecycle rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Alanscut committed May 31, 2021
1 parent bf6e4ea commit b5854f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 168 deletions.
30 changes: 8 additions & 22 deletions lib/rules/no-deprecated-destroyed-lifecycle.js
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
193 changes: 47 additions & 146 deletions tests/lib/rules/no-deprecated-destroyed-lifecycle.js
Expand Up @@ -71,8 +71,8 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
code: `
<script>
export default {
beforeUnmount:beforeDestroy,
unmounted:destroyed,
beforeUnmount,
unmounted,
}
</script>
`
Expand Down 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

0 comments on commit b5854f4

Please sign in to comment.