Skip to content

Commit ea6f9f0

Browse files
author
Alan Wang
authored
update no-deprecated-destroyed-lifecycle rule (#1501)
1 parent e1815cd commit ea6f9f0

File tree

2 files changed

+53
-166
lines changed

2 files changed

+53
-166
lines changed

lib/rules/no-deprecated-destroyed-lifecycle.js

+8-22
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ module.exports = {
2323
categories: ['vue3-essential'],
2424
url: 'https://eslint.vuejs.org/rules/no-deprecated-destroyed-lifecycle.html'
2525
},
26-
fixable: null,
26+
fixable: 'code',
2727
schema: [],
2828
messages: {
2929
deprecatedDestroyed:
3030
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
3131
deprecatedBeforeDestroy:
32-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
33-
insteadUnmounted: 'Instead, change to `unmounted`.',
34-
insteadBeforeUnmount: 'Instead, change to `beforeUnmount`.'
32+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.'
3533
}
3634
},
3735
/** @param {RuleContext} context */
@@ -43,15 +41,9 @@ module.exports = {
4341
context.report({
4442
node: destroyed.key,
4543
messageId: 'deprecatedDestroyed',
46-
// I don't know if they have exactly the same function, so don't do autofix.
47-
suggest: [
48-
{
49-
messageId: 'insteadUnmounted',
50-
fix(fixer) {
51-
return fix(fixer, destroyed, 'unmounted')
52-
}
53-
}
54-
]
44+
fix(fixer) {
45+
return fix(fixer, destroyed, 'unmounted')
46+
}
5547
})
5648
}
5749

@@ -60,15 +52,9 @@ module.exports = {
6052
context.report({
6153
node: beforeDestroy.key,
6254
messageId: 'deprecatedBeforeDestroy',
63-
// I don't know if they have exactly the same function, so don't do autofix.
64-
suggest: [
65-
{
66-
messageId: 'insteadBeforeUnmount',
67-
fix(fixer) {
68-
return fix(fixer, beforeDestroy, 'beforeUnmount')
69-
}
70-
}
71-
]
55+
fix(fixer) {
56+
return fix(fixer, beforeDestroy, 'beforeUnmount')
57+
}
7258
})
7359
}
7460

tests/lib/rules/no-deprecated-destroyed-lifecycle.js

+45-144
Original file line numberDiff line numberDiff line change
@@ -111,42 +111,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
111111
}
112112
</script>
113113
`,
114-
errors: [
115-
{
116-
message:
117-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
118-
line: 4,
119-
suggestions: [
120-
{
121-
desc: 'Instead, change to `beforeUnmount`.',
122-
output: `
114+
output: `
123115
<script>
124116
export default {
125117
beforeUnmount () {},
126-
destroyed () {},
118+
unmounted () {},
127119
}
128120
</script>
129-
`
130-
}
131-
]
121+
`,
122+
errors: [
123+
{
124+
message:
125+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
126+
line: 4
132127
},
133128
{
134129
message:
135130
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
136-
line: 5,
137-
suggestions: [
138-
{
139-
desc: 'Instead, change to `unmounted`.',
140-
output: `
141-
<script>
142-
export default {
143-
beforeDestroy () {},
144-
unmounted () {},
145-
}
146-
</script>
147-
`
148-
}
149-
]
131+
line: 5
150132
}
151133
]
152134
},
@@ -160,42 +142,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
160142
}
161143
</script>
162144
`,
163-
errors: [
164-
{
165-
message:
166-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
167-
line: 4,
168-
suggestions: [
169-
{
170-
desc: 'Instead, change to `beforeUnmount`.',
171-
output: `
145+
output: `
172146
<script>
173147
export default {
174148
beforeUnmount:beforeDestroy,
175-
destroyed,
149+
unmounted:destroyed,
176150
}
177151
</script>
178-
`
179-
}
180-
]
152+
`,
153+
errors: [
154+
{
155+
message:
156+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
157+
line: 4
181158
},
182159
{
183160
message:
184161
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
185-
line: 5,
186-
suggestions: [
187-
{
188-
desc: 'Instead, change to `unmounted`.',
189-
output: `
190-
<script>
191-
export default {
192-
beforeDestroy,
193-
unmounted:destroyed,
194-
}
195-
</script>
196-
`
197-
}
198-
]
162+
line: 5
199163
}
200164
]
201165
},
@@ -218,15 +182,7 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
218182
}
219183
</script>
220184
`,
221-
errors: [
222-
{
223-
message:
224-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
225-
line: 12,
226-
suggestions: [
227-
{
228-
desc: 'Instead, change to `beforeUnmount`.',
229-
output: `
185+
output: `
230186
<script>
231187
export default {
232188
beforeCreate,
@@ -238,40 +194,21 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
238194
activated,
239195
deactivated,
240196
beforeUnmount:beforeDestroy,
241-
destroyed,
197+
unmounted:destroyed,
242198
errorCaptured,
243199
}
244200
</script>
245-
`
246-
}
247-
]
201+
`,
202+
errors: [
203+
{
204+
message:
205+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
206+
line: 12
248207
},
249208
{
250209
message:
251210
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
252-
line: 13,
253-
suggestions: [
254-
{
255-
desc: 'Instead, change to `unmounted`.',
256-
output: `
257-
<script>
258-
export default {
259-
beforeCreate,
260-
created,
261-
beforeMount,
262-
mounted,
263-
beforeUpdate,
264-
updated,
265-
activated,
266-
deactivated,
267-
beforeDestroy,
268-
unmounted:destroyed,
269-
errorCaptured,
270-
}
271-
</script>
272-
`
273-
}
274-
]
211+
line: 13
275212
}
276213
]
277214
},
@@ -285,42 +222,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
285222
}
286223
</script>
287224
`,
288-
errors: [
289-
{
290-
message:
291-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
292-
line: 4,
293-
suggestions: [
294-
{
295-
desc: 'Instead, change to `beforeUnmount`.',
296-
output: `
225+
output: `
297226
<script>
298227
export default {
299228
['beforeUnmount']() {},
300-
['destroyed']() {},
229+
['unmounted']() {},
301230
}
302231
</script>
303-
`
304-
}
305-
]
232+
`,
233+
errors: [
234+
{
235+
message:
236+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
237+
line: 4
306238
},
307239
{
308240
message:
309241
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
310-
line: 5,
311-
suggestions: [
312-
{
313-
desc: 'Instead, change to `unmounted`.',
314-
output: `
315-
<script>
316-
export default {
317-
['beforeDestroy']() {},
318-
['unmounted']() {},
319-
}
320-
</script>
321-
`
322-
}
323-
]
242+
line: 5
324243
}
325244
]
326245
},
@@ -334,42 +253,24 @@ ruleTester.run('no-deprecated-destroyed-lifecycle', rule, {
334253
}
335254
</script>
336255
`,
337-
errors: [
338-
{
339-
message:
340-
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
341-
line: 4,
342-
suggestions: [
343-
{
344-
desc: 'Instead, change to `beforeUnmount`.',
345-
output: `
256+
output: `
346257
<script>
347258
export default {
348259
[\`beforeUnmount\`]() {},
349-
[\`destroyed\`]() {},
260+
[\`unmounted\`]() {},
350261
}
351262
</script>
352-
`
353-
}
354-
]
263+
`,
264+
errors: [
265+
{
266+
message:
267+
'The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead.',
268+
line: 4
355269
},
356270
{
357271
message:
358272
'The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.',
359-
line: 5,
360-
suggestions: [
361-
{
362-
desc: 'Instead, change to `unmounted`.',
363-
output: `
364-
<script>
365-
export default {
366-
[\`beforeDestroy\`]() {},
367-
[\`unmounted\`]() {},
368-
}
369-
</script>
370-
`
371-
}
372-
]
273+
line: 5
373274
}
374275
]
375276
}

0 commit comments

Comments
 (0)