-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
Description
質問です。
聞きたいこと
今、Vue 向けに、i18n の custom rule を 作っているのですが、.vue
と.(j|t)s
(SFC と SFC 以外のJavaScript/TypeScript) の両方に対応した custome rule 作りたい。
困っていること
.vue
の方の custom rule はvue-eslint-parser
のこちらドキュメントにあるように、context.parserServices
を使って、custome rule を実装したオブジェクトを return すれば、.vue
向けに対応できます。
ただ、このようにしてしまうと、.(j|t)s
のJavaScript/TypeScriptのコードには lint が対応できなくなってしまう。
自分が今考えてる問題の解決方法
context.getFilename()
で取得したファイル名の拡張子を見て、動的に custome rule の実装オブジェクトを返す。
module.exports = {
// ...
create (context) {
const filename = context.getFilename()
if (isSFCFile(filename)) {
return context.parserServices.defineTemplateBodyVisitor({
// Event handlers for <template> ...
}, {
// Event handlers for <script> ...
})
} else {
return {
// Evant Handlers for normally ...
}
}
}
}
function isSFCFile (filename) {
// ...
}
ESLintのAPIか何かで、スマートな方法があれば教えて頂けるとありがたいです。:pray: