ESLintのno-restricted-syntax
が便利だったので使い方をメモ📝
例えばVue3へのアップデート時に以下のようなVue Test Utilsの変更がありアップデートするまでwrapper.destroy
を禁止したいとします。
Wrapper API (mount)
destroy: renamed to unmount to match Vue 3 lifecycle hook name.
Migrating from Vue Test Utils v1 | Vue Test Utils
こういう場合、カスタムルールを書かなくても以下のような感じでno-restricted-syntax
を使って簡単に禁止にできます。
module.exports = { rules: { "no-restricted-syntax": [ "error", { selector: "CallExpression[callee.property.name='destroy'][callee.object.name='wrapper']", message: "Calling wrapper.destroy() is not allowed", }, ], }, };
CallExpression[callee.property.name='destroy'][callee.object.name='wrapper']
でASTを元にwrapper.destory
に合致したらエラーにできるというわけですね。
カスタムルールを作らずにこういうのができるな便利ですね! かつGitHub Copilot Chat等で生成してもらいやすいのも非常に便利でした🤖✨