eslint-plugin-vue
Version:
Official ESLint plugin for Vue.js
48 lines (47 loc) • 1.8 kB
JavaScript
const require_index = require("../utils/index.js");
// lib/rules/no-deprecated-destroyed-lifecycle.ts
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
function fix(fixer, property, newName) {
if (property.computed) return require_index.default.isStringLiteral(property.key) ? fixer.replaceTextRange([property.key.range[0] + 1, property.key.range[1] - 1], newName) : null;
return property.shorthand ? fixer.insertTextBefore(property.key, `${newName}:`) : fixer.replaceText(property.key, newName);
}
var no_deprecated_destroyed_lifecycle_default = {
meta: {
type: "problem",
docs: {
description: "disallow using deprecated `destroyed` and `beforeDestroy` lifecycle hooks (in Vue.js 3.0.0+)",
categories: ["vue3-essential"],
url: "https://eslint.vuejs.org/rules/no-deprecated-destroyed-lifecycle.html"
},
fixable: "code",
schema: [],
messages: {
deprecatedDestroyed: "The `destroyed` lifecycle hook is deprecated. Use `unmounted` instead.",
deprecatedBeforeDestroy: "The `beforeDestroy` lifecycle hook is deprecated. Use `beforeUnmount` instead."
}
},
create(context) {
return require_index.default.executeOnVue(context, (obj) => {
const destroyed = require_index.default.findProperty(obj, "destroyed");
if (destroyed) context.report({
node: destroyed.key,
messageId: "deprecatedDestroyed",
fix(fixer) {
return fix(fixer, destroyed, "unmounted");
}
});
const beforeDestroy = require_index.default.findProperty(obj, "beforeDestroy");
if (beforeDestroy) context.report({
node: beforeDestroy.key,
messageId: "deprecatedBeforeDestroy",
fix(fixer) {
return fix(fixer, beforeDestroy, "beforeUnmount");
}
});
});
}
};
exports.default = no_deprecated_destroyed_lifecycle_default;